Jump to content

Archived

This topic is now archived and is closed to further replies.

grumpy

Why doen't this simple query work?

Recommended Posts

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"] . " ");
}
?>

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
G'day

Not 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).

Share this post


Link to post
Share on other sites
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!!

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.