SitePoint Sponsor

User Tag List

Results 1 to 12 of 12
  1. #1
    SitePoint Enthusiast Yonko's Avatar
    Join Date
    Jun 2001
    Location
    Panama
    Posts
    79
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    What's wrong with this code???

    Help please, what am I doing wrong? I want to pull the previous to last record using the date and category id criteria from the database.

    PHP Code:
    <HTML>
    <HEAD>
    <TITLE> Test </TITLE>
    </HEAD>
    <BODY>
    <?PHP 

      $dbcnx 
    = @mysql_connect("localhost""root""***********");
      if (!
    $dbcnx) {
        echo( 
    "<P>No es posible conectar con " .
              
    "el servidor en este momento.</P>" );
        exit();
      }

      if (! @
    mysql_select_db("******") ) {
        echo( 
    "<P>No es posible localizar la " .
              
    "base de datos de noticias.</P>" );
        exit();
      }

      
    $result mysql_query("SELECT COUNT (*) FROM News")
        or exit();
      if (
    $row mysql_fetch_array ($result)) {
        
    $final mysql_query("SELECT Text FROM News WHERE Date=CURDATE() AND ID=$row[0] - 1 AND CID=1)
        or exit();
        echo 
    $final;
      }

    ?>
    </BODY>
    </HTML>

    Thanks

  2. #2
    SitePoint Addict manipura's Avatar
    Join Date
    Apr 2001
    Location
    Calgary,AB
    Posts
    345
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm guessing all you are getting is some kind of "Resource" being echo'd....

    You need to take the $final variable from the SQL Query and make a mysql_fetch_array()

    $row = mysql_fetch_array($final);

    Then you can either show the information by putting $row["field"] or what I like to do is make that a variable

    $field_name = $row["field_name"];

    Then wherever you put $field_name you will get the contents in that field...

    If you are querying for more then one row in the DB you can put a while() loop on your Mysql_Fetch_array. Then it will echo everything that the query has taken from the DB

  3. #3
    SitePoint Enthusiast Yonko's Avatar
    Join Date
    Jun 2001
    Location
    Panama
    Posts
    79
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Basically what I want to do is evaluate the total number of records (in this case news) and then display the last, last - 1 and last - 2 that meets my criteria of current date and category id (local news, international news or sports news). Do you think you have an idea of how can I do that? Thanks for your attention.

  4. #4
    SitePoint Addict manipura's Avatar
    Join Date
    Apr 2001
    Location
    Calgary,AB
    Posts
    345
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So what I'm guessing is that you want the last three rows from the query displayed?

  5. #5
    SitePoint Enthusiast Yonko's Avatar
    Join Date
    Jun 2001
    Location
    Panama
    Posts
    79
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    That's right! but...

    the case is I don't want to pull the three values in the same table, I want to set the three results as a newspaper layout.

    Like this:
    _________________ ________________
    |.........................||........................|
    |.........................||........................|
    |.........................||........................|
    | News = last id.....|| News = last - 1 |
    |.........................||........................|
    |.........................||........................|
    |_______________ ||_______________|
    |.........................||........................|
    |.........................||........................|
    |.........................||........................|
    | News = last - 2 ..||........................|
    |.........................||........................|
    |.........................||........................|
    |________________||_______________|

    Do you copy me?

  6. #6
    SitePoint Addict manipura's Avatar
    Join Date
    Apr 2001
    Location
    Calgary,AB
    Posts
    345
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not really... Can I guess that you want the last row from each table(local, int, sport), then display each on the page?

    I think whats confusing me is the last, last -1, last -2

  7. #7
    SitePoint Enthusiast Yonko's Avatar
    Join Date
    Jun 2001
    Location
    Panama
    Posts
    79
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Maybe...

    if you check the URL, you'll understand what I need to do:

    http://www.rcmtelevision.com/rcmtelevision.html

    The three news shown above (where the picture is), need to be from local news category (CID=1) and the two news shown below the blue line must come from the international news category (CID=2). The text of the news is Text.News and the title is Title.News. The page must show the most recent records from both categories ALWAYS. Any questions welcome. Please help! I'm on the edge of a nervous breakdown!

  8. #8
    SitePoint Addict manipura's Avatar
    Join Date
    Apr 2001
    Location
    Calgary,AB
    Posts
    345
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So to get this straight you want the news in the top right corner to be the latest news article.. Then when a new one comes you want it to move to the next spot, then when another one comes in move that article to the last spot. Then when one more article gets written it won't show up at all?
    Do you have a date field in your DB?

  9. #9
    SitePoint Enthusiast Yonko's Avatar
    Join Date
    Jun 2001
    Location
    Panama
    Posts
    79
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    That's right!

    This is my db structure:

    Table One is called News and contains [ID, Title, Text, Date, AID(author id), CID (category id)]
    The second one is Authors and contains (ID, Name, Email).
    The third one is Categories and contains (ID, Name).

    Is my database structure wrong? I can submit news to my tables, modify them, even display them all in a different page, I just don't know exactly how to pull the latest records from each category.

  10. #10
    SitePoint Addict manipura's Avatar
    Join Date
    Apr 2001
    Location
    Calgary,AB
    Posts
    345
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    structure seems right

    But what I think you should do is just make the query decending and put a limit on it. Limit 0,3 I think will grab the last three of the DB.

    All you want is the last(newest) article in position #1 Then, second newest in pos. #2, etc. right?

    Are you doing a loop and displaying them all at once or are you doing a different query for each one to be displayed?

  11. #11
    SitePoint Enthusiast Yonko's Avatar
    Join Date
    Jun 2001
    Location
    Panama
    Posts
    79
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Not exactly...


    All you want is the last(newest) article in position #1 Then, second newest in pos. #2, etc. right?
    No, read this:
    All I want is the newest article from the LOCAL NEWS category in position #1. Then the second newest from LOCAL NEWS in position #2 and then the third newest from LOCAL NEWS in position #3.

  12. #12
    Node mutilating coot timnz's Avatar
    Join Date
    Feb 2001
    Location
    New Zealand
    Posts
    516
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well I think manipura was telling you what you needed.

    You can either have a different query for each of the things, or a single query, and then display all the results from that accordingly.

    Like manipura said, you need to put a limit on your sql statement(s), to limit your results to the 3 latest.


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
  •