Jump to content

next and previous script


jck

Recommended Posts

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
Share on other sites

<?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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.