|
-
Nov 3rd, 2012, 07:03 PM
#1
Thread Starter
Lively Member
Can't fetch any string with spaces in it using [SQL]
PHP Code:
<?
$sql = "SELECT * FROM bns_cars WHERE id =(".$_GET['id'].")";
$data = mysql_query( $sql )
or die(mysql_error());
while($info = mysql_fetch_assoc( $data ))
{
$bsql = "SELECT * FROM `bns_brands` WHERE `id` = {$info['brand']};";
$bresult = mysql_query($bsql);
while ($binfo = mysql_fetch_assoc($bresult)) {
echo "{$binfo['title_en']}</br>";
}
$csql = "SELECT * FROM `bns_cars_images` WHERE `record_id` = (".$_GET['id'].");";
$cresult = mysql_query($csql);
$cinfo = mysql_fetch_array($cresult);
echo "<img src=http://xxx.com/uploads/cars/{$cinfo['path']}/{$cinfo['file_name']} width=170px height=113px />" ;
}
?>
So basically this is what i am using to get the path of my stored image and the file name but the problem here is that if the file name is saved as such "file_365_Untitled attachment 00124.jpg" then it will only parse out the "file_365_Untitled" from it and i want it to fetch the complete information not just the string before space.
Also if anyone can make this process short then it would be appreciated too
-
Nov 3rd, 2012, 09:36 PM
#2
Re: Can't fetch any string with spaces in it using [SQL]
have you tried surrounding the offending string in the database with quotes? that usually works. You just have to modify your code to pad the strings with quotes when writing the entries. I don't offhand remember if the quotes are still there when you read it back, but i don't think so.
-
Nov 3rd, 2012, 10:22 PM
#3
Thread Starter
Lively Member
Re: Can't fetch any string with spaces in it using [SQL]
I know about this method but not quite sure if that's going to work ... I need to understand how this is not returning back with a full string with spaces.
Is there anyone who has faced such issue and know how to resolve it ?
-
Nov 4th, 2012, 12:13 AM
#4
Re: Can't fetch any string with spaces in it using [SQL]
- If you are just starting to code this app, switch to PDO or mysqli, which are more secure and better. What you are using is mysql_* functions which is discouraged by the community.
- Try enclosing the values in single quotes inside the query.
- Check whether the field that truncates the string is actually having a lengthier size instead of the size 17 or something
- Check whether your database(using phpMyAdmin or something else) contains the full length string. If not, ie, the string is stored as truncated form, check whether you have enclosed the values in single quotes on your code where you do the insert operation.
- I think your code could be simplified by doing SQL JOIN operations.
If my post was helpful to you, then express your gratitude using Rate this Post. 
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|