Closed Thread Icon

Topic awaiting preservation: Silly mysql question (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=28455" title="Pages that link to Topic awaiting preservation: Silly mysql question (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: Silly mysql question <span class="small">(Page 1 of 1)</span>\

 
redroy
Paranoid (IV) Inmate

From: 1393
Insane since: Dec 2003

posted posted 09-20-2006 19:27

When I have

code:
mysql_query("UPDATE " . TABLE_USERS . " SET user = ''");

It seems to update all rows under "user"... which is what I want; my question, is that the proper way to update all rows within the table? I'm testing with a very small number of rows but eventually it will be huge and I don't want problems in the futre. Thanks.

edit: That's comes after

code:
mysql_query("SELECT * FROM " . TABLE_USERS);

... naturaly.



(Edited by redroy on 09-20-2006 19:30)

_Mauro
Maniac (V) Inmate

From:
Insane since: Jul 2005

posted posted 09-20-2006 20:03

Yes.
It's correct.

If it was to be a protected field, it should have some attributes (auto-increment, primary or foreign key) to do so, I mean it should have been considered for the db design.
Now ask yourself, "is there a task I will have to perform which will require complex queries if this field is empty". If the answer is no.

You're fine.

Tyberius Prime
Maniac (V) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 09-20-2006 20:10

Now... why would you ever update *all* the rows?

redroy
Paranoid (IV) Inmate

From: 1393
Insane since: Dec 2003

posted posted 09-20-2006 21:11

Cool thanks!

TP, It's not updating all the rows; just most of it. The user ID will remain etc. The data is being tracked on a monthly basis... at the end of the month it dumps totals into another table and sets back to default.

redroy
Paranoid (IV) Inmate

From: 1393
Insane since: Dec 2003

posted posted 09-23-2006 04:53

Ok, now I'm having trouble on the other side... sort of...

So I have

code:
for ($i = 0; $i < $num_rows; $i++)
	{
		$hits = mysql_result($result, $i, "total_hits");
		mysql_query("UPDATE " . TABLE_USERS . " SET temp_hits = " . $hits);
	}

I'm grabbing "total_hits" from row $i out of the database, how do I update "temp_hits" w/ only the total hits from row $i... the above example will populate all "temp_hits" to the number in the last row. If that makes any sense...

redroy
Paranoid (IV) Inmate

From: 1393
Insane since: Dec 2003

posted posted 09-23-2006 16:30

duh

code:
for ($i = 0; $i < $num_rows; $i++)
	{
		$hits = mysql_result($result, $i, "total_hits");
		$id = mysql_result($result, $i, "id");
		mysql_query("UPDATE " . TABLE_USER_HITS . " SET temp_hits = " . $hits . " WHERE id = " . $id);
	}

I guess I just needed some sleep... I'll try not to ask questions late at night anymore



(Edited by redroy on 09-23-2006 16:31)

« BackwardsOnwards »

Show Forum Drop Down Menu