SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Enthusiast
    Join Date
    Dec 2000
    Location
    USA
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    $result = mysql_query("SELECT * FROM Links ORDER BY stamp DESC");
    if (!$result){
    $body = "mysql_error()";
    $title = "Error!";
    }
    $i = 0;
    while ($row = mysql_fetch_array($result)) {
      $date = $row["date"];
      $url = $row["url"];
      $title = $row["title"];
      $descrip = $row["descrip"];
    $body = "<br><br><div align=center><center>" .
    "<table border=0 width=600 cellpadding=0 cellspacing=0><tr>" .
    "<td width=600 bgcolor=#000000></td></tr><tr><td width=600 bgcolor=#FCC403><table border=0 width=100% cellspacing=1><tr>" .
    "<td width=33%><strong><small><a href=$url>$title</a></small></strong></td>" .
    "<td width=33%><p align=right><small><small>Added on $date</small></small></td>" .
    "<td width=34%><p align=right><small><small><a href=addlink.php>Add your link</a></small></small></td>" .
    "</tr></table></td></tr><tr><td width=100% bgcolor=#000000></td></tr><tr>" .
    "<td width=100%><small>$descrip</small></td>" .
    "</tr></table></center></div>";
    $title = "Links";
    }
    Using that bit of code or editing it, how could I have the free for all links display only...say...50 links?

    Thanks, MethoD
    Living the OO way.
    Hardware Help | Desperados!

  2. #2
    SitePoint Wizard edshuck's Avatar
    Join Date
    Jul 2000
    Posts
    1,200
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi

    $result = mysql_query("SELECT * FROM Links ORDER BY stamp DESC");

    Modify the above code thusly and it should work.

    $result = mysql_query("SELECT * FROM Links ORDER BY stamp DESC LIMIT 50");

    Have not tried it but that is the proper implementation of the Limit

    peace


  3. #3
    SitePoint Evangelist
    Join Date
    May 2000
    Location
    Canada
    Posts
    533
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    just another thing I noticed:

    you might want to change

    if (!$result){

    to

    if (mysql_num_rows($result) == 0){

    -------------------
    SitePoint Community Advisor
    myPHPhost.com: when you want something MORE in a host

  4. #4
    SitePoint Enthusiast
    Join Date
    Dec 2000
    Location
    USA
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok thanks

    one more question

    Code:
    while ($row = mysql_fetch_array($result)) {
      $date = $row["date"];
      $url = $row["url"];
      $title = $row["title"];
      $descrip = $row["descrip"];
    $format = str_replace("<InsertTitle>", "$title", $format);
    $format = str_replace("<InsertDate>", "$date", $format);
    $format = str_replace("<InsertUrl>", "$url", $format);
    $format = str_replace("<InsertDescription>", "$descrip", $format);
    $body = $format;
    $title = "Links";
    }

    Hmmmmmmm. I'm stumped. I'm using a custom made template based ffa script and it stores everything it needs in the $body variable which is displayed later on. How can I get each generated link format ($format) into the $body var so I can display all of the links?
    Maybe an array?
    I'm not sure.
    Living the OO way.
    Hardware Help | Desperados!

  5. #5
    SitePoint Enthusiast
    Join Date
    Oct 2000
    Posts
    89
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $body .= $format;
    Great Dane
    Gokhan ARLI

  6. #6
    SitePoint Enthusiast
    Join Date
    Dec 2000
    Location
    USA
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmmm... That's not working either. It works just the same as doing

    $body = $body .
    $fearures

    It shows the latest link for however many entries there are in the database.
    Living the OO way.
    Hardware Help | Desperados!

  7. #7
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It seems that $format never gets reset to it s original value so after the first loop the str_replace never actually replaces anything I think you will need to declare $format in its original state at the beginning of the loop so that each time it goes through it has the proper $format string to work with.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  8. #8
    SitePoint Enthusiast
    Join Date
    Dec 2000
    Location
    USA
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Alright
    Thanks a lot!!!
    Living the OO way.
    Hardware Help | Desperados!


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
  •