| tox_yray 2004-08-18, 3:57 pm |
| Hello, I have been modifying a MySQL db, and I was trying to reorder
stuff. I ended up adding a "ordre" column to my tables that
I will increment by 5.
Now, I got a huge problem: one of the tables contains more than 200
records! I can't change this by hand, it's gonna be
awfully too long. I had the idea to create a PHP script to to this
for me, type of record by type of record.
Here is te code I came up with:
--------
<?php
include ("include/dbconnect.php");
select = "SELECT * FROM "
.langue. "publilol WHERE type=" . type;
result =
mysql_query(select,db);
total =
mysql_num_rows(result);
if(total)
{
max = (total*5)+10;
i = 1;
while(publication =
mysql_fetch_array(result))
{
query1 = "UPDATE
".langue."publilol SET ordre = ".max."
WHERE identification =
".publication['identification']." AND
url=".publication['url']." AND
type=".publication['type'];
query2 =
mysql_query(query1,db);
max = (max-5);
echo "Done for ".i."
enregistrements";
++i;
}
}
include ("include/dbclose.php");
?>
--------
It does not work... The loop to make the # of records show up works,
but nothing updates.
Thanks for your help,
Bruno M-A, Summer intern at LARIM, Polytechnique, Montreal.
----------------------------------------
The post originated from PHP Freaks:
----------------------------------------
http://www.phpfreaks.com
http://www.phpfreaks.com/forums
|