Re: previous, current and next while looping

From: Date: Wed, 19 Jun 2002 15:57:31 +0000
Subject: Re: previous, current and next while looping
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-102958@lists.php.net to get a copy of this message
Hi wilbert ....foll is a code that i'd wrote with First ,Nest,Prev and Last moves....it should help you... <?php //file--db_navigation.php4 //purpose--this script enables one to traverse thro the db, i.e First,Prev,Next,Last moves //author--Snehal Patel //email--snehoo77@yahoo.com //collect the variables posted by the form $rowcnt = $HTTP_POST_VARS["rowcnt"]; $first = $HTTP_POST_VARS["first"]; $prev = $HTTP_POST_VARS["prev"]; $next = $HTTP_POST_VARS["next"]; $last = $HTTP_POST_VARS["last"]; //connect to db and query it $db = mysql_connect("localhost","root"); $dbase = "phpmysqlbox"; $table = "signbook"; mysql_select_db($dbase,$db); $sql = "select * from $table"; $result = mysql_query($sql); //get the maxrows of the table $maxrows= mysql_num_rows($result); //if first is clicked if ($first) { $rowcnt = 0; $FirstDisabled = "disabled"; $PrevDisabled = "disabled"; //get the row mysql_data_seek($result,$rowcnt); $row = mysql_fetch_object($result); $guest_id = $row->guest_id; $name = $row->name; $email = $row->email; } //if prev is clicked elseif ($prev) { $rowcnt--; if ($rowcnt <= 0){ $PrevDisabled = "disabled"; $FirstDisabled = "disabled"; } if ( $rowcnt > -1 ) { //get the row mysql_data_seek($result,$rowcnt); $row = mysql_fetch_object($result); $guest_id = $row->guest_id; $name = $row->name; $email = $row->email; } } //if next is clicked elseif ($next) { $rowcnt++; $maxrows= mysql_num_rows($result); if ($rowcnt == $maxrows-1){ $NextDisabled = "disabled"; $LastDisabled = "disabled"; } if ($rowcnt < $maxrows){ //get the row mysql_data_seek($result,$rowcnt); $row = mysql_fetch_object($result); $guest_id = $row->guest_id; $name = $row->name; $email = $row->email; } } //if last is clicked elseif ($last) { $rowcnt = $maxrows-1; $LastDisabled = "disabled"; $NextDisabled = "disabled"; //get the row mysql_data_seek($result,$rowcnt); $row = mysql_fetch_object($result); $guest_id = $row->guest_id; $name = $row->name; $email = $row->email; } //if nothing clicked i.e default else { $rowcnt = 0; $FirstDisabled = "disabled"; $PrevDisabled = "disabled"; //get the row mysql_data_seek($result,$rowcnt); $row = mysql_fetch_object($result); $guest_id = $row->guest_id; $name = $row->name; $email = $row->email; } ?> <form method=post action="<?=$PHP_SELF ?>"> <h2 align=center><u>DB Navigation</u></h2> <table Border=1 align=center width="40%"> <tr><td width="30%"><b>ID:</b></td><td width="70%"><?=$guest_id?></td></tr> <tr><td width="30%"><b>Name:</b></td><td width="70%"><?=$name?></td></tr> <tr><td width="30%"><b>Email</b></td><td width="70%"><?=$email?></td></tr> <tr><td align=center colspan=2> <INPUT TYPE="submit" NAME="first" <?=$FirstDisabled?> value="<< First"> <INPUT TYPE="submit" NAME="prev" <?=$PrevDisabled?> value="< Prev"> <INPUT TYPE="submit" NAME="next" <?=$NextDisabled?> value="Next >"> <INPUT TYPE="submit" NAME="last" <?=$LastDisabled?> value="Last >>"> </td></tr> </table> <input type = hidden name = "rowcnt" value="<?=$rowcnt?>"> </form> "Wilbert Enserink" <wilbert@pdd.nl> wrote in message news:004501c21773$b0f57770$0c01a8c0@pulsar... Hi all, I'm doing this query and looping through the results: $result_ID_ID=mysql_query($gallery_list_query) OR die(mysql_error()); $counter=0; while ($queryresult_IDresult=mysql_fetch_array($result_ID_ID)) { $result_array['$counter']=$queryresult_IDresult; if ($result_array['$counter']['galleryID']==$galleryID) { $current_number=$counter+1; $current_item=current(($result_array)); $next_item=next($result_array);///////this doesn't seem te work. } $counter=$counter+1; } When it has found the right record with ID number $galleryID I also need the previous record and the next record. Anybody has any clue how to do this? thx Wilbert ------------------------- Pas de Deux Van Mierisstraat 25 2526 NM Den Haag tel 070 4450855 fax 070 4450852 http://www.pdd.nl info@pdd.nl -------------------------

« previous php.general (#102958) next »