Jump to content

[SOLVED] Mysql search returning every row and not what was asked for...


JoeF

Recommended Posts

Hey, im using this:
[code] $get="SELECT *
FROM `songs`
WHERE `title` LIKE  '%$query%'";
$result = mysql_query($get) or die(mysql_error());
while ($row =mysql_fetch_array($result))
        {
$title=$row['title'];
$id=$row['id'];
echo "<a href='play.php?id=$id'>$title</a><br>";
}[/code]

To search for results that match the title.
But instead of that, its returning every row on that table.

Ive used this before and it usually works fine, also in phpmyadmin when i use its built in search it works fine also on the table, so its not something wrong with the table itself. Has to be something with this code, but i cant see what.

Anyone any ideas?


Thanks very much..
change it to this...
[code] $get="SELECT *
FROM `songs`
WHERE `title` LIKE  '%$query%'";
print("<hr>SQL: $get<hr>");
$result = mysql_query($get) or die(mysql_error());
while ($row =mysql_fetch_array($result))
        {
$title=$row['title'];
$id=$row['id'];
echo "<a href='play.php?id=$id'>$title</a><br>";
}[/code]
This way you can see what the sql looks like when it is built.  If $query does not have a value you will get [b]WHERE 'title" LIKE '%%'[/b] which I guess would give you everything in the database.

-John

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.