jck Posted July 14, 2007 Share Posted July 14, 2007 in my webpage of jokes when we choose a category it shows all the jokes in a category in alphabetical order so can u tell me how to add nect and previous buttons for each script?? Link to comment https://forums.phpfreaks.com/topic/59926-next-and-previous-script/ Share on other sites More sharing options...
jck Posted July 14, 2007 Author Share Posted July 14, 2007 i mean in each joke Link to comment https://forums.phpfreaks.com/topic/59926-next-and-previous-script/#findComment-298022 Share on other sites More sharing options...
bluebyyou Posted July 14, 2007 Share Posted July 14, 2007 This was discussed earlier here: http://www.phpfreaks.com/forums/index.php/topic,149594.0.html Or there are a couple of tutorials here: http://www.phpfreaks.com/tutorial_cat/25/Page-Number--Pagination.php Do you have any code you are already working with or trying it? Link to comment https://forums.phpfreaks.com/topic/59926-next-and-previous-script/#findComment-298024 Share on other sites More sharing options...
jck Posted July 14, 2007 Author Share Posted July 14, 2007 when a category is opened the list of jokes come in descending order so if i open the first joke i have to click back and then find the next one in the list and so on which is very irritating so i am trying for a script which goes to the next joke in alphabetical order belonging to that category and similarly to the previous i hape i was clear this time Link to comment https://forums.phpfreaks.com/topic/59926-next-and-previous-script/#findComment-298025 Share on other sites More sharing options...
bluebyyou Posted July 14, 2007 Share Posted July 14, 2007 I'm pretty sure what you are looking for is the same basic principle as pagination. are your jokes stored in a DB? Link to comment https://forums.phpfreaks.com/topic/59926-next-and-previous-script/#findComment-298026 Share on other sites More sharing options...
jck Posted July 14, 2007 Author Share Posted July 14, 2007 yes in a db... Link to comment https://forums.phpfreaks.com/topic/59926-next-and-previous-script/#findComment-298028 Share on other sites More sharing options...
bluebyyou Posted July 14, 2007 Share Posted July 14, 2007 <?php if(!isset($_GET['joke'])) { $joke= 0;} else { $joke = $_GET['joke']; } $prev = ($joke - 1); $next = ($joke + 1); $query = "SELECT * FROM jokes ORDER BY title LIMIT $joke,1"; ?> <a href="<?php echo "$_SERVER['PHP_SELF']?joke=$prev"; ?>">Previous</a> <a href="<?php echo "$_SERVER['PHP_SELF']?joke=$next"; ?>">Next</a> Im not exaclty sure about the LIMIT part of that, I think that should give you the idea. Link to comment https://forums.phpfreaks.com/topic/59926-next-and-previous-script/#findComment-298030 Share on other sites More sharing options...
jck Posted July 14, 2007 Author Share Posted July 14, 2007 firstly i made a mistake its done in desc order of item id but all the jokes are in 1 db so joke +1 and joke-1 wont work........ because for any particular jokes with conecutive ids may nt be of same category but i need next one in this category Link to comment https://forums.phpfreaks.com/topic/59926-next-and-previous-script/#findComment-298039 Share on other sites More sharing options...
bluebyyou Posted July 14, 2007 Share Posted July 14, 2007 well then you can add a where clause to specify which letter of the alphabet you need. Link to comment https://forums.phpfreaks.com/topic/59926-next-and-previous-script/#findComment-298040 Share on other sites More sharing options...
jck Posted July 14, 2007 Author Share Posted July 14, 2007 i think i didnt explain properly, consider 8 jokes 1,2,3,4,5,6,7,8 1,5,6,7 belong to category a 2,8 belong to category b 3,4 belong to category c suppose im reading 1 i need next to take me to 6 i need next to go to 7 and previous to 5 and so on but in ur case 1 will go to 2 and 3 and so on Link to comment https://forums.phpfreaks.com/topic/59926-next-and-previous-script/#findComment-298042 Share on other sites More sharing options...
bluebyyou Posted July 14, 2007 Share Posted July 14, 2007 I know what you mean, please post your code, and I will try to insert my solution into it to show you how it will work. Link to comment https://forums.phpfreaks.com/topic/59926-next-and-previous-script/#findComment-298044 Share on other sites More sharing options...
jck Posted July 14, 2007 Author Share Posted July 14, 2007 i am writing a new code and i am not getting the idea i think this is wrong in this context $prev = ($joke - 1); $next = ($joke + 1); Link to comment https://forums.phpfreaks.com/topic/59926-next-and-previous-script/#findComment-298045 Share on other sites More sharing options...
bluebyyou Posted July 14, 2007 Share Posted July 14, 2007 I think it would work. Perhaps I didn't explain my self very well. did you even try to do it on your own before you posted? I tried to help with the description of what you wanted and no code posted. Link to comment https://forums.phpfreaks.com/topic/59926-next-and-previous-script/#findComment-298047 Share on other sites More sharing options...
jck Posted July 14, 2007 Author Share Posted July 14, 2007 i tried but i was not getting any idea how to do it thats why i posted now i got a differnt idea ill try it Link to comment https://forums.phpfreaks.com/topic/59926-next-and-previous-script/#findComment-298088 Share on other sites More sharing options...
bluebyyou Posted July 14, 2007 Share Posted July 14, 2007 Well you can still post your code and I will show you what I meant. Link to comment https://forums.phpfreaks.com/topic/59926-next-and-previous-script/#findComment-298089 Share on other sites More sharing options...
jck Posted July 14, 2007 Author Share Posted July 14, 2007 dont worry about a1 it exists on the page where im gonna inset this this was the best i cud think of dont know if it will work... <? $joke = '$ItemID'; $result = mysql_query("SELECT ItemID FROM dd_items WHERE CategoryID = '$a1[itemCategory]' and ItemStatus = 'approved' ORDER by ItemID DESC"); $i = 0; while($row = mysql_fetch_array($result)) { $ID['$i'] = $row['ItemID'] $i++ } if ($ID['$j'] == $ItemID) { $prev = $ID['$j--']; $next = $ID['$j++']; } ?> <a href="/view.php?=<?=$prev?>"Previous</a> <a href="/view.php?=<?=$Next?>"Next</a> Link to comment https://forums.phpfreaks.com/topic/59926-next-and-previous-script/#findComment-298092 Share on other sites More sharing options...
bluebyyou Posted July 14, 2007 Share Posted July 14, 2007 You have a typo here: $ID['$i'] = $row['IemID'] should be: $ID['$i'] = $row['ItemID'] also here: <a href="/view.php?=<?=$prev?>"Previous</a> <a href="/view.php?=<?=$Next?>"Next</a> You are missing something to create the GET varible. Should be: <a href="/view.php?=<?joke=$prev?>"Previous</a> <a href="/view.php?=<?joke=$Next?>"Next</a> Link to comment https://forums.phpfreaks.com/topic/59926-next-and-previous-script/#findComment-298094 Share on other sites More sharing options...
jck Posted July 14, 2007 Author Share Posted July 14, 2007 is every thing else correct??? Link to comment https://forums.phpfreaks.com/topic/59926-next-and-previous-script/#findComment-298095 Share on other sites More sharing options...
jck Posted July 14, 2007 Author Share Posted July 14, 2007 so the whole concept of if ($ID['$j'] == $ItemID) { $prev = $ID['$j--']; $next = $ID['$j++']; } is correct huh?? Link to comment https://forums.phpfreaks.com/topic/59926-next-and-previous-script/#findComment-298098 Share on other sites More sharing options...
bluebyyou Posted July 14, 2007 Share Posted July 14, 2007 No what you have wont work. Have you tried it? What does your table in the DB look like? and on the page what is$a1[itemCategory] set to? I am assuming that ItemID is the primary key as well. edit: when I say what does the table look like I mean what are all of the fields in it? edit 2: I wish you would just post the code to your entire page already. Link to comment https://forums.phpfreaks.com/topic/59926-next-and-previous-script/#findComment-298102 Share on other sites More sharing options...
jck Posted July 14, 2007 Author Share Posted July 14, 2007 a1 is in view.php the table has ItemID ItemTitle ItemCategory ItemSubcategory ItemText Contributor DateAdded ItemType ItemStatus i didnt try it Link to comment https://forums.phpfreaks.com/topic/59926-next-and-previous-script/#findComment-298108 Share on other sites More sharing options...
bluebyyou Posted July 14, 2007 Share Posted July 14, 2007 please post the code for view.php Link to comment https://forums.phpfreaks.com/topic/59926-next-and-previous-script/#findComment-298110 Share on other sites More sharing options...
jck Posted July 14, 2007 Author Share Posted July 14, 2007 view.php <? require_once("conn.php"); require_once("access.php"); //get the item details $q1 = "select * from dd_items where ItemID = '$_GET[itemID]' "; $r1 = mysql_query($q1) or die(mysql_error()); $a1 = mysql_fetch_array($r1); //get the category $q2 = "select CategoryName from dd_categories where CategoryID = '$a1[itemCategory]' "; $r2 = mysql_query($q2) or die(mysql_error()); $a2 = mysql_fetch_array($r2); $Item_Category = $a2[0]; $ItemID = $a1[itemID]; if($a1[itemSubcategory] > '0') { //get the subcategory name $q3 = "select SubcategoryName from dd_subcategories where SubcategoryID = '$a1[itemSubcategory]' "; $r3 = mysql_query($q3) or die(mysql_error()); $a3 = mysql_fetch_array($r3); $Item_Category .= "/$a3[0]"; } $Item_Contributor = $a1[Contributor]; //get the rating $q4 = "select count(ItemID) as n, sum(Rating) as r from dd_rating where ItemID = '$a1[itemID]' "; $r4 = mysql_query($q4) or die(mysql_error()); $a4 = mysql_fetch_array($r4); if($a4[n] > '0') { $Item_Rating = number_format($a4[r]/$a4[n], 2, ".", ""); } else { $Item_Rating = "0.00"; } $View_Item .= "<b>$a1[itemTitle]</b><br>"; $VenInfo = explode("|", $a1[itemText]); $View_Item .= nl2br($VenInfo[0])."<br><br>"; if(!empty($a1[itemImage])) { $MySize = getimagesize("items_images/$a1[itemImage]"); if($MySize[0] > '100') { $MyWidth = '100'; } else { $MyWidth = $MySize[0]; } $View_Item .= "<img src=\"items_images/$a1[itemImage]\" style=\"float:left\" width=\"$MyWidth\">"; } $View_Item .= nl2br($VenInfo[1]); if($_GET[rate_error] == "y") { $message = "<b>Sorry, you have already rated this $main_keyword.</b>"; } elseif($_GET[rate_error] == "n") { $message = "<b>Thank you for rating this $main_keyword.</b>"; } //get the templates require_once("templates/MainHeader.php"); require_once("templates/MainView.php"); require_once("templates/MainFooter.php"); ?> mainview.php <table align=center width=400 class=MainTable border=0 bordercolor="<?=$aset[MainBorderColor]?>" cellspacing=0 cellpadding=5 rules=none> <tr> <td valign=top> <table align=left width=330 border=0 bordercolor=black cellspacing=0> <tr> <td> <div align="left"><b><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Category:</font></b> <font size="2" face="Verdana, Arial, Helvetica, sans-serif"> <?=$Item_Category?> <br> <b>Reader Rating:</b> <?=$Item_Rating?> <br> <b>Contributor:</b> <?=$Item_Contributor?> </font><br> </div></td> </tr> </table> <div align="left"></div></td> </tr> <tr> <td align=center><hr size="1"></td> </tr> <tr> <td align=center><form method=post action="rate.php"> <input type=hidden name=ItemID value="<?=$ItemID?>"> <table align=center border=0 bordercolor=black cellspacing=0 cellpadding=2 rules=none width=400> <tr> <td colspan=5> <center> <b><font size="2" face="Arial, Helvetica, sans-serif">Rate this <?=$main_keyword?> <br> <br> </font></b> </center></td> </tr> <tr bgcolor="#000000"> <td align=center><strong><font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif"> <input type=radio name=rr value=5 onClick="this.form.submit();"> <br> Hilarious</font></strong></td> <td align=center><strong><font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif"> <input type=radio name=rr value=4 onClick="this.form.submit();"> <br> Good</font></strong></td> <td align=center><strong><font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif"> <input type=radio name=rr value=3 onClick="this.form.submit();"> <br> Average</font></strong></td> <td align=center><strong><font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif"> <input type=radio name=rr value=2 onClick="this.form.submit();"> <br> Poor</font></strong></td> <td align=center><strong><font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif"> <input type=radio name=rr value=1 onClick="this.form.submit();"> <br> Nasty</font></strong></td> </tr> </table> </form></td> </tr> <tr> <td align="center"> <?php $query="SELECT * FROM dd_rating WHERE ItemID = '$ItemID' AND username = '$_SESSION[username]'"; $result = mysql_query($query); if (mysql_num_rows($result) == 0) { echo '<b><center>You have not yet rated this joke </center></b><br>'; } else { $rate = mysql_result($result, 0, 'Rating'); echo '<b><center>You have given this joke a rating of ' . $rate . '</center></b><br>'; } ?> <br> <a style="color: rgb(0, 0, 0);" href="/othersvote.php?ItemID=<?=$ItemID?>Click here to how the others rated this joke</a></td> </tr> <td align=center> <?=$message?> </td> </tr> <tr> <td> <?=$View_Item?> <br> <br> <hr size="1"> </td> </tr> <tr> <td align=center valign=top> <form method=post action="EmailFriend.php" name=sfriend onsubmit="return CheckFriend();"> <input type=hidden name=ItemID value="<?=$ItemID?>"> <table align=center border=0 bordercolor=black cellspacing=0 rules=none width=400> <tr> <td colspan=2> <center> <font size="2" face="Verdana, Arial, Helvetica, sans-serif"><b>Email this <?=$main_keyword?> to a friend</b></font></center></td> </tr> <tr> <td align=right>Your email address:</td> <td> <input type=text name=f1> </td> </tr> <tr> <td align=right>Your friends address:</td> <td> <input type=text name=f2> </td> </tr> <tr> <td colspan=2 align=center> <input type=checkbox checked name=f3 value=yes> Recieve <?=$main_keyword?> s in your email. <input type=submit name=sfr value=Send> <br> <br> </td> </tr> </table> </form></td> </tr> <tr> <td align=center valign=top> </td> </tr> </table> <? $joke = '$ItemID'; $result = mysql_query("SELECT ItemID FROM dd_items WHERE CategoryID = '$a1[itemCategory]' and ItemStatus = 'approved' ORDER by ItemID DESC"); while($row = mysql_fetch_array($result)) { if($row['ItemID'] == '$ItemID') { $next = $ItemID + 1; $prev = $ItemID - 1; } } ?> <a href="/view.php?=<?=$prev?>"Previous</a> <a href="/view.php?=<?=$Next?>"Next</a> <br><br> Link to comment https://forums.phpfreaks.com/topic/59926-next-and-previous-script/#findComment-298128 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.