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 array data fetching

$w3 = mysql_query( "SELECT * FROM w3" ) or die("SELECT Error: ".mysql_error());
$worth = mysql_query( "SELECT * FROM worth" ) or die("SELECT Error: ".mysql_error());
// fetching data
while ($get_w3 = mysql_fetch_assoc($w3db) && $get_worth = mysql_fetch_assoc($worth))
{
// Loading Urls for Comparing
echo $w3url=$get_w3['domain']; // cant echo
echo $worthurl=$get_worth['domain']; // ok printed

the code seems to be ok .. but i do not know why it cant print ( echo $w3url=$get_w3['domain']; )

please help
also is there any way to use separate while loops and compare data i use one while loop
for tow data fetches because i have to compare data of both tables

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

This looks like an odd loop. I'd use a UNION for this, seeing as the data from each table is the same type/name.

(SELECT `domain`, 'w3' as source FROM w3)
UNION
(SELECT `domain`, 'worth' as source FROM worth);
ORDER BY `domain`


That'll give you a mix, with duplicates next to each other (below).

diafol
Rhod Gilbert Fan (ardav)
Moderator
7,792 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
 

change this line

$w3 = mysql_query( "SELECT * FROM w3" ) or die("SELECT Error: ".mysql_error());



to

$w3db = mysql_query( "SELECT * FROM w3" ) or die("SELECT Error: ".mysql_error());
vaultdweller123
Posting Pro
554 posts since Sep 2009
Reputation Points: 42
Solved Threads: 75
 

mysql_fetch_assoc($w3db), change $w3db to $w3 or use @ardav method. It is better way.

Zero13
Practically a Master Poster
624 posts since Jan 2009
Reputation Points: 120
Solved Threads: 139
 

This article has been dead for over three months

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