tags:

views:

76

answers:

4

Hello,

I want to loop the update statement, but it only loops once.

Here is the code I am using:

do {
    mysql_select_db($database_ll, $ll);
    $query_query= "update table set ex='$71[1]' where field='val'";
    $query = mysql_query($query_query, $ll) or die(mysql_error());
    $row_domain_all = mysql_fetch_assoc($query);
} while ($row_query = mysql_fetch_assoc($query));

Thanks Jean

A: 

The problem is you reattribute a value to $query within your loop. Try

do {
    mysql_select_db($database_ll, $ll);
    $query_query= "update table set ex='$71[1]' where field='val'";
    $query2 = mysql_query($query_query, $ll) or die(mysql_error());
    $row_domain_all = mysql_fetch_assoc($query2);
} while ($row_query = mysql_fetch_assoc($query));
Kaaviar
plus he is using mysql_fetch_assoc on an UPDATE query, which does not return any rows.
softcr
Actually no, he's only assigning to `$query` once within the loop, that shouldn't pose any problem.
deceze
+5  A: 

Well, the reason it's only looping once would be that UPDATE queries do not return any rows that you could extract with mysql_fetch_assoc. So mysql_fetch_assoc returns false, which renders the expression ($row_query = mysql_fetch_assoc($query)) false, which is why the loop aborts.

Apart from that though, that code is, sorry to say, pretty atrocious. It might help telling us what it is you want to do, there must be a better way.

deceze
A: 

may be it has some problem in your mysql query.

$query_query= "update table set ex='$71[1]' where field='val'";

Your query is wrong.

update query is "update "table name" set ex='$71[1]' where field='val'";

You missed the table name.

or if you are using 'table' as your table name. then change it.

Anup Prakash
A: 

People,

I needed to replace this

$query = mysql_query($query_query, $ll) or die(mysql_error());
$row_domain_all = mysql_fetch_assoc($query);

With

$Result1 = mysql_query($query_query, $ll) or die(mysql_error());
Jean
Sorry, but that makes no sense. If that's the solution you must have omitted half the problem from the question.
deceze