Web Hosting Talk







View Full Version : mysql question


matt2kjones
11-01-2002, 06:29 PM
ok then i have a question.

i want to put the value 'y' in the variable $end_of_table when my script gets to the last row of data. how could i do this.

how do i know once i have got to the last row of data. because i have a loop, which goes round and round, while the value of $end_of_table == 'n'

now then, i want to change that value to 'y' once i get to the last row, how could i do this?

thanx

jtrovato
11-01-2002, 07:36 PM
Are you using PHP?

can you send the query and the variable name so we can help you better? or maybe I'm a bit comfused, that happens alot... lol

I would know the last record of the query from the mysql_num_rows() function. I would then use an 'i" variable to loop through until the end. at that point I would still have th ID for the record and I would do an update on that record and change the variable "field in the table" to what ever you want it to do.


Does that make sense??

John

ChickenSteak
11-01-2002, 10:37 PM
Jtrovato even better instead of "knowing" what the last row is using that you can do a count of mysql_num_rows then check if the field is n, and if so switch to y with an update query shouldn't be to hard but i'm not in a php mood right now :).

jtrovato
11-02-2002, 12:04 AM
me neither... lol If i had the table in front of me and never which field needed the 'y' at the end i could push it out and display it here. But I don't have any of that info. Matt if you didn't figure it out yet send that info and I'll see what I can do.

John

Lagniappe-labgeek
11-02-2002, 08:30 AM
I assume you're doing something like

$end_of_table = "n";
while ($end_of_table == "n")
{
$row = mysql_fetch_assoc($result));
// do something
}

You could change it to:

$end_of_table = "n";
while ($end_of_table == "n")
{
if ($row = mysql_fetch_assoc($result))
{
// do something
}
else
{
$end_of_table = "y";
}
}


But even better imo would be:

while ($row = mysql_fetch_assoc($result))
{
// whatever you want to do with each record
}