|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
You eat, breathe and sleep innovation. Build your mobile intelligence with BlackBerry® experts this July. Register Today! |
|
#1
|
|||
|
|||
|
Using 2 tables
Hello,
I am trying to use 2 tables from the same database. The tables are named: profiles countries Below is the code and after the ******s is the output. Can someone tell me what I am doing wrong? <?php include('my_dbconn.php'); if (!db_connect()) { echo "<p>Error: Could not connect to database. Please try again later.</p>"; } else { mysql_select_db("ladies"); $query = "select * from profile where ID='1001'"; $result = mysql_query($query); $num_results = mysql_num_rows($result); echo "There is $num_results 1001 record."; $row = mysql_fetch_assoc($result); echo "<p>1001’s name is: "; echo $row["FirstName"]; echo " "; echo $row["LastName"]; echo " "; echo "from"; echo " "; echo $row["CountryCode"]; echo "</p>"; } ?> <?php mysql_select_db("ladies"); $query = "select * from countries where CountryCode='CountryCode'"; $result = mysql_query($query); $num_results = mysql_num_rows($result); echo $row["FirstName"]; echo " "; echo $row["LastName"]; echo " "; echo "is from"; echo " "; echo $row["Country"]; echo " "; echo "</p>"; ?> ******************** There is 1 1001 record. 1001’s name is: Svetlana Korobova from RU Svetlana Korobova is from ***************** They run fine if I use them separately so I know there is not a typo. Thanks, Ed Plummer Saratoga, NY |
|
#2
|
|||
|
|||
|
RE: Using 2 tables
This might work.
select profiles.*, countries.* from profiles, countries where profile.id = '1001' and countries.countrycode = profiles.countrycode That might help. |
|
#3
|
|||
|
|||
|
RE: Using 2 tables
Thaks for the suggestion Evil. I can see the logic in it.
For some reason that made it worse, at least as far as the number of errors goes. Now i get: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource on line 21 There is 1001 record. Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource on line 23 1001’s name is: from ********************** line 21 is: $num_results = mysql_num_rows($result); line 23 is: $row = mysql_fetch_assoc($result); Thanks, Ed |
|
#4
|
|||
|
|||
|
RE: Using 2 tables
Hello EvilivE,
I have spent all afternoon playing with this stupid little mistake of mine. You can call me "dumb and dumber" today. But I am happy it works now. Thank you so much for your knowledge and assistance. The only thing wrong with the code you sent me was an "s" on the end of "profile". I did not catch it for hours. Tells you the more you look at something the better it looks. Thanks again. Your code work fine. Ed Plummer Saratoga Springs, NY |
|
#5
|
|||
|
|||
|
RE: Using 2 tables
Glad to hear it worked!
|
![]() |
| Viewing: Codewalkers Forums > PHP Related > PHP Coding > Using 2 tables |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|
|