SitePoint Sponsor

User Tag List

Results 1 to 13 of 13
  1. #1
    SitePoint Addict
    Join Date
    Jun 2007
    Location
    Plymouth uk
    Posts
    313
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    need help to display records in database

    ok i have the following script which displays some records from my database
    it displays them on screen
    what i would like to do is display one at a time then press next to view next
    i am guessing it would involve some thing like
    for r= 1 to ?
    input
    next r

    PHP Code:
     $data mysql_query("SELECT * FROM register WHERE state='lost' and type='dog'") or die(mysql_error());
    //Puts it into an array 
    while($info mysql_fetch_array$data )) 

    for 
    1 to 10
    //Outputs the image and other data
    Echo "<img src=http://www.lostpetsplymouth.com/images/".$info['pname'] ." alt=\"Image\" align=\"left\" width=\"100px\" height=\"100px\" hspace=\"10px\" vspace=\"8px\"> <br>";
    Echo 
    "<b>Area:</b> ".$info['area'] . " <br>";
    Echo 
    "<b>Description:</b> ".$info['desc'] . " <br>";
    Echo 
    "<b>Tel:</b> ".$info['tel'] . " <br>";
    Echo 
    "<b>Date of listing:</b> ".$info['date'] . " <hr>";
    input 
    next r



    ?> 
    am i on the right track
    cheers
    Doug
    an old man of 60 trying to keep up with the youngsters he he
    http://lostpetsplymouth.net16.net

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,494
    Mentioned
    161 Post(s)
    Tagged
    4 Thread(s)
    No. It means passing the key value of the displayed record through the link of your 'next' button, and writing the query in such a way that it'll extract the row following the passed key value.

  3. #3
    SitePoint Zealot Steveiwonder's Avatar
    Join Date
    Nov 2008
    Posts
    151
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by guido2004 View Post
    No. It means passing the key value of the displayed record through the link of your 'next' button, and writing the query in such a way that it'll extract the row following the passed key value.
    What he said

  4. #4
    SitePoint Addict
    Join Date
    Jun 2007
    Location
    Plymouth uk
    Posts
    313
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok i havnt got a clue
    so could i just put a input next button in the loop without the for next etc
    cheers
    Doug
    an old man of 60 trying to keep up with the youngsters he he
    http://lostpetsplymouth.net16.net

  5. #5
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,494
    Mentioned
    161 Post(s)
    Tagged
    4 Thread(s)
    Does your table have a unique key? Something like an autoincrement field calles registerID or something like that?

  6. #6
    SitePoint Addict
    Join Date
    Jun 2007
    Location
    Plymouth uk
    Posts
    313
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:

    //Outputs the image and other data
    Echo "<img src=http://www.lostpetsplymouth.com/images/".$info['pname'] ." alt=\"Image\" align=\"left\" width=\"100px\" height=\"100px\" hspace=\"10px\" vspace=\"8px\"> <br>";
    Echo 
    "<b>Area:</b> ".$info['area'] . " <br>";
    Echo 
    "<b>Description:</b> ".$info['desc'] . " <br>";
    Echo 
    "<b>Tel:</b> ".$info['tel'] . " <br>";
    Echo 
    "<b>Date of listing:</b> ".$info['date'] . " <hr>";
    [
    COLOR="Red"]Put some thing here to Pause[/COLOR]

    what i cant understand is why i cant just put a pause or next button as it is looping if you see what i mean
    cheers
    Doug
    an old man of 60 trying to keep up with the youngsters he he
    http://lostpetsplymouth.net16.net

  7. #7
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,494
    Mentioned
    161 Post(s)
    Tagged
    4 Thread(s)
    Never mind the unique key

    PHP Code:
    $count 0;
    if (isset(
    $_GET['count']) && ((int)$_GET['count'] > 0)) $count = (int)$_GET['count'];

    $sql "
      SELECT * 
      FROM register 
      WHERE state='lost' 
      AND type='dog' 
      LIMIT 
    $count, 2
      "
    ;
    $data mysql_query($sql) or die(mysql_error());
    $info mysql_fetch_array$data ); 

    //Outputs the image and other data

    Echo "<img src=http://www.lostpetsplymouth.com/images/".$info['pname'] ." alt=\"Image\" align=\"left\" width=\"100px\" height=\"100px\" hspace=\"10px\" vspace=\"8px\"> <br>";

    Echo 
    "<b>Area:</b> ".$info['area'] . " <br>";

    Echo 
    "<b>Description:</b> ".$info['desc'] . " <br>";

    Echo 
    "<b>Tel:</b> ".$info['tel'] . " <br>";

    Echo 
    "<b>Date of listing:</b> ".$info['date'] . " <hr>";

    //Output the previous and next links
    if ($count 0) {
      
    $previous $count 1;
      echo 
    '<a href="scriptname.php?count=' $previous '">Previous</a>';
    }
    if (
    mysql_num_rows($data) > 1) {
      
    $next $count 1;
      echo 
    '<a href="scriptname.php?count=' $next '">Next</a>';


  8. #8
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,494
    Mentioned
    161 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by dougvcd View Post
    PHP Code:

    //Outputs the image and other data
    Echo "<img src=http://www.lostpetsplymouth.com/images/".$info['pname'] ." alt=\"Image\" align=\"left\" width=\"100px\" height=\"100px\" hspace=\"10px\" vspace=\"8px\"> <br>";
    Echo 
    "<b>Area:</b> ".$info['area'] . " <br>";
    Echo 
    "<b>Description:</b> ".$info['desc'] . " <br>";
    Echo 
    "<b>Tel:</b> ".$info['tel'] . " <br>";
    Echo 
    "<b>Date of listing:</b> ".$info['date'] . " <hr>";
    [
    COLOR="Red"]Put some thing here to Pause[/COLOR]

    what i cant understand is why i cant just put a pause or next button as it is looping if you see what i mean
    cheers
    Doug
    Because PHP is a server side language. If you want to pause the looping, then you'd have to use a client side language like Javascript. You might extract all rows from the database, loop through them to put the data in a JS array and display the first row. Then you'd have to write a javascript script that would manage the displaying of the next row when the button is pressed.

  9. #9
    SitePoint Addict
    Join Date
    Jun 2007
    Location
    Plymouth uk
    Posts
    313
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok thanks for the info will try that bit of code you have put here
    cheers
    Doug
    an old man of 60 trying to keep up with the youngsters he he
    http://lostpetsplymouth.net16.net

  10. #10
    SitePoint Addict
    Join Date
    Jun 2007
    Location
    Plymouth uk
    Posts
    313
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok have tried that bit of code and displays the first record and shows next button
    but if you press button get a 404 page
    cheers
    Doug
    an old man of 60 trying to keep up with the youngsters he he
    http://lostpetsplymouth.net16.net

  11. #11
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,494
    Mentioned
    161 Post(s)
    Tagged
    4 Thread(s)
    Of course
    You'll have to change this with the name of your script:

    href="scriptname.php

  12. #12
    SitePoint Addict
    Join Date
    Jun 2007
    Location
    Plymouth uk
    Posts
    313
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    many thanks good buddy
    starting to look good found the mistake i made about changing that line
    now working ok
    cheers
    Doug
    an old man of 60 trying to keep up with the youngsters he he
    http://lostpetsplymouth.net16.net

  13. #13
    SitePoint Addict
    Join Date
    Jun 2007
    Location
    Plymouth uk
    Posts
    313
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok i have just one question is it poss to put a space between
    next and previous when displayed on screen
    cheers
    Doug
    an old man of 60 trying to keep up with the youngsters he he
    http://lostpetsplymouth.net16.net


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
  •