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 Link to comment https://forums.phpfreaks.com/topic/52387-solved-calling-data-from-2-tables/ Share on other sites More sharing options...
effigy Posted May 21, 2007 Share Posted May 21, 2007 Joins. Link to comment https://forums.phpfreaks.com/topic/52387-solved-calling-data-from-2-tables/#findComment-258510 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 Link to comment https://forums.phpfreaks.com/topic/52387-solved-calling-data-from-2-tables/#findComment-258512 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. Link to comment https://forums.phpfreaks.com/topic/52387-solved-calling-data-from-2-tables/#findComment-258513 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? Link to comment https://forums.phpfreaks.com/topic/52387-solved-calling-data-from-2-tables/#findComment-258517 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); Link to comment https://forums.phpfreaks.com/topic/52387-solved-calling-data-from-2-tables/#findComment-258529 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? Link to comment https://forums.phpfreaks.com/topic/52387-solved-calling-data-from-2-tables/#findComment-258536 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. Link to comment https://forums.phpfreaks.com/topic/52387-solved-calling-data-from-2-tables/#findComment-258537 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 Link to comment https://forums.phpfreaks.com/topic/52387-solved-calling-data-from-2-tables/#findComment-258539 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. Link to comment https://forums.phpfreaks.com/topic/52387-solved-calling-data-from-2-tables/#findComment-258545 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.