Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Reset Auto Increament Number
Old 01-21-2007, 12:23 PM Reset Auto Increament Number
Daman's Avatar
Extreme Talker

Posts: 157
Location: Toronto, CANADA
Trades: 0
My problem:
If I have entered 10 records, and deleted 9th, 10th records. The next auto increment value will be 11, not 9. I need the auto increment value of next inserted record to start from 9.

I beleive the code option I need to use is:

PHP Code:
ALTER TABLE theTableInQuestion AUTO_INCREMENT=
Where do i place this exactly?

Here is my code:

PHP Code:
<?
include("config.php");
$connection=mysql_connect($hostname,$user,$pass)or die ("Failed to connect.");
mysql_select_db($dbname,$connection) or die ("Cannot connect to DB");

$sql "ALTER TABLE tablename AUTO_INCREMENT = 1";

$sql="
select 
REG_ID, TITLE, FIRST_NM, LAST_NM, SCHOOL, EMAIL, YEAR, PHONE, SESSION
from int_prep2006
order by
REG_ID
"
;

$result=mysql_query($sql$connection) or die ("Could not execute query.");

while (
$signed=mysql_fetch_array($result))
{
$reg_id=$signed['REG_ID'];
$title=$signed['TITLE'];
$first_nm=$signed['FIRST_NM'];
$last_nm=$signed['LAST_NM'];
$school=$signed['SCHOOL'];
$email=$signed['EMAIL'];
$year=$signed['YEAR'];
$phone=$signed['PHONE'];
$session=$signed['SESSION'];
echo 
"<table>";
$students_list .="
<tr><td>
$reg_id</td><td>$title $first_nm $last_nm</td><td>$school</td><td>$email</td><td>$year</td><td>$phone</td><td>$session</td></tr>
"
;
}
//echo $students_list;
?>
Daman is offline
Reply With Quote
View Public Profile Visit Daman's homepage!
 
 
Register now for full access!
Old 01-22-2007, 06:10 AM Re: Reset Auto Increament Number
ibbo's Avatar
Super Spam Talker

Posts: 880
Location: Leeds UK
Trades: 0
The alter statement is correct and you must issue the alter before you insert the next record or immediately after deleteing the last one.

Ibbo
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Linux user #349545 :
(GNU/Linux)iD8DBQBAzWjX+MZAIjBWXGURAmflAKCntuBbuKCWenpm XoA7LNydllVQOwCf
ibbo is offline
Reply With Quote
View Public Profile Visit ibbo's homepage!
 
Old 01-22-2007, 07:23 AM Re: Reset Auto Increament Number
Experienced Talker

Posts: 46
Name: John Henson
Trades: 0
I know little about the syntax of SQL so can't comment on that but I can say that doing this...

PHP Code:
$sql "ALTER TABLE tablename AUTO_INCREMENT = 1"
 
$sql=
select 
REG_ID, TITLE, FIRST_NM, LAST_NM, SCHOOL, EMAIL, YEAR, PHONE, SESSION 
from int_prep2006 
order by 
REG_ID 
"

is not going to alter the auto-increment since you're setting the value of $sql and then changing it on the next line before you've executed the first SQL statement.

Hope that helps.

Last edited by Invictus; 01-22-2007 at 07:26 AM..
Invictus is offline
Reply With Quote
View Public Profile
 
Old 01-22-2007, 09:04 AM Re: Reset Auto Increament Number
Daman's Avatar
Extreme Talker

Posts: 157
Location: Toronto, CANADA
Trades: 0
Could you please explain to me where and how I would use this in my form code below?

PHP Code:
include("config.php");
$connection=mysql_connect($hostname,$user,$pass)or die ("Failed to connect.");
mysql_select_db($dbname,$connection) or die ("Cannot connect to DB");

$count="
select count(REG_ID) as COUNT
from int_prep2006
"
;

$result=@mysql_query($count$connection) or die ("Could not execute query.");
while (
$row=mysql_fetch_array($result))
{
$total_reg=$row['COUNT'];
}

if (
$total_reg >= 45)
{
header "Location:http://students.fasken.com/ipw2007/sessionfull.html");
exit;
}

$sql="
insert into int_prep2006
(REG_ID, TITLE, FIRST_NM, LAST_NM, EMAIL, SCHOOL, YEAR, PHONE, SESSION)
values
 ('', '
$title', '$first_nm', '$last_nm', '$email', '$school', '$year', '$phone', '$session')
"
;

$result=mysql_query($sql$connection) or die ("Could not insert data into the DB.");

if (
$result)
{
header "Location:http://students.fasken.com/ipw2007/thanks1.html");

Thanks!
Daman is offline
Reply With Quote
View Public Profile Visit Daman's homepage!
 
Old 01-22-2007, 03:48 PM Re: Reset Auto Increament Number
Daman's Avatar
Extreme Talker

Posts: 157
Location: Toronto, CANADA
Trades: 0
Here is my attempt. I used $reset in the $result query.
This newbie still hasnt got it. Please help. Thanks

PHP Code:
<?
if ((!$title)||(!$first_nm)||(!$last_nm)||(!$email)||(!$phone)||(!$school)||(!$year)||(!$session))
{
echo 
"<html><head><title>Error!</title></head><body bgcolor=\"#ffffff\"><p>&nbsp;</p><p><center><font color=\"#3D007e\" size=4>You have not filled some of the required fields.<br>Click on the \"Back\" button on your browser and fill in the form<b> completely</b>.";
header "Location:http://students.fasken.com/ipw2007/index.php");
exit;
}

include(
"config.php");
$connection=mysql_connect($hostname,$user,$pass)or die ("Failed to connect.");
mysql_select_db($dbname,$connection) or die ("Cannot connect to DB");

$count="
select count(REG_ID) as COUNT
from int_prep2006
"
;

$result=@mysql_query($count$connection) or die ("Could not execute query.");
while (
$row=mysql_fetch_array($result))
{
$total_reg=$row['COUNT'];
}

if (
$total_reg >= 45)
{
header "Location:http://students.fasken.com/ipw2007/sessionfull.html");
exit;
}

$reset "ALTER TABLE tablename AUTO_INCREMENT = 1";

$sql="
insert into int_prep2006
(REG_ID, TITLE, FIRST_NM, LAST_NM, EMAIL, SCHOOL, YEAR, PHONE, SESSION)
values
 ('', '
$title', '$first_nm', '$last_nm', '$email', '$school', '$year', '$phone', '$session')
"
;

$result=mysql_query($reset$sql$connection) or die ("Could not insert data into the DB.");

if (
$result)
{
header "Location:http://students.fasken.com/ipw2007/thanks1.html");
}
?>
Daman is offline
Reply With Quote
View Public Profile Visit Daman's homepage!
 
Old 01-23-2007, 09:49 AM Re: Reset Auto Increament Number
Daman's Avatar
Extreme Talker

Posts: 157
Location: Toronto, CANADA
Trades: 0
Can anyone assist me with this? I'm some what of a newbie and I just don't know how to place this in my already existing code above. My attempts have not been successful.

Thanks
Daman is offline
Reply With Quote
View Public Profile Visit Daman's homepage!
 
Old 01-29-2007, 01:08 PM Re: Reset Auto Increament Number
Daman's Avatar
Extreme Talker

Posts: 157
Location: Toronto, CANADA
Trades: 0
Thanks Invictus, your advise helped.

Cheers!
Daman is offline
Reply With Quote
View Public Profile Visit Daman's homepage!
 
Reply     « Reply to Reset Auto Increament Number
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.19340 seconds with 12 queries