Ameslee Posted May 4, 2006 Share Posted May 4, 2006 hope someone can help me, i want to know how to display a certain amount of records coming from a database on my website. can anyone help me???another question!!! once displaying a certain amount of records on the website, how do i keep it up to date so that once a date passes, because i am displaying events and the dates they are on, that one gets replaced with newer ones from the database. thanks! Quote Link to comment Share on other sites More sharing options...
Ameslee Posted May 4, 2006 Author Share Posted May 4, 2006 [quote name='Ames' date='May 4 2006, 10:41 AM' post='371116']hope someone can help me, i want to know how to display a certain amount of records coming from a database on my website. can anyone help me???ive managed to do the above like this:$i=1;while (($row!="")&&($i<=6))now im not sure how to replace records displayed where the dates have passed, please help!!!!! Quote Link to comment Share on other sites More sharing options...
Ameslee Posted May 5, 2006 Author Share Posted May 5, 2006 Ok im not sure if im making sense so im going to have another go at explaining my probelem.I am displaying events with dates on a website. I have limited how many records are to be displayed at once, i now want to know how i can keep these records up to date so that events that have passed do not show and are replaced with newer events from the database????hope this makes sense, thanks Quote Link to comment Share on other sites More sharing options...
jeremywesselman Posted May 5, 2006 Share Posted May 5, 2006 The easiest way to do this by your specifications would be to use an 'id' column in your database table, assuming that you have one. Just select the last x records from your table, order by 'id' descending.[code]<?php$query = "SELECT * FROM table ORDER BY id DESC LIMIT 10";?>[/code]Your query would look something like that.[!--coloro:#990000--][span style=\"color:#990000\"][!--/coloro--]Jeremy[!--colorc--][/span][!--/colorc--] Quote Link to comment Share on other sites More sharing options...
Ameslee Posted May 6, 2006 Author Share Posted May 6, 2006 [!--quoteo(post=371470:date=May 5 2006, 06:29 PM:name=jeremywesselman)--][div class=\'quotetop\']QUOTE(jeremywesselman @ May 5 2006, 06:29 PM) [snapback]371470[/snapback][/div][div class=\'quotemain\'][!--quotec--]The easiest way to do this by your specifications would be to use an 'id' column in your database table, assuming that you have one. Just select the last x records from your table, order by 'id' descending.[code]<?php$query = "SELECT * FROM table ORDER BY id DESC LIMIT 10";?>[/code]Your query would look something like that.[!--coloro:#990000--][span style=\"color:#990000\"][!--/coloro--]Jeremy[!--colorc--][/span][!--/colorc--][/quote]thanks for you helpi have already got this statement:$query = "SELECT * FROM events ORDER BY Date"; date being my field and events being the table. So when u say id that would be eventid for me, as that is my primary key field. So that simple query, will keep updating new events that are added to my database? thanks! Amy! Quote Link to comment Share on other sites More sharing options...
dougal85 Posted May 6, 2006 Share Posted May 6, 2006 [!--quoteo(post=371782:date=May 6 2006, 08:03 AM:name=Ames)--][div class=\'quotetop\']QUOTE(Ames @ May 6 2006, 08:03 AM) [snapback]371782[/snapback][/div][div class=\'quotemain\'][!--quotec--]thanks for you helpi have already got this statement:$query = "SELECT * FROM events ORDER BY Date"; date being my field and events being the table. So when u say id that would be eventid for me, as that is my primary key field. So that simple query, will keep updating new events that are added to my database? thanks! Amy![/quote]SELECT * FROM events ORDER BY Date DESC LIMIT 0, 10will give you the most recent 10 assuming you have a date field with the date of when its posted.LIMIT works like this : LIMIT starting number, countie. LIMIT 0, 10 - starts at 0 gives you 10 - records 0 - 9LIMIT 4, 5 - Starts at result 4 and gives you 4 - records 4 - 9 Quote Link to comment Share on other sites More sharing options...
Ameslee Posted May 8, 2006 Author Share Posted May 8, 2006 [!--quoteo(post=371811:date=May 6 2006, 11:15 PM:name=Dougal Matthews)--][div class=\'quotetop\']QUOTE(Dougal Matthews @ May 6 2006, 11:15 PM) [snapback]371811[/snapback][/div][div class=\'quotemain\'][!--quotec--]SELECT * FROM events ORDER BY Date DESC LIMIT 0, 10will give you the most recent 10 assuming you have a date field with the date of when its posted.LIMIT works like this : LIMIT starting number, countie. LIMIT 0, 10 - starts at 0 gives you 10 - records 0 - 9LIMIT 4, 5 - Starts at result 4 and gives you 4 - records 4 - 9[/quote]ok i have worked it out a different way, others may be interested or have the same problem. I did it this way:$query = "SELECT * FROM events WHERE Date >=now() ORDER BY Date ASC";Events is my table, Date is my field. It works well!Thanks anyways to all!Amy Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.