|
 |
|
 |
02-26-2003, 09:09 PM
|
#1 (permalink)
|
|
Code Monkey
Join Date: Jan 2003
Location: Canada
Posts: 91
|
auto_increment
anyone know how to change what auto_increment is set to?
I deleted a couple of posts on my news section of my site, and now whenever I post something, the ID is off by 2. So i have to change the ID -2 for the post to show up. (probably make more sense if you saw my code).
But anyways, if my news id's go up to 14, and I post something, the id for that thing is 17, so id have to change it to 15 for it to show.
hope that makes sense (its really late)
thanks,
Trevor
|
|
|
02-26-2003, 09:29 PM
|
#2 (permalink)
|
|
Moderator
Join Date: May 2002
Location: us.ca
Posts: 4,529
|
it shouldnt' matter that the id's are not sequencial.
for example .. no matter how you ordered your news .. this would pull up the last 5 articles:
PHP Code:
<?
$result=mysql_query("select * from news order by news_id desc limit 5");
?>
but then again, your right, .. i don't see your code.
|
|
|
02-26-2003, 09:38 PM
|
#3 (permalink)
|
|
Code Monkey
Join Date: Jan 2003
Location: Canada
Posts: 91
|
the way my code works is it shows all the news (yeah i gotta fix that soon). But it counts the lines, and the line numbers should be equal to the highest ID#, the newest post. Then it just counts down till it runs out. The problem is that if it puts my post to ID=17 and there is only 15 lines, it wont show up until i add 2 more posts, or subtract 2 from the ID.
|
|
|
02-26-2003, 10:27 PM
|
#4 (permalink)
|
|
Moderator
Join Date: May 2002
Location: us.ca
Posts: 4,529
|
yeah, i would definately re-program the page that shows the news .. it can still show all the news, .. just make it order the results by news_id in descending order. the query would look like the one above except it would not have the 'limit 5' stipulation.
|
|
|
02-26-2003, 10:51 PM
|
#5 (permalink)
|
|
Code Monkey
Join Date: Jan 2003
Location: Canada
Posts: 91
|
ok,
I tried the:
$result=mysql_query("select * from news order by id desc limit 5");
but it only shows my FIRST 5 posts, so the most recent posts after the first 5 dont show?
|
|
|
02-26-2003, 10:54 PM
|
#6 (permalink)
|
|
Code Monkey
Join Date: Jan 2003
Location: Canada
Posts: 91
|
here is my accual code:
PHP Code:
<?
$result=mysql_query("select * from news order by id desc limit 5");
$num_rows = mysql_num_rows($result);
while ($num_rows >= 0) {
$query = "Select * from news where(id = $num_rows)";
$result = mysql_query ($query, $db)
or die("error");
while ($row = mysql_fetch_array ($result)) {
print("<br><br><p><b><i>posted by</i> -=[$row[author]]=- <u>$row[header]</u> </b><font size='2'><i> $row[date] @ $row[time] </i></font><br> $row[content] </p><br><hr width='85%'");
}
$num_rows = $num_rows - 1;
}
?>
|
|
|
02-26-2003, 11:02 PM
|
#7 (permalink)
|
|
Moderator
Join Date: May 2002
Location: us.ca
Posts: 4,529
|
you can change the 'limit 5' to 'limit 10' or however many news posts you want to limit it too .. if you want to completely eliminate the limit, i just take it off
PHP Code:
$result=mysql_query("select * from news order by id desc");
i would suggest putting some limit on it though
|
|
|
02-26-2003, 11:06 PM
|
#8 (permalink)
|
|
Code Monkey
Join Date: Jan 2003
Location: Canada
Posts: 91
|
but its backwards, it only shows the first 5 posts, nothing after that.
|
|
|
02-26-2003, 11:12 PM
|
#9 (permalink)
|
|
Moderator
Join Date: May 2002
Location: us.ca
Posts: 4,529
|
sorry... i am not paying attention.. it's late here to. looks like you have an extra query .. try this:
PHP Code:
<?
$query = "Select * from news order by id desc limit 20";
$result = mysql_query ($query, $db)
or die("error");
while ($row = mysql_fetch_array ($result)) {
print("<br><br><p>
<b><i>posted by</i> -=[$row[author]]=- <u>$row[header]</u></b>
<font size='2'><i> $row[date] @ $row[time] </i></font>
<br>
$row[content] </p>
<br>
<hr width='85%'>");
}
?>
|
|
|
03-14-2003, 01:32 PM
|
#10 (permalink)
|
|
Code Monkey
Join Date: Jan 2003
Location: Canada
Posts: 91
|
woah sorry man, i've been gone for a coulpe weeks due to a family emergency and completely forgot about this problem.
but yeah, the code doesnt want to work. i get an "unexpected T_STRING" on the "or die("error");" line.
thanks
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -8. The time now is 01:16 PM.
|
Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting
|
 |
|