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 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Feb 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    mysql table contents

    Hi,

    i am using the following code to view mysql db contents of a table, but when i view the page from a browser it is not showing any contents from the db,, any ideas what is wrong with the code..?

    The code is below

    List db contents here

    PHP Code:
    <? 
    //connect to mysql 
    //change user and password to your mySQL name and password 
    mysql_connect("localhost","mysql_username","mysql_password");  
         
    //select which database you want to edit 
    mysql_select_db("db_info");  

    //select the table 
    $result mysql_query("select * from address_book"); 


    ?>

    Thanks
    saj
    Last edited by guelphdad; 02-13-2007 at 01:26 AM.

  • #2
    Senior Coder koyama's Avatar
    Join Date
    Dec 2006
    Location
    Copenhagen, Denmark
    Posts
    1,246
    Thanks
    1
    Thanked 5 Times in 5 Posts
    Your code seems fine so far, but I don't see any code that will actually print any results.

    Try this instead which just prints the raw data results: (Notice also the die statements which are good for debugging when things go wrong)
    PHP Code:
    mysql_connect("localhost","mysql_username","mysql_password") or die("couldn't connect");

    mysql_select_db("db_info") or die("couldn't select database");

    $result mysql_query("select * from address_book") or die("Bad query");

    while(
    $row mysql_fetch_array($result)) {
      
    var_dump($row);


  • #3
    New to the CF scene
    Join Date
    Feb 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi,

    thank you for that piece of information, now i can see the info from the DB but it is not formatted, i want to format it so it is in a neat table listed below is the results of the first few of lines of what is showing,:--

    List db contents here array(26) { [0]=> string(1) "1" ["address_book_id"]=> string(1) "1" [1]=> string(1) "1" ["customers_id"]=> string(1) "1" [2]=> string(1) "m" ["entry_gender"]=> string(1) "m" [3]=> string(9) "ACME Inc." ["entry_company"]=> string(9) "ACME Inc." [4]=> string(4) "John" ["entry_firstname"]=> string(4) "John" [5]=> string(3) "Doe" ["entry_lastname"]=> string(3) "Doe" [6]=> string(12) "1 Way Street" ["entry_street_address"]=> string(12) "1 Way Street" [7]=> string(0) "" ["entry_suburb"]=> string(0) "" [8]=> string(5) "12345" ["entry_postcode"]=> string(5) "12345" [9]=> string(10) "NeverNever" ["entry_city"]=> string(10) "NeverNever" [10]=> string(0) "" ["entry_state"]=> string(0) "" [11]=> string(3) "223" ["entry_country_id"]=> string(3) "223" [12]=> string(2) "12" ["entry_zone_id"]=> string(2) "12" } array(26)

    Thanks
    saj

  • #4
    Regular Coder
    Join Date
    Jan 2007
    Posts
    213
    Thanks
    0
    Thanked 0 Times in 0 Posts
    then you would do something like...

    Code:
    mysql_connect("localhost","mysql_username","mysql_password") or die("couldn't connect");
    
    mysql_select_db("db_info") or die("couldn't select database");
    
    $result = mysql_query("select * from address_book") or die("Bad query");
    ?>
    <table cellpadding="0" cellspacing="2" border="1">
    <tr><th>Header 1</th><th>header2</th><th>header 3</th>
    <?php
    while($row = mysql_fetch_array($result)) {
      echo "<tr>";
      echo "<td>".$row['address_book_id']."</td>";
      echo "<td>".$row['customers_id']."</td>";
      echo "<td>".$stripslashes($row['entry_firstname'])."</td>";
      echo "</tr>";
    }  
    @mysql_free_result($sql);
    ?>
    </table>

    That of course is not the full code you are looking for but explains how you would get the content into a table.
    Matthew Bagley
    Paramiliar Design Studios
    Website Design | Website Development | Search Engine Optimisation (SEO)

  • #5
    Super Moderator guelphdad's Avatar
    Join Date
    Mar 2006
    Location
    St. Catharines, Ontario Canada
    Posts
    2,631
    Thanks
    4
    Thanked 147 Times in 138 Posts
    Wouldn't hurt for you to read a tutorial either, this is standard stuff. Search on "mysql and php tutorial" in any search engine.

  • #6
    New to the CF scene
    Join Date
    Feb 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi,

    i have just tried the code for listing the results into a table, but page only shows the header1 header2 header3 cells the rest comes up blank it , it is not showing the db contents at all,

    Thanks
    saj


  •  

    Posting Permissions

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