itsjames Posted August 5, 2008 Share Posted August 5, 2008 Hi, This is probably quite a simple error, so appologies if I'm just being stupid! My script queries the database to select all fields from my table where the category matches what I've specified (in this case, heating): $item = mysql_query("SELECT * FROM items WHERE category = heating"); The following code displays the result in a table: while($result = mysql_fetch_array($item)) { echo( "<table width=\"450\" border=\"0\"><tr>" ); echo( "<td colspan=\"2\" class=\"resultTitle\">" . $result['name'] . "</td>" ); echo( "<td rowspan=\"3\" align=\"center\" width=\"110\" height=\"110\"><a href=\"#\" onclick=\"window.open(\'images/database/" . $result['image'] . ".jpg\',\'Photo\',\'width=600,height=550,scrollbars=yes\')\">" ); echo( "<img src=\"images/database/" . $result['image'] . "\" border=\"0\" height=\"110\" width=\"110\" /></a></td></tr>" ); echo( "<tr><td width=\"170\"><p><strong>Category:</strong> " . $result['category'] . "<br>" ); echo( "<strong>Subcategory:</strong> " . $result['sub_category'] . "</p></td>" ); echo( "<td width=\"170\"><strong>Dimensions:</strong> " . $result['dimensions'] . "<br>" ); echo( "<strong>Price:</strong> £" . $result['price'] . "</td></tr>" ); echo( "<tr><td colspan=\"2\"><strong>Self collect available:</strong> " . $result['self_collect'] . "</td></tr>" ); echo( "<tr><td colspan=\"3\">" . $result['long_description'] . "</td></tr></table>" ); } I assume my fault is somewhere within this block of code, as when I run the script, nothing is echoed. I have checked that the database login details are correct, and that the query works. I am using PHP 4.4.8 MySQL 5.0.22 All help appreciated Regards Link to comment https://forums.phpfreaks.com/topic/118243-solved-phpmysql-not-returning-any-results/ Share on other sites More sharing options...
Ace Jon Posted August 5, 2008 Share Posted August 5, 2008 In the mysql search, try changing: category = heating to: category = 'heating' Whether or not that works, you should do this whenever you're in doubt with a mysql query: $something = mysql_query("query goes here") or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/118243-solved-phpmysql-not-returning-any-results/#findComment-608527 Share on other sites More sharing options...
vikramjeet.singla Posted August 5, 2008 Share Posted August 5, 2008 as mentioned by Ace always enquote strings with single quotes... Link to comment https://forums.phpfreaks.com/topic/118243-solved-phpmysql-not-returning-any-results/#findComment-608530 Share on other sites More sharing options...
itsjames Posted August 5, 2008 Author Share Posted August 5, 2008 Hi, I've added the quotes, and the die statement. Turns out it wasn't what I thought it was at fault, but I'd forgot to select the table!! Thanks for your help! Link to comment https://forums.phpfreaks.com/topic/118243-solved-phpmysql-not-returning-any-results/#findComment-608535 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.