PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP RelatedPHP Coding

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
You eat, breathe and sleep innovation. Build your mobile intelligence with BlackBerry® experts this July. Register Today!
  #1  
Old June 20th, 2002, 07:41 PM
eplummer eplummer is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Saratoga Springs, NY, US
Posts: 15 eplummer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 46 sec
Reputation Power: 0
Send a message via ICQ to eplummer Send a message via Yahoo to eplummer
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 "&nbsp;";
echo $row["LastName"];
echo "&nbsp;";
echo "from";
echo "&nbsp;";
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 "&nbsp;";
echo $row["LastName"];
echo "&nbsp;";
echo "is from";
echo "&nbsp;";
echo $row["Country"];
echo "&nbsp;";
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

Reply With Quote
  #2  
Old June 20th, 2002, 08:46 PM
EvilivE EvilivE is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Milwaukee, WI USA
Posts: 291 EvilivE User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via Yahoo to EvilivE
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.

Reply With Quote
  #3  
Old June 20th, 2002, 09:19 PM
eplummer eplummer is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Saratoga Springs, NY, US
Posts: 15 eplummer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 46 sec
Reputation Power: 0
Send a message via ICQ to eplummer Send a message via Yahoo to eplummer
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



Reply With Quote
  #4  
Old June 21st, 2002, 01:41 AM
eplummer eplummer is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Saratoga Springs, NY, US
Posts: 15 eplummer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 46 sec
Reputation Power: 0
Send a message via ICQ to eplummer Send a message via Yahoo to eplummer
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

Reply With Quote
  #5  
Old June 21st, 2002, 02:49 AM
EvilivE EvilivE is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Milwaukee, WI USA
Posts: 291 EvilivE User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via Yahoo to EvilivE
RE: Using 2 tables

Glad to hear it worked!

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Coding > Using 2 tables


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway