I need help getting a version of this to work where i can limit the entries by $page <?php $hostname = 'localhost'; $username = 'root'; $password = ''; $db = 'phpbook'; $page=$_GET['page']; /* open a single DB connection for this page */ $global_dbh = mysql_connect($hostname, $username, $password) or die("Could not connect to database"); mysql_select_db($db, $global_dbh) or die("Could not select database"); function display_stunt_actors($db_connection) { $query = "select * from stunts_page WHERE page LIKE '%". $page ."%' order by year"; $result_id = mysql_query($query, $db_connection) OR die(mysql_error($query)); print("<table border=0 cellpadding=0 cellspacing=0 width=600>\n"); $old_id = 0; while ($row_array = mysql_fetch_row($result_id)) { $id = $row_array[0]; if ($id != $old_id) { $name = $row_array[3]; if ($old_id != 0) print("</TD></TR></TABLE><p><table border=0 cellpadding=0 cellspacing=0 width=600>\n"); print("<TR ALIGN=LEFT VALIGN=TOP>"); print("<TD colspan='5'><b>$name</b></TD></tr>"); $old_id = $id; } $stunt_query = "select * from stunts where id = $id order by quickname"; $result = mysql_query($stunt_query, $db_connection) OR die(mysql_error()); $num=mysql_numrows($result); $cols = 5; $j = 0; $i=0; echo "<tr valign=\"top\">"; while ($i < $num ) { $designation=mysql_result($result,$i,"quickname"); $link=mysql_result($result,$i,"link"); $pic=mysql_result($result,$i,"pic"); $comments=mysql_result($result,$i,"comments"); $actor=mysql_result($result,$i,"actor"); echo "<td width=\"120\">\n<table border=0 cellpadding=0 cellspacing=0 width=120>\n<tr>\n<td width=120>\n"; if( $link == "") { echo "<img src=\"/images/$pic\" width=100 height=120 alt=\"\" border=\"0\">\n"; } else { echo "<a href=\"/database/$link/\"><img src=\"/images/$pic\" width=100 height=120 alt=\"\" border=\"0\"></a>\n"; } echo "</td>\n</tr>\n<tr>\n<td><font size=\"2\"><b><u>$designation</u></b><br>$actor $comments</font><br>\n"; echo "</td>\n</tr>\n</table></td>"; $i++; $j++; if ($j == $cols) { echo "</tr><tr>\n"; $j = 0; } } } /* close off final country and table */ print("</TD></TR></TABLE>"); } ?> <HTML><HEAD><TITLE>Stunt Guide</TITLE></HEAD> <BODY> <?php display_stunt_actors($global_dbh); ?> </BODY></HTML> PHP:
You would need to pass the $page variable to your display_stunt_actors function, pass that number in to the SQL query using LIMIT and calculate the remaining pages available from that number. Hint: Use FOUND_ROWS to reduce the amount of SQL calls necessary. Try it out yourself, then come back for help if you are stumped...
I just have to ask did you read the original post or the php code in it? I am not trying to use limit or calculate pages. $page is a column in my database for page ie ss-index.htm or kr-index.htm. I don't even know what founds_rows has to do with that or how to use it.
Sorry - that wasn't apparent from the question. So your database has a page column that basically acts like a version history of those pages (since you also have a year column)? A little more clarification would help since I don't know what the current outcome is and what you are expecting. On a side note - you need to use mysql_real_escape_string on $page in that initial query or you are open to MySQL injection attacks.
nevermind, i found the only issue i need to worry about it was $page=$_GET['page']; which was a bitch to figure out. it needed to be right before $query = "select * from stunts_page WHERE page LIKE '%". $page ."%' order by year"; as this is script for private use and pure html version for the public to access. This script is for a tv show website that covers multiple franchise over multiple decades that is why its ordered by year, and where page is for the shows sorted by a certain decade/franchise.