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

    Displaying MySQL Records in a Table

    Hi Everyone,

    Well basically I am not very savvy with PHP, however I do wish to get rather proficient to help me build websites etc. (I am proficient with VB6 and Java)

    What I would like to know is how I would go about displaying records linked with a Primary Key in 4 different tables, in one formatted HTML Table on a website.

    The four tables are:

    - globaliddb_ids
    - globaliddb_names
    - phphlsw_logs
    - phphlsw_users

    The concept is really easy, but I have no idea about how to go about doing such a thing in PHP. I have looked at a number of solutions via Googling, but they only cover displaying records that exist in one MySQL Table.

    Thanks in Advance,

    Adam

  • #2
    Regular Coder mic2100's Avatar
    Join Date
    Feb 2006
    Location
    Scunthorpe
    Posts
    562
    Thanks
    15
    Thanked 28 Times in 27 Posts
    here is an example of what i was using, i learnt it this way by using dreamweaver's built in tools. hopefully you can figure out what its doing from this, but i don't think it is any harder than Java.

    PHP Code:
    <?

    $hostname_conn_hes 
    "conection_string";
    $database_conn_hes "database";
    $username_conn_hes "username";
    $password_conn_hes "password";
    $conn_hes mysql_connect($hostname_conn_hes$username_conn_hes$password_conn_hes) or trigger_error(mysql_error(),E_USER_ERROR); 

    mysql_select_db($database_conn_hes$conn_hes);
    //use your query here
    $query_rs_getUserNames "SELECT * FROM users";
    $rs_getUserNames mysql_query($query_rs_getUserNames$conn_hes) or die(mysql_error());
    $row_rs_getUserNames mysql_fetch_assoc($rs_getUserNames);
    $totalRows_rs_getUserNames mysql_num_rows($rs_getUserNames);

    if(
    $totalRows_rs_getUserNames 0)
    {
        
        do
        {
            
            
    //any field you you wish to display can be echo out like so.
            //you just type the field name in the piece where it says
            //'username'
            
    echo $row_rs_getUserNames['username']."<BR>";
        
        }
        while(
    $row_rs_getUserNames mysql_fetch_assoc($rs_getUserNames));

    }
    else
    {

        echo 
    "There are no records to display";

    }

    ?>

  • #3
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,638
    Thanks
    2
    Thanked 404 Times in 396 Posts
    Why would you use a do/while() there instead of just a while() loop?

  • #4
    New to the CF scene
    Join Date
    Nov 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for the help, i'll try post my final code if I get it working.

    Ok. I know how to do it for one field, but can I do more than one query to link to another field?
    Last edited by petro007; 11-07-2007 at 10:32 PM.

  • #5
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,638
    Thanks
    2
    Thanked 404 Times in 396 Posts
    Lookup "SQL Joins" so you can select all the fields you need with one query.


  •  

    Posting Permissions

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