MySQL Forums
Forum List  »  PHP

Problemo with QUERY and LIMIT
Posted by: Travis Thomas
Date: April 07, 2006 05:36PM

I'm brand spankin' new to PHP & MySQL...

This is what I have so far to display my results in pages limited to 10 results per page...

---Results viewable on http://www.badassrockers.com/data/music-instruments/zzounds/products.php?category=6-String%20Acoustic%20Guitars

<?php
$s = $_GET['s'];

if (empty($s)){
$s=0;
}
$limit = 10;
$category = @$_GET['category'];
$query = mysql_query("SELECT Name, URL_Image_Small, Price, URL_Product, Product_Type, Category, Description, Popular FROM db WHERE Category LIKE '$category' ORDER BY Popular");

if (!$query) {
exit('<p>Error performing query: ' . mysql_error() . '</p>');
}


?>
<?php
$numresults = $query;
$numrows = @mysql_num_rows($numresults);
//here's where I'm trying to limit... ie: "LIMIT 0, 10"
$query .= " LIMIT $s, $limit";
$result = $query;

while ($row = mysql_fetch_array($result)) {
$name = $row['Name'];
$image_small = $row['URL_Image_Small'];
$price = $row['Price'];
$link = $row['URL_Product'];
$desc = $row['Description'];

//When the code above is used, this echo doesn't display at all...
echo ("<td class='row1h' align='center' width='15%'><a href='$link'><img src='$image_small'></a></td><td class='row1h' align='center' width='75%'><a href='$link'>$name</a><br>$desc</td><td class='row1h' align='center' width='10%'>$$price</td><tr>");
}
?>

So... Problemo is... It doesn't display any results...

I've noticed that when I take out " $query .= "LIMIT $s, $limit"; " from above, it displays results...but, it displays ALL of the results. That's why I'm trying to use LIMIT in there... It's just not working right... Any ideas on what my problem is?

I hope I've listed everything that is relevant...

Options: ReplyQuote


Subject
Written By
Posted
Problemo with QUERY and LIMIT
April 07, 2006 05:36PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.