| | |
Update the auto increment value
Please support our MySQL advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
Is it possible to update the AUTO_INCREMENT value who's attributes are primary key, not null, auto increment and also an INT type
The thing is I need to synchronize the 'image_id' to access images sequentially
and if one row is deleted the sequence is destroyed Help me!
The thing is I need to synchronize the 'image_id' to access images sequentially
and if one row is deleted the sequence is destroyed Help me!
MySQL Syntax (Toggle Plain Text)
<?php include('db_conexn.php'); $data = mysql_query("SELECT image_id FROM imagetable") OR die(mysql_error()); while($info = mysql_fetch_array( $data )) { echo $id += 1; echo " - ".$info['image_id']; $sync=mysql_query("UPDATE imagetable SET image_id = $id"); echo "<BR>"; } echo " - <BR> " . $id +=1; $autoinc = mysql_query("ALTER TABLE imagetable AUTO_INCREMENT = $id"); ?>
if a row is deleted the sequence will be destroyed can you suggest me any way to update the id.
i've done using following code
this is not working ie all ids have same number
it all contains the last value if $id
help me
i've done using following code
MySQL Syntax (Toggle Plain Text)
$id=1; $count = mysql_num_rows( mysql_query("SELECT image_id FROM imagetable") ) $data = mysql_query("SELECT * FROM imagetable ORDER BY image_path ASC") OR die(mysql_error()); while($info = mysql_fetch_array($data)) { $sync = mysql_query("UPDATE imagetable SET image_id = $id "); }
this is not working ie all ids have same number
it all contains the last value if $id
help me
•
•
Join Date: Jul 2008
Posts: 14
Reputation:
Solved Threads: 3
It seems that you are not increment the id maybe add an increment to your loop? IE:
$id=1;
$count = mysql_num_rows( mysql_query("SELECT image_id FROM imagetable") )
$data = mysql_query("SELECT * FROM imagetable ORDER BY image_path ASC")
or die(mysql_error());
while($info = mysql_fetch_array($data))
{
$sync = mysql_query("UPDATE imagetable SET image_id = $id ");
$id++;
} Last edited by mike_g; Aug 22nd, 2008 at 5:59 pm.
i have updated $id but still the problem persists
the loop is execute completely on a row and only after that it goes to the next row
this is why every row has same number
help me solve this
the loop is execute completely on a row and only after that it goes to the next row
this is why every row has same number
help me solve this
Last edited by danishbacker; Aug 23rd, 2008 at 4:59 am.
php Syntax (Toggle Plain Text)
$data = mysql_query("SELECT id ,name FROM imagetable") or die(mysql_error()); $id=0; while($info = mysql_fetch_array( $data )) { $id=$id+1; mysql_query("UPDATE imagetable SET id =$id where name='$info[1]'"); }
instead of using auto increment i incremented the value manually and
updated each fields.
Last edited by danishbacker; Dec 15th, 2008 at 5:01 am.
![]() |
Similar Threads
- MYSQL: update all fields in a table (increase value by one) (PHP)
- display image from databse (MySQL)
- Please check my code below (Java)
- Not getting information from the database (PHP)
- Fatal error: require once (PHP)
- vb express database autonumber problem. (VB.NET)
- Hello all... Need help updating mysql with php (PHP)
- Help With Messages in Mysql Stop Overwriting (MySQL)
- How to auto increment? (ASP.NET)
- auto incrememnt mysql (PHP)
Other Threads in the MySQL Forum
- Previous Thread: qick question
- Next Thread: How select Documents which contain more than n tag-specified words
| Thread Tools | Search this Thread |
agplv3 alfresco amazon api artisticlicense aws bizspark breathalyzer camparingtocolumns changingprices cmg communityjournalism contentmanagement contractors copyright count court crm database developer distinct drupal dui ec2 email enter enterprise eudora facebook form foss gartner gnu government gpl greenit groklaw groupware hiring hyperic images innerjoins insert ip joebrockmeier join journalism keyword keywords kickfire laptop law legal license licensing linux maintenance managing mariadb matchingcolumns micromanage microsoft microsoftexchange mindtouch montywidenius mozilla multiple music mysql mysqlcolumnupdating mysqldatetimeordermax() mysqlindex mysqlquery mysqlsearch news open-xchange opendatabasealliance opengovernment opensource oracle penelope php priceupdating query referencedesign reorderingcolumns resultset saas select sharepoint simpledb sourcecode spotify sql sugarcrm syntax techsupport thunderbird transparency virtualization






