Browsing MySQL array? Help!

Discussion in 'Programming' started by livingearth, Oct 30, 2006.

  1. #1
    I am trying to set up the typical " First << Prev Next>> Last" type navigation on a php photography site. I came up with a work around that is a bit buggy and would like to do it better. Can anyone here help me find a better solution ? Here is my existing arrangement...

    
    
    <?php
    
    if($cat == $photo_category){
        $prev = ($photo - 1);
        echo "<center><a class=type1 href=\"site_photo.php?
    
    photo=$prev&cat=$cat\"><font face=\"Tahoma\">< < Previous<font 
    
    face=\"Tahoma\"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n
    
    bsp;\n";
    }
    if($cat == $photo_category){
        $next = ($photo + 1);
        echo "<a href=\"site_photo.php?photo=$next&cat=$cat\"><font 
    
    face=\"Tahoma\">Next > ></font></a></center><br>\n";
    }
    if($cat != $photo_category){
        $prev = ($photo - 1);
        echo "<html><head><meta http-equiv=\"Refresh\" 
    
    content=\"0;url=site_gallery.php&cat=$cat\"> 
    
    </head><body></body></html>\n";
    }
    ?>
    
    
    
    <?php
            $thisimage = '0';
    	include("setting.php"); 
    	$db_connect = mysql_connect($db_host, $db_username, 
    
    $db_password);
    	mysql_select_db($db_name, $db_connect) || die(mysql_error());
    
    	$sql_query		= "SELECT * FROM photo WHERE 
    
    photo_category = '$cat'";
    	$result			= mysql_query($sql_query) or die
    
    (mysql_error());
    	$row			= mysql_fetch_array($result);
    
    //echo"$row(prev)";
    //echo"$row(next)";
    //echo"$result(last)";
    //echo"<p>";
    
    while ($row = mysql_fetch_array($result)) {
    $field1 = $row["photo_id"];
    $field2 = $row["photo_file"];
    $field3 = $row["photo_code"];
    $field4 = $row["photo_category"];
    $thisimage++;
    if($photo == $field1){
    echo " <a href='site_photo.php?photo=$field1&cat=$field4'><font 
    
    color=#ffffff face=tahoma size=1><small>$thisimage</small></a> &nbsp; 
    
    &nbsp; ";
    }
    else{
    echo " <a href='site_photo.php?photo=$field1&cat=$field4'><font 
    
    color=#aaaaaa face=tahoma size=1><small>$thisimage</small></a> &nbsp; 
    
    &nbsp; ";
    }
    }
    ?>
    
    
    
    PHP:
     
    livingearth, Oct 30, 2006 IP
  2. livingearth

    livingearth Well-Known Member

    Messages:
    1,469
    Likes Received:
    83
    Best Answers:
    0
    Trophy Points:
    140
    #2
    no ideas? I figured for sure I had come to the right place...
     
    livingearth, Oct 30, 2006 IP