Re: Pragmatically changing a "Record Number"

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



tedd wrote:
Hi to the original poster:

Snip -- a lot of discussion

Use the following code at your own peril.

$dbQuery = "ALTER TABLE $dbtable ";
$dbQuery .= "DROP id, ";
$dbQuery .= "ADD id INT UNSIGNED NOT NULL AUTO_INCREMENT,";
$dbQuery .= "AUTO_INCREMENT = 1";
$result = mysql_query($dbQuery) or die("Could not renumber dB $dbQuery" . mysql_error());

The reason for not wanting to care about the auto_increment id is that it is something that the database uses and really should not be changed. If you want to have a sequential record number, then add that field and alter it as you will, but leave the internal workings of database alone.

However, if you wish not to understand how all that works, then use the code above -- it will renumber your auto_increment id leaving no gaps.


At the risk of turning this into a truly marathon thread ...

I don't think altering the id is necessary at all. The solution the OP seems to be looking for is to (as Graham has said) count off the rows as they are being printed using a variable. Using a table for clarity:

<?php
$sql = 'SELECT id, title FROM foo';
$result = mysql_query($sql);
$count = 0;
while (++$count && ($row = $result->fethchRow()))
{
?>
 <tr>
  <td>
    row #<?= $count ?>
  </td>
  <td>
    <a href="foo.php?id=<?= $row['id'] ?>"><?= $row['title'] ?></a>
  </td>
 </tr>
<?php
}

It seems that all this is about is displaying a rowcount. The ids can be anything at all and it'll still look spiffy.

brian

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux