DeadDude Posted May 21, 2007 Share Posted May 21, 2007 how would i go about calling the data from 2 different tables within a database to display on one form? cheers in advance James Quote Link to comment Share on other sites More sharing options...
effigy Posted May 21, 2007 Share Posted May 21, 2007 Joins. Quote Link to comment Share on other sites More sharing options...
DeadDude Posted May 21, 2007 Author Share Posted May 21, 2007 how would that work? i'm new to this to call the data from one of the table i've used echos up to now Quote Link to comment Share on other sites More sharing options...
chadrt Posted May 21, 2007 Share Posted May 21, 2007 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. Quote Link to comment Share on other sites More sharing options...
DeadDude Posted May 21, 2007 Author Share Posted May 21, 2007 is there any specific place i should put that? Quote Link to comment Share on other sites More sharing options...
chadrt Posted May 21, 2007 Share Posted May 21, 2007 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); Quote Link to comment Share on other sites More sharing options...
DeadDude Posted May 21, 2007 Author Share Posted May 21, 2007 so i can just add the next query to pull the data from the second table to the end of the query to pull the data from the first one? Quote Link to comment Share on other sites More sharing options...
chadrt Posted May 21, 2007 Share Posted May 21, 2007 Yeah and you can query as many tables as you like and I am assuming you know how to pull the fields from each record so I didnt put that code in there. Quote Link to comment Share on other sites More sharing options...
DeadDude Posted May 21, 2007 Author Share Posted May 21, 2007 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 Quote Link to comment Share on other sites More sharing options...
effigy Posted May 21, 2007 Share Posted May 21, 2007 If you don't need an actual join, you can use a UNION. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.