Jump to content

Help with MySQL Query and error When Joining tables


jbwebdesign

Recommended Posts

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'] . '

';

}

 

//===============================================================================================

Link to comment
Share on other sites

  • 1 month later...

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 :D

Edited by Teddy
Link to comment
Share on other sites

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 :D

Link to comment
Share on other sites

  • 3 weeks later...

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 by bishwadeep
Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...