Forum Moderators: coopster

Message Too Old, No Replies

having a table join problem

php/mysql/ and a left join

         

Trisha

12:47 am on Feb 23, 2005 (gmt 0)

10+ Year Member



This is my first time to try to join tables, and I swear I'm following exactly what is in the php book I have, but I keep getting a "mysql_fetch_array(): supplied argument is not a valid MySQL result resource in....." error.

This is what I have - does anyone see anything obviously wrong?

"select m_widget2.Description, m_widget.ThumbNailImage, m_widget.SKU, m_widget.Price
from m_widget left join m_widget2
on m_widget.SKU = m_widget2.SKU"

Thanks

coopster

11:25 am on Feb 23, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Syntax looks fine to me. I usually throw parentheses around the ON clause, but that's more for readability than anything else. Your statement should work fine as laid out. Double check your table and column names and make sure there is data to retrieve. Also, you may want to make sure you are actually connecting to your database first.

horaghn

7:53 pm on Feb 23, 2005 (gmt 0)

10+ Year Member



$aQuery = mysql_query("SELECT b.Description, a.ThumbNailImage, a.SKU, a.Price FROM m_widget a LEFT JOIN m_widget2 b
ON a.SKU=b.SKU");

$aWidget = mysql_fetch_assoc( $aQuery );

1.) I like to create and use aliases on the tables, and put the reserved words in CAPITALS to make it easier to look and ts the query.

2.) Did you query first?

3.) mysql_fetch_assoc is more effective of a call - less data transmitted.

Trisha

8:11 pm on Feb 23, 2005 (gmt 0)

10+ Year Member



If I try to pull out the data using either of the two tables by themselves, it works fine, I just have a problem when trying to join them. So I don't think it is a problem with either the database or the field names. It could be something that got mixed up in the process of widgetizing the code though, I'll check that more closely.

Trisha

8:14 pm on Feb 23, 2005 (gmt 0)

10+ Year Member



Just saw your response horaghn.

not sure what you mean by "2.) Did you query first?"

never heard of mysql_fetch_assoc, I'll try that though.

RyanM

10:06 pm on Feb 24, 2005 (gmt 0)

10+ Year Member



Are the two collumns that are joined using the on statement the same data type?

horaghn

10:30 pm on Feb 24, 2005 (gmt 0)

10+ Year Member



You have to use -

$mQueryVariable = mysql_query("SQL STATEMENT");

before you can use

mysql_fetch_assoc()

or

mysql_fetch_array();

My preceeding code should work if cut and pasted with your example. If the two columns are able to be compared.

Trisha

10:56 pm on Feb 24, 2005 (gmt 0)

10+ Year Member



RyanM - they are the same types.

horaghn - thanks, I'll try that.