VideoHelp Forum




+ Reply to Thread
Results 1 to 8 of 8
  1. Member thecoalman's Avatar
    Join Date
    Feb 2004
    Location
    Pennsylvania
    Search PM
    I'm tryin to display some info from a database. I have a table named test_table with three columns: key_id (a numbered column), name, and phone. I want to display just the field numbered 100 in the phone column. What I have is this which does work but displays the entire phone colunm, I just want entry number 100.
    Code:
    <?php 
     
    $result = @mysql_query('SELECT phone FROM test_table'); 
    if (!$result) { 
     exit('
    
    Error performing query: ' . mysql_error() . '</p>'); 
    } 
    
    while ($row = mysql_fetch_array($result)) { 
     echo '
    
    ' . $row['post_text'] . '</p>'; 
    } 
    
    ?>
    The other question I have is the information in block 100 is in three paragraphs but is displayed as a single paragraph when using the above code. How do I keep the pragraph formatting.
    Quote Quote  
  2. Always Watching guns1inger's Avatar
    Join Date
    Apr 2004
    Location
    Miskatonic U
    Search Comp PM
    It's been a while since I did any database programming, but the query you are running is an open query against that column and table. You need to limit it by including a 'where id_column = row_no' - id_column being your key column and row_no being the row you want returned. Or, put the check in the while statement and pick it up when you go through the results array. At the moment you just don't have anything there to tell it row 100 is what you want.
    Read my blog here.
    Quote Quote  
  3. Member thecoalman's Avatar
    Join Date
    Feb 2004
    Location
    Pennsylvania
    Search PM
    Example? I comprehend a little but I'm still learning. Heeeeeeeeeeelp me please, it's due tomorrow.
    Quote Quote  
  4. I'm a MEGA Super Moderator Baldrick's Avatar
    Join Date
    Aug 2000
    Location
    Sweden
    Search Comp PM
    Code:
    <?php
    
    $result = @mysql_query('SELECT * FROM test_table where key_id=100');
    if (!$result) {
    exit('
    
    Error performing query: ' . mysql_error() . '</p>');
    }
    
    while ($row = mysql_fetch_array($result)) {
    echo '
    
    '. $row['key_id']. $row['name'] . $row['phone'] . '</p>';
    }
    
    ?>
    if you want to list the name, phone keyid and keyid=100.
    Quote Quote  
  5. Member thecoalman's Avatar
    Join Date
    Feb 2004
    Location
    Pennsylvania
    Search PM
    Excellent, thanks Baldrick that works perfect. Can anyone answer my second question? How do I keep the formatting so the paragraphs don't run together?

    If I open up that specific cell in MySQL Query Browser it displays the correctly.
    Quote Quote  
  6. I'm a MEGA Super Moderator Baldrick's Avatar
    Join Date
    Aug 2000
    Location
    Sweden
    Search Comp PM
    you can add a space between each,
    . $row['key_id']. ' '. $row['name'] . ' ' .$row['phone'] .
    Quote Quote  
  7. Member thecoalman's Avatar
    Join Date
    Feb 2004
    Location
    Pennsylvania
    Search PM
    I guess I used the wrong terminology, what I'm trying to do is display a single post from phpbb post. It's in a hidden forum but I want to display it on other pages so I can't use phpbb fetchall. This is what I have in a file called test.php:
    Code:
    <html>
    <head> 
    <title>Test</title> 
    </head> 
    <body> 
     
    <?php 
    
    
    $result = @mysql_query('SELECT * FROM phpbb_posts_text where post_id=410'); 
    if (!$result) { 
     exit('
    
    Error performing query: ' . mysql_error() . '</p>'); 
    } 
    
    while ($row = mysql_fetch_array($result)) { 
    echo '<div>'. $row['post_text'] . '</div>'; 
    } 
    
    ?> 
    
    </body> 
    </html>
    The result I get is:

    paragraph 1 paragraph 2



    What I want is:

    paragraph 1

    paragraph 2
    Quote Quote  
  8. Member thecoalman's Avatar
    Join Date
    Feb 2004
    Location
    Pennsylvania
    Search PM
    After about 100 tries I came up with this:

    Code:
    <html>
    <head> 
    <title>Test</title> 
    </head> 
    <body> 
    
    <?php 
    
    $result = @mysql_query('SELECT * FROM phpbb_posts_text where post_id=410'); 
    if (!$result) { 
    exit('
    
    Error performing query: ' . mysql_error() . '</p>'); 
    } 
    
    while ($row = mysql_fetch_array($result)) { 
    echo nl2br('<div>' . $row['post_text'] . '</div>'); 
    } 
    
    
    ?> 
    
    </body> 
    </html>
    Any suggestions other suggestions if there's something wrong here that I should be aware of is appreciated.
    Quote Quote  



Similar Threads

Visit our sponsor! Try DVDFab and backup Blu-rays!