jbwebdesign Posted June 12, 2009 Report Share Posted June 12, 2009 hello, I am trying to work on a script that will JOIN 2 different tables and I keep getting the following error..... Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource on line 109 can anyone help me out with this? thanks //==========================CONNECT TO DB AND PULL THE SALES FROM EACH USER FROM SEPERATE TABLES===================== $con = mysql_connect('localhost','bcheight_textmon','fadjflka'); $sel = mysql_select_db('bcheight_text'); $sql_query = "SELECT promoters.username, promoter_sales.package_sold ". "FROM promoters, promoter_sales ". "WHERE promoters.username = promoter_sales.username"; $my_q = mysql_query($sql_query); $my_sales; while($row = mysql_fetch_array($sql_query,MYSQL_ASSOC)){ $my_sales = $my_sales . 'Date Sold: ' . $row['date_sold']. " Package Sold: ". $row['package_sold'] . ' '; } //=============================================================================================== Quote Link to comment Share on other sites More sharing options...
Teddy Posted July 28, 2009 Report Share Posted July 28, 2009 (edited) Hi, Usually when u get this Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource........ it means ur information is wrong (table, db, etc.,) or the result is empty (there is no data in the table) so check that first.... Hope this helps Edited July 28, 2009 by Teddy Quote Link to comment Share on other sites More sharing options...
Teddy Posted July 28, 2009 Report Share Posted July 28, 2009 Database Connection should be....... $con = mysql_connect("localhost","root",""); or $con = mysql_connect('localhost','bcheight_textmon','fadjflka'); if(!$con) { die('Could not connect: '.mysql_error()); } mysql_select_db("bcheight_text",$con); --> plz look at this line u didn't connect to the DB... and u can follow this one...... $sql_query = mysql_query("SELECT promoters.username, promoter_sales.package_sold FROM promoters, promoter_sales WHERE promoters.username = promoter_sales.username"); while($row = mysql_fetch_array($sql_query)) { $sold_date = $row['date_sold']; $sold_package = $row['package_sold']; echo "Sold Date: " . $sold_date . "Package Sold: " . $sold_package . " "; } Have a nice day Quote Link to comment Share on other sites More sharing options...
bishwadeep Posted August 18, 2009 Report Share Posted August 18, 2009 (edited) You have created the mysql query object in the variable($my_q = mysql_query($sql_query) but you are still using $sql_query $sql_query = "SELECT promoters.username, promoter_sales.package_sold ". "FROM promoters, promoter_sales ". "WHERE promoters.username = promoter_sales.username"; $my_q = mysql_query($sql_query); $my_sales; Wrong: while($row = mysql_fetch_array($sql_query,MYSQL_ASSOC)){ $my_sales = $my_sales . 'Date Sold: ' . $row['date_sold']. " Package Sold: ". $row['package_sold'] . ' '; } Right: while($row = mysql_fetch_array($my_q, MYSQL_ASSOC)){ $my_sales = $my_sales . 'Date Sold: ' . $row['date_sold']. " Package Sold: ". $row['package_sold'] . ' '; } Edited August 18, 2009 by bishwadeep Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.