Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 02-26-2003, 08:09 PM   #1 (permalink)
trevor
Code Monkey
 
Join Date: Jan 2003
Location: Canada
Posts: 91
trevor is on a distinguished road
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
trevor is offline   Reply With Quote
Old 02-26-2003, 08:29 PM   #2 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,446
sde is on a distinguished road
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.
sde is offline   Reply With Quote
Old 02-26-2003, 08:38 PM   #3 (permalink)
trevor
Code Monkey
 
Join Date: Jan 2003
Location: Canada
Posts: 91
trevor is on a distinguished road
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.
trevor is offline   Reply With Quote
Old 02-26-2003, 09:27 PM   #4 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,446
sde is on a distinguished road
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.
sde is offline   Reply With Quote
Old 02-26-2003, 09:51 PM   #5 (permalink)
trevor
Code Monkey
 
Join Date: Jan 2003
Location: Canada
Posts: 91
trevor is on a distinguished road
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?
trevor is offline   Reply With Quote
Old 02-26-2003, 09:54 PM   #6 (permalink)
trevor
Code Monkey
 
Join Date: Jan 2003
Location: Canada
Posts: 91
trevor is on a distinguished road
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;
                }
?>
trevor is offline   Reply With Quote
Old 02-26-2003, 10:02 PM   #7 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,446
sde is on a distinguished road
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
sde is offline   Reply With Quote
Old 02-26-2003, 10:06 PM   #8 (permalink)
trevor
Code Monkey
 
Join Date: Jan 2003
Location: Canada
Posts: 91
trevor is on a distinguished road
but its backwards, it only shows the first 5 posts, nothing after that.
trevor is offline   Reply With Quote
Old 02-26-2003, 10:12 PM   #9 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,446
sde is on a distinguished road
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%'>"
);
}
?>
sde is offline   Reply With Quote
Old 03-14-2003, 12:32 PM   #10 (permalink)
trevor
Code Monkey
 
Join Date: Jan 2003
Location: Canada
Posts: 91
trevor is on a distinguished road
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
trevor is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

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 On
Pingbacks are On
Refbacks are On



All times are GMT -8. The time now is 11:46 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting