Results 1 to 5 of 5

Thread: Hexus style, news posting. Hows it done?

  1. #1
    Flak Monkey! Dorza's Avatar
    Join Date
    Jul 2003
    Location
    UK - South Wales
    Posts
    1,762
    Thanks
    34
    Thanked
    17 times in 15 posts
    • Dorza's system
      • Motherboard:
      • Asus P5B Deluxe - WiFi
      • CPU:
      • Q6600 @ 3.06Ghz
      • Memory:
      • 2GB Crucial
      • Storage:
      • 500GB Samsung SpinPoint
      • Graphics card(s):
      • Geforce 9600GT
      • PSU:
      • Cosair HX520W
      • Case:
      • LianLi something something or other
      • Monitor(s):
      • Eizo FlexScan S1910 (1280*1024)
      • Internet:
      • 2mb Virgin (when they want to give me that: else 1mb)

    Hexus style, news posting. Hows it done?

    1)

    Im currently working on a site which incorporates a database to hold the content for the site. The data on the home page shall be stored in a table called "content" The fields i have for this table include:

    id, cont_title, authorid, cont_txt, cont_date

    Im currently having problems segmenting the data when it is posted on the home page. Whenever i add new information to the database i simply get chunks of data all grouped together by their field names instead of being seen as single records. For example instead of each post appearing (on the home page)as:


    header1
    content1

    header2
    content2

    it appears as:

    header1
    header2

    text1
    text2

    i know why its doing it but i have no idea how to get around the problem. My php looks like this:

    This code is inserted just under the <body> tag
    PHP Code:
     // Request the title of all the posts
     
    $title = @mysql_query('SELECT cont_title FROM content');
     if (!
    $title) {
     exit(
    '<p>Error performing query: ' .
     
    mysql_error() . '</p>');
      }
      
       
    // Request the author of all the posts
     
    $author = @mysql_query('SELECT authorid FROM content');
     if (!
    $author) {
     exit(
    '<p>Error performing query: ' .
     
    mysql_error() . '</p>');
      }
        
      
    // Request the ID and text of all the jokes
     
    $cont = @mysql_query('SELECT id, cont_txt FROM content');
     if (!
    $cont) {
     exit(
    '<p>Error performing query: ' .
     
    mysql_error() . '</p>');
      } 
    Then i add the following to display the data:

    PHP Code:
            <?php

            
    // Displays the header of each post
            
    while ($row mysql_fetch_array($title)) { echo '' $row['cont_title'] . '';}
              
    // Displays the author of each post. NOTE: NO AUTHORID OR AUTHOR TABLE CURRENTLY SETUP-THIS DISPLAYS 0
            
    while ($row mysql_fetch_array($author)) { echo '' $row['auhorid'] . '';}
            
    // Displays the text of each post
            
    while ($row mysql_fetch_array($cont)) { echo '' $row['cont_txt'] . '';}

            
    ?>
    I believe that the ^ code is the problem since there’s no segregation of each individual record. How would i separate them so that i get some sort of posting system that hexus or neowin has?

    If ive lost anyone with my explanations please say and ill try to clear my question up

    Im using the PHP & MySql book by sitepoint. I may have mist it but i dont think that book covers what the above is stating.

    PS:A minor annoyance but how do you change the date formatting in MySql tables? It's currently set to yyyy-mm-dd when i want it to be the standard british layout.
    Last edited by Dorza; 03-04-2005 at 10:48 PM.

  2. #2
    Large Member
    Join Date
    Apr 2004
    Posts
    3,720
    Thanks
    47
    Thanked
    99 times in 64 posts
    You want just the one SQL query which selects all the fields from your table i.e.

    SELECT * FROM content

    You then want to perform your display operations and have the whole thing in a loop or similar, commonly known as a repeat region i.e.

    while (not last record in db)
    echo field title
    echo field author
    echo field content
    move to next record
    end while

    at the moment with your seperate select statements and seperate while loops you are just retreiving the values from one column at a time, instead of one row at a time.
    Last edited by yamangman; 04-04-2005 at 02:46 AM.
    To err is human. To really foul things up ... you need a computer.

  3. #3
    Flak Monkey! Dorza's Avatar
    Join Date
    Jul 2003
    Location
    UK - South Wales
    Posts
    1,762
    Thanks
    34
    Thanked
    17 times in 15 posts
    • Dorza's system
      • Motherboard:
      • Asus P5B Deluxe - WiFi
      • CPU:
      • Q6600 @ 3.06Ghz
      • Memory:
      • 2GB Crucial
      • Storage:
      • 500GB Samsung SpinPoint
      • Graphics card(s):
      • Geforce 9600GT
      • PSU:
      • Cosair HX520W
      • Case:
      • LianLi something something or other
      • Monitor(s):
      • Eizo FlexScan S1910 (1280*1024)
      • Internet:
      • 2mb Virgin (when they want to give me that: else 1mb)
    Sorry i havent replied to ur response. Been fiddleing round with various CMS the last few days so i didnt have time to implement what you suggested to me. Anyway...

    Im a little confused as to what to do with the While statement. Does it go where i want the content to appear? And how to i determinethe (not last record ) and move to next record parts?

  4. #4
    Large Member
    Join Date
    Apr 2004
    Posts
    3,720
    Thanks
    47
    Thanked
    99 times in 64 posts
    I suggest you search google for: mysql_fetch_assoc()
    To err is human. To really foul things up ... you need a computer.

  5. #5
    Flak Monkey! Dorza's Avatar
    Join Date
    Jul 2003
    Location
    UK - South Wales
    Posts
    1,762
    Thanks
    34
    Thanked
    17 times in 15 posts
    • Dorza's system
      • Motherboard:
      • Asus P5B Deluxe - WiFi
      • CPU:
      • Q6600 @ 3.06Ghz
      • Memory:
      • 2GB Crucial
      • Storage:
      • 500GB Samsung SpinPoint
      • Graphics card(s):
      • Geforce 9600GT
      • PSU:
      • Cosair HX520W
      • Case:
      • LianLi something something or other
      • Monitor(s):
      • Eizo FlexScan S1910 (1280*1024)
      • Internet:
      • 2mb Virgin (when they want to give me that: else 1mb)
    Thanks reading about it now

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Hows about a big old hexus fly?
    By menthel in forum PC
    Replies: 7
    Last Post: 21-08-2004, 06:45 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •