View Full Version : Displaying MySQL Records in a Table

11-07-2007, 09:02 AM
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,


11-07-2007, 03:53 PM
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.


$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)


//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
echo $row_rs_getUserNames['username']."<BR>";

while($row_rs_getUserNames = mysql_fetch_assoc($rs_getUserNames));


echo "There are no records to display";



11-07-2007, 06:47 PM
Why would you use a do/while() there instead of just a while() loop?

11-07-2007, 11:29 PM
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?

11-08-2007, 05:14 AM
Lookup "SQL Joins" so you can select all the fields you need with one query.