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
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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.