Jamz Posted March 17, 2008 Share Posted March 17, 2008 Hi There, Im currently having problems when i add a WHERE statment into my SQL... this is the code i have so far: <?php $brand = $_GET['brand']; $count = 0; $stop; include('images/config.php'); $database = mysql_connect($hostname,$username,$password) or die("Could not connect to server"); mysql_select_db($table,$database) or die("Could not find table"); $query = "SELECT * FROM 'Phone_Feed' WHERE 'Model.Name'='$brand'"; $result = mysql_query ($query); while ($row = mysql_fetch_assoc($result)) { $name = $row['Model.Name']; $img = $row['Model.ImageSmall']; while ($count < 6){ echo '<td width="100" align="center" bgcolor="#CCCCCC" class="deals"><strong>'.$name.'</strong></td>'; $stop = $name; $count++; } $count=0; $stop=0; echo '</tr><tr>'; while ($count < 6){ echo '<td align="center" valign="middle" class="deals"><img src="'.$img.'" alt="" /></td>'; $count++; } echo '</tr><tr><td colspan="8" align="center" valign="middle"></td></tr>'; $count=0; } ?> Now if i remove the WHERE the code works, but i need the WHERE to sort out all the phones. Im not sure what is wrong with it, and i cannot see anything Cheers James Quote Link to comment https://forums.phpfreaks.com/topic/96606-warning-mysql_fetch_assoc/ Share on other sites More sharing options...
trq Posted March 17, 2008 Share Posted March 17, 2008 There can be no quotes around identifyers. $query = "SELECT * FROM Phone_Feed WHERE Model.Name='$brand'"; Quote Link to comment https://forums.phpfreaks.com/topic/96606-warning-mysql_fetch_assoc/#findComment-494364 Share on other sites More sharing options...
Jamz Posted March 17, 2008 Author Share Posted March 17, 2008 I was just trying different things to see if they worked, but its still the same if i have them or take them out Quote Link to comment https://forums.phpfreaks.com/topic/96606-warning-mysql_fetch_assoc/#findComment-494431 Share on other sites More sharing options...
Jeremysr Posted March 17, 2008 Share Posted March 17, 2008 Change the mysql_query() line to: $result = mysql_query ($query) or die(mysql_error()); I have a habit of writing all my mysql_query()'s like that. It'll show you the error with your query. Quote Link to comment https://forums.phpfreaks.com/topic/96606-warning-mysql_fetch_assoc/#findComment-494441 Share on other sites More sharing options...
Jamz Posted March 17, 2008 Author Share Posted March 17, 2008 Here's the error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''Phone_Feed' WHERE 'Model.Name'='Nokia'' at line 1 Quote Link to comment https://forums.phpfreaks.com/topic/96606-warning-mysql_fetch_assoc/#findComment-494477 Share on other sites More sharing options...
trq Posted March 17, 2008 Share Posted March 17, 2008 Your field name isn't Model.name is it? That will cause all sorts of dramas as a period seperated identifier tells mysql to look in the table Model for a field called Name. Id'e suggest renaming your field to Model_Name. Quote Link to comment https://forums.phpfreaks.com/topic/96606-warning-mysql_fetch_assoc/#findComment-494480 Share on other sites More sharing options...
Jamz Posted March 17, 2008 Author Share Posted March 17, 2008 Aye i just realised that... the problem is, the whole database is like that... What it is you see, the database is imported from an comma file into mysql, and more or less every field has a . inbetween... Is there no work around without having to change the .'s? Quote Link to comment https://forums.phpfreaks.com/topic/96606-warning-mysql_fetch_assoc/#findComment-494481 Share on other sites More sharing options...
trq Posted March 18, 2008 Share Posted March 18, 2008 Its should work if you surround the field names with `backticks`, but it would be much prefered to change the field names. Quote Link to comment https://forums.phpfreaks.com/topic/96606-warning-mysql_fetch_assoc/#findComment-494661 Share on other sites More sharing options...
Jamz Posted March 18, 2008 Author Share Posted March 18, 2008 Well it gets rid of the error.... but does not show any output.... hmmmm ??? Quote Link to comment https://forums.phpfreaks.com/topic/96606-warning-mysql_fetch_assoc/#findComment-494772 Share on other sites More sharing options...
Jamz Posted March 18, 2008 Author Share Posted March 18, 2008 Code now looks like the following: <?php $brand = $_GET['brand']; $count = 0; $stop; include('images/config.php'); $database = mysql_connect($hostname,$username,$password) or die("Could not connect to server"); mysql_select_db($table,$database) or die("Could not find table"); $query = "SELECT * FROM Phone_Feed WHERE `Model.Name`='$brand'"; $result = mysql_query ($query) or die(mysql_error());; while ($row = mysql_fetch_assoc($result)) { $name = $row['Model.Name']; $img = $row['Model.ImageSmall']; while ($count < 6){ echo '<td width="100" align="center" bgcolor="#CCCCCC" class="deals"><strong>'.$name.'</strong></td>'; $stop = $name; $count++; } $count=0; $stop=0; echo '</tr><tr>'; while ($count < 6){ echo '<td align="center" valign="middle" class="deals"><img src="'.$img.'" alt="" /></td>'; $count++; } echo '</tr><tr><td colspan="8" align="center" valign="middle"></td></tr>'; $count=0; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/96606-warning-mysql_fetch_assoc/#findComment-494773 Share on other sites More sharing options...
Jamz Posted March 18, 2008 Author Share Posted March 18, 2008 W00P I got it working now.... There might be another post up soon though! Cheers for the helP! Quote Link to comment https://forums.phpfreaks.com/topic/96606-warning-mysql_fetch_assoc/#findComment-494833 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.