SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    As you can see i am using a PHP/MySQL solution.

    What i have in my script is:

    I select articles from database and sort them all by date. Then i need to get say, 6 of them and then display them with a line break between them.

    The only part i am struggling with is getting only 6 results then displaying only six.

    dbname= petesmc_articles
    table = article, authors

    field = SELECT AID, DateAdded, Title, Description, Name WHERE AuthorID=author.ID ORDER BY DateAdded DESC


    //SLECT SIX NEWEST ARTICLES

    // DISPLAY


    Can anyone help me fill in the gaps?

    Thanx

  2. #2
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So you want to grab all articles but only display 6 at a time with a line break between each six?

    $i = 1;
    $result = mysql_query("SELECT AID, DateAdded, Title, Description, Name WHERE AuthorID=author.ID ORDER BY DateAdded DESC ");

    while($row = mysql_fetch_array($result)) {

    print $row["whatever"];

    if ($i == 6) print "<br>";

    $i++;

    }
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  3. #3
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry if i wasn't clear enough. I just want to grab to top 6 records and display each record with a line break between them.

    So only 6 can be displayed on the page and only the 6 most recent. None other.

    Sorry about that.

  4. #4
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $result = mysql_query("SELECT AID, DateAdded, Title, Description, Name WHERE AuthorID=author.ID ORDER BY DateAdded DESC LIMIT 6");

    while($row = mysql_fetch_array($result)) {
    print $row["whatever"];
    print "<br>";
    }

    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  5. #5
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanx allot

  6. #6
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Another question about something i just noticed.

    i have an INSERT statment saying:

    $sql = "INSERT INTO articles SET " .
    "AuthorID='$authorid', " .
    "CatID='$catid', " .
    "SubID='$subid', " .
    "DateAdded='CURDATE()', " .
    "Description='$description', " .
    "Title='$title', " .
    "Text='$text'";

    but it isn't inserting the current date into the field. How can i do this?

  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)
    cause CURDATE() is a function you will need to either assign it to a var before the insert statement or conactenate in there.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  8. #8
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How would i do that?

  9. #9
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    don't worry, i did this:

    "DateAdded=CURDATE()";

    Thanx


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
  •