JoeF Posted December 15, 2006 Share Posted December 15, 2006 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.. Link to comment https://forums.phpfreaks.com/topic/30819-solved-mysql-search-returning-every-row-and-not-what-was-asked-for/ Share on other sites More sharing options...
jsladek Posted December 16, 2006 Share Posted December 16, 2006 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 Link to comment https://forums.phpfreaks.com/topic/30819-solved-mysql-search-returning-every-row-and-not-what-was-asked-for/#findComment-142123 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.