SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    May 2007
    Location
    Oslo, Norway
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Problem with previous/next row in array

    Hi folks,

    The script below works fine with almost the same array, except that sectorid is set to 1. This file is in a different folder.
    Anyway, the second script below won't work...? And right now there are 4 image listings in the database with sectorid 2.

    Can anyone help me with figure this out? Is there another way to make this work?

    I also want a number listing between the arrows. If there are 20 images in the array I want people to be able to navigate directly to i.e. image 15. Does anyone know how to do this? Should I use paginating?
    Thanks!

    PHP Code:
    // initialization

    $pid = (int)($_GET['pid']);

    // Finds the previous and next image in the array

    $result3 mysql_query"SELECT photo_id, sectorid FROM photos 
    WHERE sectorid=2
    ORDER BY date" 
    );
    $num_rows mysql_num_rows$result3 );

    $j=0;
    while (
    $num_rows $j) {
    $prev=mysql_result($result3,$j,"photo_id");

    $j++;

    $myarray = array("$j"=>"$prev");
    foreach(
    $myarray as $key=>$value2) {
    if (
    $value2 == "$pid"){

    $b=($key);
    $a=($key-1);
    $c=($key+1);

    }}
    }

    if(
    $a == "0") {
    echo 
    "<span class='nextimg'>No photos found</span>";
    } else {
    if(
    $key == "$value2"
    echo 
    "<span class='nextimg'><a href=index.php?sid=2&pid=$a><img src='../images/arrow_left.gif' border='0' /></a></span>";
    }


    $i=0;
    while (
    $i $num_rows) {
    $next=mysql_result($result3,$i,"photo_id");

    $i++;

    $myarray = array("$i"=>"$next");
    foreach(
    $myarray as $key=>$value) {
    if (
    $value == "$pid"){

    $b=($key);
    $a=($key-1);
    $c=($key+1);

    }}

    if (
    $num_rows $value) {
    echo 
    "<span class='previmg'>No photos found</span>";
    } else {
    if (
    $key == "$c") echo "<span class='previmg'><a href=index.php?sid=2&pid=$value><img src='../images/arrow_right.gif' border='0' /></a></span>";
    }
    }
    ?> 

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,506
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    I don't see a second script?
    And what does "doesn't work" mean? What is the script supposed to do, and what does it do instead?
    Yes, you might want to look into pagination.

  3. #3
    SitePoint Enthusiast
    Join Date
    May 2007
    Location
    Oslo, Norway
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry, the above script works fine.
    Here is the one that don't work:

    PHP Code:
    // initialization

    $pid = (int)($_GET['pid']);

    // Finds the previous and next image in the array

            
    $result3 mysql_query"SELECT photo_id, sectorid, photo_filename FROM photos 
            WHERE sectorid=2
            ORDER BY date" 
    );
            
    $num_rows mysql_num_rows$result3 );

    $j=0;
    while (
    $num_rows $j) {
    $prev=mysql_result($result3,$j,"photo_id");

    $j++;

    $myarray = array("$j"=>"$prev");
    foreach(
    $myarray as $key=>$value2) {
    if (
    $value2 == "$pid"){

    $b=($key);
    $a=($key-1);
    $c=($key+1);

    }}
    }

    if(
    $a == "0") {
    echo 
    "<span class='nextimg'>No photos found</span>";
    } else {
    if(
    $key == "$value2"
    echo 
    "<span class='nextimg'><a href=index.php?sid=2&pid=$a><img src='../images/arrow_left.gif' border='0' /></a></span>";
    }


    $i=0;
    while (
    $i $num_rows) {
    $next=mysql_result($result3,$i,"photo_id");

    $i++;

    $myarray = array("$i"=>"$next");
    foreach(
    $myarray as $key=>$value) {
    if (
    $value == "$pid"){

    $b=($key);
    $a=($key-1);
    $c=($key+1);

    }}

    if (
    $num_rows $value) {
    echo 
    "<span class='previmg'>No photos found</span>";
    } else {
    if (
    $key == "$c") echo "<span class='previmg'><a href=index.php?sid=2&pid=$value><img src='../images/arrow_right.gif' border='0' /></a></span>";
    }

    The script is supposed to navigate to the next row in the array. It adds to the $pid variable with +/1. "mysite.no/folder/index.php?sid=1&pid=12".
    It should move to pid=11/pid=13 next - showing the prevoius/next image in the array.

    R


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •