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 :(
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.
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 ?
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.
:wave: