Go Back   CodingForums.com > :: Server side development > MySQL

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-20-2002, 11:19 PM   PM User | #1
reub77
New Coder

 
Join Date: Sep 2002
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
reub77 is an unknown quantity at this point
joining 3 tables

I'm joining 3 tables at the id field in mySQL. I get an error.

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/shabangw/public_html/invoices.php on line 51


This is my query:

$query = "SELECT currprojects.companyName, contracts.dueDate, invoices.amount, currprojects.jobSummary, invoices.invoiceDate, invoices.paid FROM currProjects, contracts, invoices WHERE currprojects.id = contracts.id AND currprojects.id = invoices.id AND invoices.id = contracts.id";

Does anything look wrong? How can I make it work? I've never joined 3 tables. Only 2 and I followed the same logic that I would for 2 but added a little more. Help me if you can.
reub77 is offline   Reply With Quote
Old 09-20-2002, 11:47 PM   PM User | #2
Spookster
Supreme Overlord


 
Spookster's Avatar
 
Join Date: May 2002
Location: Marion, IA USA
Posts: 6,220
Thanks: 4
Thanked 80 Times in 79 Posts
Spookster will become famous soon enough
At first glance I do not see anything wrong with your query. Post the other code where you are trying to get the number of rows returned. That error can occur when the query doesn't return anything but there also might be an error elsewhere so post all pertinent code.
__________________
Spookster
CodingForums Supreme Overlord
All Hail Spookster
Who gave you that Ugging infraction? Yeah that's right it was me!
Spookster is offline   Reply With Quote
Old 09-21-2002, 12:00 AM   PM User | #3
reub77
New Coder

 
Join Date: Sep 2002
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
reub77 is an unknown quantity at this point
ok

I've modified it a little since I posted it, but here it is:

<?PHP
$conn = db_connect();
//declare query
$query = "SELECT currprojects.companyName, contracts.dueDate, invoices.amount, currprojects.jobSummary, invoices.invoiceDate, invoices.invStatus FROM currProjects, contracts, invoices WHERE currprojects.id = contracts.id AND currprojects.id = invoices.id AND invoices.id = contracts.id";
//Execute Query
$result = mysql_query($query);
$x = 0;
while ($x < mysql_num_rows($result)) :
$company = mysql_result($result, $x, 'companyName');
$due = mysql_result($result, $x, 'dueDate');
$Amount = mysql_result($result, $x, 'amount');
$sent = mysql_result($result, $x, 'invoiceDate');
$job_sum = mysql_result($result, $x, 'jobSummary');
$invStat = mysql_result($result, $x, 'invStatus');
print "<tr class='tabletext'>";
print "<td><div align='left'>$company&nbsp;</div></td><td><div align='center'>$due</div></td><td><div align='center'>$Amount</div></td><td><div align='center'>$sent</div></td><td><div align='left'>$job_sum</div></td><td><div align='center'>$paid</div></td><td><div align='center'><img src='images/magnify.jpg' alt='View' width='25' height='19'></div></td><td valign='middle'><div align='center'><img src='images/Gold-Coin.jpg' alt='Paid' width='25' height='25'></div></td></tr><tr><td colspan='8'><div align='center'><img src='images/tableLine.jpg' width='710' height='5'></div></td>";
print "</tr>";
$x++;
endwhile;
print "</table>";
mysql_close();
if(!$result)
return("Query could not be executed"); // if query error
if(mysql_num_rows($result)>0) {
// if the values match values in the database
return("true");
}
?>
reub77 is offline   Reply With Quote
Old 09-21-2002, 12:40 AM   PM User | #4
Spookster
Supreme Overlord


 
Spookster's Avatar
 
Join Date: May 2002
Location: Marion, IA USA
Posts: 6,220
Thanks: 4
Thanked 80 Times in 79 Posts
Spookster will become famous soon enough
The easiest way to debug this would be to verify that your query is valid. If you have phpMyAdmin run your query in there first to ensure it does in fact work and return records.
__________________
Spookster
CodingForums Supreme Overlord
All Hail Spookster
Who gave you that Ugging infraction? Yeah that's right it was me!
Spookster is offline   Reply With Quote
Old 09-21-2002, 12:52 AM   PM User | #5
reub77
New Coder

 
Join Date: Sep 2002
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
reub77 is an unknown quantity at this point
found the problem

It was just that I didn't refer to my table with the right name. I was thinking though that maybe a more effective way to do what I'm doing would be to use the JOIN option. But I don't know how it works so I just stuck with what I knew. How could you use the same code with the JOIN option? And is it considered better?
reub77 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:54 PM.


Advertisement
Log in to turn off these ads.