List all records?

Discussion in 'PHP' started by jmansa, Aug 4, 2006.

  1. #1
    I'm working on a script to show all records from a certain table in my DB, but I can only make it show the first. How do I make it show all???

    
    $query="SELECT * FROM names ORDER BY name DESC"; 
    $result=mysql_query($query) or die("Unable to find requested user");
    $currUser = mysql_fetch_array($result);
    
    
    ?>
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td><?php echo ("<b>" . $currUser['name'] . "</b>"); ?></td>
          </tr>
        </table></td>
        <td>&nbsp;</td>
      </tr>
    </table>
    
    Code (markup):

     
    jmansa, Aug 4, 2006 IP
  2. [*-AnOnYmOuS-*]

    [*-AnOnYmOuS-*] Active Member

    Messages:
    253
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    58
    #2
    This is supposed to work fine, if it doesn't remember you just have to loop through the results from the DB.
     
    [*-AnOnYmOuS-*], Aug 4, 2006 IP
  3. goldensea80

    goldensea80 Well-Known Member

    Messages:
    422
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    128
    #3
    Try this

    
    $query="SELECT * FROM names ORDER BY name DESC"; 
    $result=mysql_query($query) or die("Unable to find requested user");
    
    while ($currUser = mysql_fetch_array($result))
    {
    ?>
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td><?php echo ("<b>" . $currUser['name'] . "</b>"); ?></td>
          </tr>
        </table></td>
        <td>&nbsp;</td>
      </tr>
    </table>
    
    <?
    }
    ?>
    
    Code (markup):
     
    goldensea80, Aug 4, 2006 IP
  4. [*-AnOnYmOuS-*]

    [*-AnOnYmOuS-*] Active Member

    Messages:
    253
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    58
    #4
    Thats the same thing I wrote...
     
    [*-AnOnYmOuS-*], Aug 4, 2006 IP
  5. akashif

    akashif Guest

    Best Answers:
    0
    #5
    <?php
    query="SELECT * FROM names ORDER BY name DESC";
    $result=mysql_query($query) or die("Unable to find requested user");
    ?>
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
    <td>USER NAME</td>
    <td>COLUMN 2</td>
    </tr>

    <?php
    while ($currUser = mysql_fetch_array($result))
    {
    ?>
    <tr>
    <td><?php echo $currUser['name']; ?></td>
    <td><?php echo $currUser['COL2']; ?></td>
    </tr>
    <?
    }
    ?>
    </table>
     
    akashif, Aug 4, 2006 IP
  6. [*-AnOnYmOuS-*]

    [*-AnOnYmOuS-*] Active Member

    Messages:
    253
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    58
    #6
    Oh yeah your right. I forgot he wasn't aiming to duplicate all this html..
     
    [*-AnOnYmOuS-*], Aug 4, 2006 IP