Jump to content


Photo

Displaying records


  • Please log in to reply
6 replies to this topic

#1 Ameslee

Ameslee
  • Members
  • PipPipPip
  • Advanced Member
  • 131 posts

Posted 04 May 2006 - 12:41 AM

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!

#2 Ameslee

Ameslee
  • Members
  • PipPipPip
  • Advanced Member
  • 131 posts

Posted 04 May 2006 - 02:06 AM

[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!!!!!

#3 Ameslee

Ameslee
  • Members
  • PipPipPip
  • Advanced Member
  • 131 posts

Posted 05 May 2006 - 02:21 AM

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


#4 jeremywesselman

jeremywesselman
  • Members
  • PipPipPip
  • Advanced Member
  • 154 posts
  • LocationIndependence, KY

Posted 05 May 2006 - 08:29 AM

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.

<?php
$query = "SELECT * FROM table ORDER BY id DESC LIMIT 10";
?>

Your query would look something like that.

[!--coloro:#990000--][span style=\"color:#990000\"][!--/coloro--]Jeremy[!--colorc--][/span][!--/colorc--]

#5 Ameslee

Ameslee
  • Members
  • PipPipPip
  • Advanced Member
  • 131 posts

Posted 06 May 2006 - 07:03 AM

[!--quoteo(post=371470:date=May 5 2006, 06:29 PM:name=jeremywesselman)--][div class=\'quotetop\']QUOTE(jeremywesselman @ May 5 2006, 06:29 PM) View Post[/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.

<?php
$query = "SELECT * FROM table ORDER BY id DESC LIMIT 10";
?>

Your query would look something like that.

[!--coloro:#990000--][span style=\"color:#990000\"][!--/coloro--]Jeremy[!--colorc--][/span][!--/colorc--]
[/quote]

thanks for you help

i 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!

#6 dougal85

dougal85
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 06 May 2006 - 01:15 PM

[!--quoteo(post=371782:date=May 6 2006, 08:03 AM:name=Ames)--][div class=\'quotetop\']QUOTE(Ames @ May 6 2006, 08:03 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
thanks for you help

i 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, 10

will 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, count

ie.
LIMIT 0, 10 - starts at 0 gives you 10 - records 0 - 9
LIMIT 4, 5 - Starts at result 4 and gives you 4 - records 4 - 9

#7 Ameslee

Ameslee
  • Members
  • PipPipPip
  • Advanced Member
  • 131 posts

Posted 08 May 2006 - 01:18 AM

[!--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) View Post[/div][div class=\'quotemain\'][!--quotec--]
SELECT * FROM events ORDER BY Date DESC LIMIT 0, 10

will 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, count

ie.
LIMIT 0, 10 - starts at 0 gives you 10 - records 0 - 9
LIMIT 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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users