OK, I have this site running a picture rating system.
My focus- a visitor checks out pictures, ranks one, it then shows the user the one with ranking at another function, and a link is used to send user back to a function that shows all the pictures again (the default function in a switch statement).
My problem- I want to, instead of showing all the pics, just show one, with a link to goto the next one.
Here's the logic to how the pics are arranged:
The admin/s are able to upload the pic to the server, the link to the file is sent into a database table, along with the unique id (incremented) and a title and post date.
When each picture is shown in the display all pictures function, mysql is called, and the id is paired up with link of the picture in the server... it shows all the pics- THAT'S the problem... I can't figure out a logical method to halt the query to mysql to limit the pics so links are shown for the next pic to view.
HERE'S THE CODE (with obviously edits):
<?
function displayPic($all = 0) {
/* $db = database connection
* $max_items is the maximum number
*/
global $db, $max_items;
// query pics
if ($all == 0) {
// LIMIT BY $max_items
$query = "SELECT id,title,picture_name," .
"DATE_FORMAT(postdate, '%m-%d-%Y') as date " .
"FROM pic ORDER BY postdate DESC LIMIT $max_items";
} else {
// NO LIMIT- need to fix it sometime soon
$query = "SELECT id,title,picture_name," .
"DATE_FORMAT(postdate, '%m-%d-%Y') as date " .
"FROM pic ORDER BY postdate DESC";
}
$result = mysql_query ($query);
while ($row = mysql_fetch_assoc ($result)) {
/* display news in a simple table */
echo "<TABLE border=\"1\" width=\"300\">\n";
//Manipulate the variables for desired results.
$date = $row['date'];
$title = htmlentities ($row['title']);
$image = htmlentities($row['picture_name']);
//Display data
echo "<TR><TD><font face=arial size=2><b>$title</b> posted on $date</font></TD></TR>\n";
echo "<TR><TD><a href=\"javascript:void(0)\" onclick=\"window.open('$image','Yeah',height=400,width=600)\"><img src=$image height=75 width=100 border=0 alt=\"$title posted on $date\"></a></TD></TR>\n";
?>
<TR><TD><font face=arial size=1>Rate it (5=best):
<FORM ACTION=<? echo "\"{$_SERVER['PHP_SELF']}" .
"?action=show2\" method=POST>"; ?>
1<input type="radio" name="rank" value="1" onclick="this.form.submit()">
2<input type="radio" name="rank" value="2" onclick="this.form.submit()">
3<input type="radio" name="rank" value="3" onclick="this.form.submit()">
4<input type="radio" name="rank" value="4" onclick="this.form.submit()">
5<input type="radio" name="rank" value="5" onclick="this.form.submit()">
<input type="hidden" name="id" value=<? echo "\"{$row['id']}\">"; ?>
</form></font>
</td></tr>
<?
//COMMENTS QUERY
$comment_query = "SELECT count(*) FROM pic_comments " .
"WHERE pic_id={$row['id']}";
$comment_result = mysql_query ($comment_query);
$comment_row = mysql_fetch_row($comment_result);
// display comments link
echo "<TR><TD><a href=\"{$_SERVER['PHP_SELF']}" .
"?action=show&id={$row['id']}\">Comments</a>" .
"($comment_row[0])</TD></TR>\n";
echo "</TABLE>\n";
echo "<BR>\n";
}
//If you're only showing one item, sent user back to all pics...
if ($all == 0) {
echo "<a href=\"{$_SERVER['PHP_SELF']}" .
"?action=all\">View all pics</a>\n";
}
}
///////////////// FYI
this script is partially influenced (for the comments section) by the script here:
http://codewalkers.com/tutorials/19/2.html
so, if you need help with posting news/pic updaters WITH comments, try to utilize that site for references.