For Programmers: Free Programming Magazines  


Home > Archive > PHP SQL > August 2004 > Assigning values automatically by PHP









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Assigning values automatically by PHP
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


tox_yray

2004-08-18, 3:57 pm

Anybody out there?



----------------------------------------
The post originated from PHP Freaks:
----------------------------------------
http://www.phpfreaks.com
http://www.phpfreaks.com/forums


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com