grumpy Posted March 2, 2006 Share Posted March 2, 2006 Hello-Why doesn't this simple query work? Nothing prints. The variable, $item4, is a one-word text string submitted from a form. If I substitute an actual keyword in the query instead of the variable, it works.Thank you.<?echo ("$item4"); //just testing to check the variable is correctly being sent from the form$query = mysql_query("select make from table1 where keyword = '$item4' ");$result = $query;while ($row = mysql_fetch_array($result)){print (" " . $row["make"] . " ");}?> Quote Link to comment Share on other sites More sharing options...
zq29 Posted March 2, 2006 Share Posted March 2, 2006 Try this to see if your query is actually returning anything, it might be that there are not any matches...[code]<?php$result = mysql_query("SELECT `make` FROM `table1` WHERE `keyword`='$item4'");if(mysql_num_rows($result) > 0) { while ($row = mysql_fetch_assoc($result)) { echo $row['make']."<br/>"; }} else { echo "There were no matches for the keyword you have supplied.";}?>[/code] Quote Link to comment Share on other sites More sharing options...
Humpty Posted March 2, 2006 Share Posted March 2, 2006 G'dayNot to sure on the whole fetch and while part, I do it differnetly, (i should convert cause all you guys seem to do it like that though)Have you checked case in the query and for the arrays? a lot of probs I get are mainly due to not having the right letter case everything seems very case sensitive when using PHP and MySQL on an apache server (as opposed to using MS softwares which I think most of us start with). Quote Link to comment Share on other sites More sharing options...
grumpy Posted March 2, 2006 Author Share Posted March 2, 2006 Thanks for everyone's help. The problem is "operator error" on my part. When I coded the form some of the element values are preceded by a 'space', so they aren't matching and thus no result is returned. Duh!! Quote Link to comment 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.