Jump to content

Non-working Query


tet3828

Recommended Posts

>:(

I swear this query was working a little while ago. Any suggestions as to why a search would yeild no results when I know for sure the posted form value for %descvalue is in my database??

$qry = "SELECT itemName,itemId,itemPrice,itemSmall FROM `products` WHERE itemDesc OR itemName OR itemId like \"%$descvalue%\"";
$result = mysql_query($qry) or die(mysql_error());
$amount = mysql_num_rows($result);

echo "<br /><b><a href='http://claireart.net/shell/data/index.php'>Click Here</a></b> to try a different search.<br /><br /> ";
while($row = mysql_fetch_array($result)) {
echo "<table border=\"1\"><tr><td>".$row['itemName']."</td></tr>";
echo "<tr><td><center><img src=\"".$row['itemSmall']."\" /></center></td>";
echo "</tr><tr><td>Price: $".$row['itemPrice']."</td>";
echo "</tr>";
echo "<tr><td>";
echo "<a href=/shell/data/edit.php?id=".$row['itemId']." />Edit This Item</a>";
echo "</td></tr>";
echo "<br>";
echo "<br>";
}

echo "</table>";
Link to comment
https://forums.phpfreaks.com/topic/26400-non-working-query/
Share on other sites

That query syntax looks suspicious.. I would parse it as

[code]SELECT itemName,itemId,itemPrice,itemSmall
FROM `products`
WHERE itemDesc IS TRUE
OR itemName IS TRUE
OR itemId like "%$descvalue%"[/code]

Not sure about the double quotes, since i'm a postgres user.  But I'm pretty sure that you need to specify the condition for every column to be checked.

If it's still not making sense, try printing the query to the browser, then run it in phpmyadmin (or whichever interface you have for mysql)
Link to comment
https://forums.phpfreaks.com/topic/26400-non-working-query/#findComment-120743
Share on other sites

That last suggestion didn't quite do the trick. I even double checked to see if the descvalue was passed properly.
anymore suggestions as to why this query would yeild no results?
$qry = "SELECT itemName,itemId,itemPrice,itemSmall FROM `products` WHERE itemDesc OR itemName OR itemId LIKE \"%$descvalue%\"";
Link to comment
https://forums.phpfreaks.com/topic/26400-non-working-query/#findComment-120750
Share on other sites

I don't think I was clear.  What I mean is this:

[code]SELECT itemName,itemId,itemPrice,itemSmall
FROM `products`
WHERE itemDesc like "%$descvalue%"
OR itemName like "%$descvalue%"
OR itemId like "%$descvalue%"[/code]

Do you want to check if $descvalue is in any of those 3 columns?
Link to comment
https://forums.phpfreaks.com/topic/26400-non-working-query/#findComment-120769
Share on other sites

Archived

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

×
×
  • Create New...

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.