Please help me find errors in this code, because it is not displaying what i requested. PLease answer A.S.A.P

$query = mysql_query("SELECT * FROM member");
							 $result = mysql_query($query);
							 
							 while ($row = mysql_fetch_array($result))
							 {
							 			  if(mysql_num_rows($result) == 0)
											$result = mysql_query("UPDATE member SET flgCurrent = 'false' WHERE idMember =" .$row[0]);
											echo $row;
										 	echo "<br />";
										 
										
										 
		     						
		 		 						
							 }

Recommended Answers

All 6 Replies

PLease answer A.S.A.P

You need curly braces { } surrounding the If statement.

Also I'm not sure what $row would display as you haven't specified a field.

e.g echo $row[0];

Try this as your code:

$result = mysql_query("SELECT * FROM `member`");
while ($row = mysql_fetch_array($result))
    {
    if(mysql_num_rows($result) == 0)
        {
        $result = mysql_query("UPDATE `member` SET `flgCurrent` = 'false' WHERE `idMember` ='" .$row[0]."'");
        }
    echo $row."<br />";
}

Also the logic in the if function just won't work. You have said the following in the script:

  • assign the mysql query
  • use the query the fetch the first row
  • after the first & second & third & fourth etc rows are fetch, check if zero rows are fetched from the original mysql query
  • If zero rows are fetched from the original mysql query then update a mysql table.

Does that seem logical to you because you are telling the script to ask itself if zero rows are fetched when it knows for sure that at least one row is fetched. So most of the code I gave above is fine but the following piece of that code will need a rethink design wise:

if(mysql_num_rows($result) == 0)
        {
        $result = mysql_query("UPDATE `member` SET `flgCurrent` = 'false' WHERE `idMember` ='" .$row[0]."'");
        }

Thats all the bugs I can think of. Hope I explained that clearly and didn't confuse you.

Please help me find errors in this code, because it is not displaying what i requested. PLease answer A.S.A.P

$query = mysql_query("SELECT * FROM member");
							 $result = mysql_query($query);
							 
							 while ($row = mysql_fetch_array($result))
							 {
							 			  if(mysql_num_rows($result) == 0)
											$result = mysql_query("UPDATE member SET flgCurrent = 'false' WHERE idMember =" .$row[0]);
											echo $row;
										 	echo "<br />";
										 
										
										 
		     						
		 		 						
							 }

what do you want to be displayed?

The line
echo $row;
will not display any useful info because $row is an array, it will just output something like Array

You should at least specify an array key like $row[0]

That will not result to none... You haven't accessed really the value of the $row[0] in the database and you did not declare an array on the first place.

while ($row = mysql_fetch_array($result))
{
$id=$row['[I]fieldname[/I]']
if(mysql_num_rows($result) == 0){

$result = mysql_query("UPDATE member SET flgCurrent = 'false' WHERE idMember =" .$id);

echo $row;

}

Thank You!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.