Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: array table

  1. #1
    New to the CF scene
    Join Date
    Oct 2008
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    array table

    im trying to get an array of information from my database and post each record into a separate table for a guestbook. iv got it working so the data is added to the database but cant seem to get the array working to show the data.
    Heres my code for the viewguestbook page:

    <?php

    $host="localhost";
    $username="root";
    $password="";
    $db_name="mywebsite";
    $tbl_name="guestbook";

    mysql_connect("$host", "$username", "$password")or die("cannot connect server ");
    mysql_select_db("$db_name")or die("cannot select DB");

    $sql="SELECT * FROM $tbl_name";
    $result=mysql_query($sql);

    while($rows=mysql_fetch_array($result));
    ?>

    <table width="400" border="0" align="center" cellpadding="3" cellspacing="0">
    <tr>
    <td><div align="left"><strong><span class="style1">View Guestbook | <a href="guestbook.php">Sign Guestbook</a></span> </strong></div></td>
    </tr>
    </table>
    <center> <table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#c4c2c2">

    <tr>
    <td width="117"><span class="style1">Name</span></td>
    <td width="14">:</td>
    <td width="357"><?php echo $rows['name']; ?></td>
    </tr>
    <tr>
    <td><span class="style1">Email</span></td>
    <td>:</td>
    <td><?php echo $rows['email']; ?></td>
    </tr>
    <tr>
    <td valign="top"><span class="style1">Comment</span></td>
    <td valign="top">:</td>
    <td><?php echo $rows['comment']; ?></td>
    </tr>
    <tr>
    <td height="25" valign="top"><span class="style1">Date/Time </span></td>
    <td valign="top">:</td>
    <td><?php echo $rows['datetime']; ?></td>
    </tr>
    </table>
    <br></center></div>


    <table width="400" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
    <tr>

    </tr>
    </table>
    <BR>
    <?php

    mysql_close();
    ?>

    any pointers would be really appreciated as it is for my dissertation which is due in soon and this is all i need to complete my work.

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Check to make sure your query worked.

  • #3
    New Coder
    Join Date
    Jan 2009
    Posts
    91
    Thanks
    17
    Thanked 1 Time in 1 Post
    Confused what the second table is for?!

    PHP Code:
    <table width="400" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
    <
    tr>

    </
    tr>
    </
    table>
    <
    BR
    If you are asking how to take each $row from the query and display it then I would try something like:

    PHP Code:
    while($rows=mysql_fetch_array($result)) {
    ?>
    "Table Code Here"
    <?
    }
    ?>


  •  

    Posting Permissions

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