4WebHelp
 FAQ  •  Search  •  User Groups  •  Forum Admins  •  Smilies List  •  Statistics  •  Rules   •  Login   •  Register
Toggle Navigation Menu

 PHP Help Needed
Post New TopicReply to Topic
View Previous Topic Print this topic View Next Topic
Author Message
Justin
4WebHelp Addict
4WebHelp Addict


Joined: 07 Jan 2002
Posts: 1060

PostPosted: Wed Jun 22, 2005 8:45 pm (18 years, 10 months ago) Reply with QuoteBack to Top

I have the following PHP/SQL in a CMS Script

@$outcome=mysql_query("SELECT * FROM articles ORDER BY adate ASC,atime ASC LIMIT $id");
if ($sectionID) @$outcome=mysql_query("SELECT * FROM articles WHERE sectionID='$sectionID' AND adate<='$date' ORDER BY adate ASC, atime ASC LIMIT $id");

I want the ASC Limit to be the value of $id -1, how would I do this in PHP, it seems ery simple, but have never had to do something like this before, hence why I'm asking.
OfflineView User's ProfileFind all posts by JustinSend Personal MessageSend email
Daniel
Team Member



Joined: 06 Jan 2002
Posts: 2564

PostPosted: Sat Jun 25, 2005 2:15 pm (18 years, 9 months ago) Reply with QuoteBack to Top

Is this what you mean?

Code:
@$outcome=mysql_query("SELECT * FROM articles ORDER BY adate ASC,atime ASC LIMIT $id");
if ($sectionID) @$outcome=mysql_query("SELECT * FROM articles WHERE sectionID='$sectionID' AND adate<='$date' ORDER BY adate ASC, atime ASC LIMIT " . ($id-1));


I think that should do it if that's what you were after.

________________________________
Image
OfflineView User's ProfileFind all posts by DanielSend Personal Message
Justin
4WebHelp Addict
4WebHelp Addict


Joined: 07 Jan 2002
Posts: 1060

PostPosted: Sat Jun 25, 2005 4:28 pm (18 years, 9 months ago) Reply with QuoteBack to Top

Thanks

What I want to do now, is for it to take into account the ID of the article, which is specified in a URL string such as: www.domain.com/news/viewarticle.php?id=1

Take the value of id= and then look in the article database and retrieve the five previous article ID's prior to that. EG if the URL specifies id=9,I want it to display articles 8,7.6,5,4 if you see what I mean.

The id value matches the value of the id column in the database, so it shouldn't be too hard to do, I'm not just 100% sure on how to do it.

If you need any further help let me know. Basically it's going to be used to list the previous five articles under the news article it's showing.
OfflineView User's ProfileFind all posts by JustinSend Personal MessageSend email
Darren
Team Member



Joined: 05 Feb 2002
Posts: 549
Location: London

PostPosted: Sat Jun 25, 2005 7:30 pm (18 years, 9 months ago) Reply with QuoteBack to Top

LIMIT can accept two values the first teeling it which row to start from the second how many rows to retrieve.

for example this would take 5 rows strating from row 3
LIMIT 3,5

So maybe you need to start by taking the starting point 6 rows before the ID and then taking the following 5.
LIMIT ($id-6),5

I'm totally guessing here.
Also not sure what will happen if you end up with a negative start point e.g. if you started with an id of 3 there are only 2 preceding records.

Hope that helps
OfflineView User's ProfileFind all posts by DarrenSend Personal MessageVisit Poster's Website
Justin
4WebHelp Addict
4WebHelp Addict


Joined: 07 Jan 2002
Posts: 1060

PostPosted: Sat Jun 25, 2005 8:19 pm (18 years, 9 months ago) Reply with QuoteBack to Top

seem to get a DB error for that, to check I'm not doing something silly, could you put the exact MySQL statements I should be using on this forum or PM them to me, just want to ensure I'm doing it right.

I should know all this really, but I haven't really done anything apart from simple PHP for the last 12 months so I've kinda got a bit rusty.
OfflineView User's ProfileFind all posts by JustinSend Personal MessageSend email
Justin
4WebHelp Addict
4WebHelp Addict


Joined: 07 Jan 2002
Posts: 1060

PostPosted: Sun Jun 26, 2005 10:41 am (18 years, 9 months ago) Reply with QuoteBack to Top

Don't matter, done it now, I figured out what I was doing wrong. Used this in the end.

@$outcome=mysql_query("SELECT * FROM `articles` WHERE ID<$id ORDER BY ID DESC LIMIT 5");
if ($sectionID) @$outcome=mysql_query("SELECT * FROM articles WHERE sectionID='$sectionID' AND articleId`>=($id-5) ORDER BY 'articleId'");
OfflineView User's ProfileFind all posts by JustinSend Personal MessageSend email
Display posts from previous:      
Post New TopicReply to Topic
View Previous Topic Print this topic View Next Topic


 Jump to:   




You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot edit your posts in this forum.
You cannot delete your posts in this forum.
You cannot vote in polls in this forum.


Page generation time: 0.201404 seconds :: 18 queries executed :: All Times are GMT
Powered by phpBB 2.0 © 2001, 2002 phpBB Group :: Based on an FI Theme