Jump to content

[SOLVED] calling data from 2 tables


DeadDude

Recommended Posts

Here try this:

 


$query1="SELECT * FROM table1 WHERE unique_id='$uidsearch'";
$resultam=mysql_query($query1);

$query2="SELECT * FROM table2 WHERE unique_id='$uidsearch'";
$resulten=mysql_query($query2);

$query3="SELECT * FROM table3 WHERE unique_id='$uidsearch'";
$resulthd=mysql_query($query3);

 

I have been told it is good method I use it and it works great.

After the code to open the database.

 

Mind you I am new to this as well I have only been programming in PHP for about a week now so there may be a better way to do it but here is a little piece of code I have put together for you.  This assumes that each table shares a common bond by having a unique ID for each record that matches the other tables.  So here goes:

 

# connection information
$username="SomeUSERnameHere";
$password="SomeUSERpassHere";
$database="YourDBname";
$dbhost="localhost";

# Connects to database
mysql_connect($dbhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

# Opens and searchs the database for a specific unique_id
$query1="SELECT * FROM table1 WHERE unique_id='$uidsearch'";
$resultam=mysql_query($query1);

$query2="SELECT * FROM table2 WHERE unique_id='$uidsearch'";
$resulten=mysql_query($query2);

$query3="SELECT * FROM table3 WHERE unique_id='$uidsearch'";
$resulthd=mysql_query($query3);

 

 

 

yeah done that in the previous query to get the data from the first table.

 

i've been using cookies as well which my tutor is making me lol and at the moment the table won't display anything so just trying to make sure i have all the code there so he can help me work out how to get it to display in the end table

 

cheers for your help

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.