PDA

View Full Version : Search.php pulls thousands of pictures


hpgoodboy
12-19-2006, 09:14 PM
Hi,

when someone goes directly to /search.php,
thousands of pictures are loaded (it lists all media on my site).

I guess I have to somehow limit the query

$games = mysql_query("SELECT DISTINCT g.mId AS game_id, g.mName AS game_name, g.mThumb AS game_thumb, g.mDescription AS game_description, c.cName AS category_name FROM media g LEFT JOIN categories c ON c.cId=g.mCategory1 WHERE g.mName LIKE '%$search%' ORDER BY RAND() ");
while (list ($gameid, $gamename, $thumb, $description, $catname) = mysql_fetch_row($games)){

in search_content.tpl


How?

kip
12-20-2006, 11:29 AM
Well since most results wont be over 100 you can do this:

$games = mysql_query("SELECT DISTINCT g.mId AS game_id, g.mName AS game_name, g.mThumb AS game_thumb, g.mDescription AS game_description, c.cName AS category_name FROM media g LEFT JOIN categories c ON c.cId=g.mCategory1 WHERE g.mName LIKE '%$search%' ORDER BY RAND() LIMIT 100");
while (list ($gameid, $gamename, $thumb, $description, $catname) = mysql_fetch_row($games)){

hpgoodboy
12-20-2006, 10:08 PM
Thanks for the quick fix.

How do I have to word the query to let the system display
lets say 15 results and then a link to display more (16 - 30 etc.)?

kip
12-22-2006, 03:18 PM
well it wouldn't be wording the query. It would be almost a total rewrite. v1 will/should have this.

allstar
01-01-2007, 08:10 AM
It would be almost a total rewrite

How would it be a rewrite?

<?php
$page = $_GET['page'];
$limit = 15;

//do the sql adding
$games = mysql_query("SELECT DISTINCT g.mId AS game_id, g.mName AS game_name, g.mThumb AS game_thumb, g.mDescription AS game_description, c.cName AS category_name FROM media g LEFT JOIN categories c ON c.cId=g.mCategory1 WHERE g.mName LIKE '%$search%' ORDER BY RAND() LIMIT $page,$limit");
while (list ($gameid, $gamename, $thumb, $description, $catname) = mysql_fetch_row($games)){

$page = $page + $limit;
?>
<!-- I don't know the link structure -->
<a href="http://website.com/???.php?page=<?=$page?>">Next <?=$limit?> Results</a>

Don't forget to clean the above $_GET for sql / xss injections before using it, which I did not do. I suggest that you just redirect them to the home page if they did not enter a search query.