mysql_fetch_array()

trying to join 2 tables in 2 different DBs together

Page 1 of 1

2 Replies - 750 Views - Last Post: 21 July 2008 - 02:24 AM Rate Topic: -----

#1 Ladydice  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 25-June 08

mysql_fetch_array()

Posted 09 July 2008 - 12:07 AM

i've been having a hard time trying to join 2 tables in 2 different DBs together. This is the first time i'm doing this so please tell me if there's something wrng.

$result2=mysql_query("SELECT * FROM Cash.Payment 
JOIN Contest.Details
ON Cash.Payment.INVOICE = Contest.Details.INVOICE  
WHERE Cash.Payment.USER_NAME = '$_COOKIE[ID_my_site]'
LIMIT $offset, $rowsPerPage");

while($row= mysql_fetch_array($result2)) {

echo "<td>" . $row['INVOICE']. "</td>";
echo "<td>" . $row['PAYMENT_STATUS']. "</td>";
echo "<td>" . $row['PAYMENT_DATE']. "</td>";
echo "<td>" . $row['AMOUNT']. "</td>";
echo "<td>" . $row['TRANS_ID']. "</td>";
echo "<td>" . $row['PAYER_STATUS']. "</td>";
echo "<td>" . $row['PAYER_STATUS']. "</td>";



i keep getting an error on my while statement.
error: mysql_fetch_array(): supplied argument is not a valid MySQL result resource

help would be much appreciated :)

Is This A Good Question/Topic? 0
  • +

Replies To: mysql_fetch_array()

#2 EvinOwen  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 8
  • Joined: 01-July 08

Re: mysql_fetch_array()

Posted 11 July 2008 - 01:40 PM

the error you are getting is because there is a problem with your query. it means that you are passing a value to your mysql_fetch_array() function that is not the result of a mysql_query(), meaning that the query failed and has returned null. i would suggest checking to see if your result is null before attempting to access it, though its not necessary.

add 'or die(mysql_error())' after your mysql_query() function, and you can get the error from your query...

like this:

$result2 = mysql_query("SELECT * FROM Cash.Payment JOIN Contest.Details ON Cash.Payment.INVOICE = Contest.Details.INVOICE WHERE Cash.Payment.USER_NAME = '$_COOKIE[ID_my_site]' LIMIT $offset, $rowsPerPage") or die(mysql_error());


Was This Post Helpful? 0
  • +
  • -

#3 Ladydice  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 25-June 08

Re: mysql_fetch_array()

Posted 21 July 2008 - 02:24 AM

View PostEvinOwen, on 11 Jul, 2008 - 01:40 PM, said:

the error you are getting is because there is a problem with your query. it means that you are passing a value to your mysql_fetch_array() function that is not the result of a mysql_query(), meaning that the query failed and has returned null. i would suggest checking to see if your result is null before attempting to access it, though its not necessary.

add 'or die(mysql_error())' after your mysql_query() function, and you can get the error from your query...

like this:

$result2 = mysql_query("SELECT * FROM Cash.Payment JOIN Contest.Details ON Cash.Payment.INVOICE = Contest.Details.INVOICE WHERE Cash.Payment.USER_NAME = '$_COOKIE[ID_my_site]' LIMIT $offset, $rowsPerPage") or die(mysql_error());



thanks alot for the tip.... :D :^:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1