Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with next/previous links script....

Status
Not open for further replies.

meeble

Programmer
Sep 24, 2002
137
GB
Hello,

I have this script which creates 'next' and 'previous' links so you can cycle through images. It works fine, but if there is only one image, I would like the 'next' link to not show up.

How can I do this please?

The code currently is:

Code:
$SQL="SELECT * FROM images where pubid='$jio' order by imageid";
$SQL_Query=mysql_db_query($DB_Name, $SQL);
$Total=mysql_num_rows($SQL_Query);
// Append a LIMIT clause to the SQL statement
if (!$Result_Set)
   {
   $Result_Set=0;
   $SQL.=" LIMIT $Result_Set, $Per_Page";
   }else
   {
   $SQL.=" LIMIT $Result_Set, $Per_Page";
   }
// Run The Query With a Limit to get result
$SQL_Query=mysql_db_query($DB_Name, $SQL);
$SQL_Rows=mysql_num_rows($SQL_Query);
// Display Results using a for loop
for ($a=0; $a < $SQL_Rows; $a++)
    {
    $SQL_Array=mysql_fetch_array($SQL_Query);
    $Description=$SQL_Array['image_name'];

    echo &quot;<img src=\&quot;pubimages/$Description\&quot;><BR><BR>&quot;;

        }
// Create Next / Prev Links and $Result_Set Value
if ($Total>0)
   {
   if ($Result_Set<$Total && $Result_Set>0)
      {
      $Res1=$Result_Set-$Per_Page;
      echo &quot;<A class=\&quot;blue\&quot; HREF=\&quot;vacancies4.php?Result_Set=$Res1&jio=$jio&pubname=$pubname&street=$street&town=$town&county=$county&pcode=$pcode&description=$description\&quot;>Previous Image</A>&nbsp;&quot;;
      }
   if ($Result_Set>=0 && $Result_Set<$Total)
      {
      $Res1=$Result_Set+$Per_Page;
      if ($Res1<$Total)
         {
         echo &quot;&nbsp;<A class=\&quot;blue\&quot; HREF=\&quot;vacancies4.php?Result_Set=$Res1&jio=$jio&pubname=$pubname&street=$street&town=$town&county=$county&pcode=$pcode&description=$description\&quot;>Next Image</A>&quot;;
         }
      if ($Res1==$Total)
         {
         $Res1=0;
         echo &quot;&nbsp;<A class=\&quot;blue\&quot; HREF=\&quot;vacancies4.php?Result_Set=$Res1&jio=$jio&pubname=$pubname&street=$street&town=$town&county=$county&pcode=$pcode&description=$description\&quot;>Next Image</A>&quot;;
         }
      }
   }

Many thanks

James
 
Add another &quot;if&quot; statement to your code which tests whether $SQL_Rows is greater than 1 and only output the link if it is. ______________________________________________________________________
TANSTAAFL!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top