954,561 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

problem with mysql_fetch_array()

include ("config.php"); 
// select data from database   
$w3db = mysql_query( "SELECT * FROM w3dbx" )     
or die("SELECT Error: ".mysql_error());
$worth = mysql_query( "SELECT * FROM worth" )    
or die("SELECT Error: ".mysql_error());
$w3db_rows = mysql_query($w3db);               
$worth_rows = mysql_query($worth);				
// fetching data 
//while ($get_infox = mysql_fetch_assoc($resultx) && $get_info = mysql_fetch_assoc($result))
while ($get_w3db = mysql_fetch_array($w3db_rows,MYSQL_ASSOC) && $get_worth = mysql_fetch_array($worth_rows,MYSQL_ASSOC))
{


error :: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource ... line #
please check the code i do not know whats wrong with it seems to be perfect to me but getting error do not why ???

darkc99
Newbie Poster
24 posts since Jan 2012
Reputation Points: 10
Solved Threads: 0
 

A few things - firstly you have out your die on the next line, php needs to be on one line, secondly you are running your mysql_query twice and thirdly you are trying to run two queries in your while loop.

This should work (unless there are other problems):

include ("config.php"); 
// select data from database   
$w3db = mysql_query( "SELECT * FROM w3dbx" ) or die("SELECT Error: ".mysql_error());
$worth = mysql_query( "SELECT * FROM worth" ) or die("SELECT Error: ".mysql_error());
			
// fetching data 
//while ($get_infox = mysql_fetch_assoc($resultx) && $get_info = mysql_fetch_assoc($result))
while ($get_w3db = mysql_fetch_array($w3db)) {
// code here
}
while ($get_worth = mysql_fetch_array($worth)) {
// code here
}


If you need to display the two sets of query results together you will either have to change your query to one using joins of run your second query within your first while loop.

simplypixie
Posting Pro in Training
447 posts since Oct 2010
Reputation Points: 116
Solved Threads: 82
 

@simplypixie:

firstly you have out your die on the next line, php needs to be on one line

Just a note: not true. You can use whitespace, including line breaks just fine.thirdly you are trying to run two queries in your while loop.

I really really don't recommend this, but using the two fetches in the while also works... just DO NOT USE IT (can get very messy)...

pritaeas
Posting Expert
Moderator
5,480 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
 

ya i know we can use two fetches in one while loop ... but i do not know whats wrong here... the same technique i use in my other codes and they work fine , but here do not know what wrong

darkc99
Newbie Poster
24 posts since Jan 2012
Reputation Points: 10
Solved Threads: 0
 

pritaes:

Just a note: not true. You can use whitespace, including line breaks just fine.

Actually, yes I don't know why I put that as I have linebreaks in my code all the time.

I have never realised (and there used) multiple fetches in a while loop so my apologies as I didn't think it was acceptable as I have never seen it before.

darkc99:

Have you re-formatted your code to remove the duplicate mysql_query as I said?

simplypixie
Posting Pro in Training
447 posts since Oct 2010
Reputation Points: 116
Solved Threads: 82
 

ya thanks

now its working but have one another problem with xml

$city = $book->Location->CityData->city; // city
$postal_code = $book->Location->CityData->postal_code; // postal code
$time_zone = $book->Location->CityData->time_zone; // time zone
$area_code = $book->Location->CityData->area_code; // area code

Notice: Trying to get property of non-object in line # ..

any other way to assign xml data to php variables so that exported to database

darkc99
Newbie Poster
24 posts since Jan 2012
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: