on the other table named "pics", i have hundreds of rows.
the columns are:
| picnum | imagename | hits |
if i want to display the 1st 50 images sort by hits i do this:
PHP Code:
$result = mysql_query("SELECT * FROM pics ORDER BY hits desc LIMIT 50")
or die(mysql_error());
echo "<table border='1'>";
echo "<tr> <th> PicNum </th> <th> Picture </th> <th> Views </th></tr>";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
// Print out the contents of each row into a table
echo "<tr><td>";
echo $row['pid'];
echo "</td><td>";
echo "<a href=\"/image-path/".$row['imagename']."\" target=\"_blank\"><img src=\"/thumbnail-path/".$row['imagename']."\" /><a/>";
echo "</td><td>";
echo $row['hits'];
echo "</td></tr>";
}
echo "</table>";
if 50 images are to be displayed, but only 25 has some hits, the rest of the images are ordered by picnum..
is there a way to ignore the rows when the "hits" value is zero?
For your first question, see the ON DUPLICATE KEY syntax for INSERT; or a simpler but less portable solution is the REPLACE INTO query syntax.
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
Bookmarks