SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: mysql problem

Hybrid View

  1. #1
    SitePoint Zealot Harvy's Avatar
    Join Date
    Feb 2002
    Location
    Aberdeen, Scotland
    Posts
    101
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    mysql problem

    Hi folks

    Im having a problem trying to retrieve data from my mysql table.

    I would like to retrieve the last record in my database table but only the last record.

  2. #2
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    do you have an auto increment field? if so order by that....
    (bit cryptic I know but you haven't given me much to work with!)

    You could also use mysql_insert_id and last_insert...
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  3. #3
    SitePoint Guru MikeBigg's Avatar
    Join Date
    Jun 2004
    Location
    Reading, UK
    Posts
    970
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Do you have an id column?


    Sigh ... I keep getting beaten to the post. Must type faster
    Last edited by MikeBigg; Jan 4, 2005 at 09:41. Reason: Late post

  4. #4
    SitePoint Zealot Harvy's Avatar
    Join Date
    Feb 2002
    Location
    Aberdeen, Scotland
    Posts
    101
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah sorry guys should have explained better.

    right this is the code i have so far

    PHP Code:
    $test mysql_query"SELECT photo_id FROM gallery_photos");
    $nr mysql_num_rows$test );
    $prevphoto $pid 1;
    $nextphoto $pid 1;
    if (
    $nextphoto $nr) {
        
    $nextphoto 1;
    }
    if (
    $prevphoto 1) {
        
    $prevphoto $nr;
    }
     
    $result_final .= "<tr>\n\t<td>
         <a href='viewgallery.php'>Categories</a> &gt; 
         <a href='viewgallery.php?cid=
    $cid'>$category_name</a></td>\n";
    $result_final .= "<td align='center'>
         <a href='viewgallery.php?cid=1&pid=
    $prevphoto'>Previous Photo</a> &lt;&gt;
         <a href='viewgallery.php?cid=1&pid=
    $nextphoto'>Next Photo</a>$row</td>\n</tr>\n"
    It works fine untill someone tryed to go back on the first image ( which i want to send them to the last image in the database ) it sends them to the wrong picture because there are 142 records but the last image id is 144 because some where deleted.
    I hope you can understand that.


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
  •