Jump to content

[SOLVED] last 3 dates


gevo12321

Recommended Posts

thanks and also is there a way to make the date look like a regular date?

 

in the format: mm/dd/yyyy

 

also could you tell me what im doing wrong in the php trying to display the info

 

<?php
include 'connect.php';
$news = mysql_query("SELECT date,title FROM news ORDER BY date desc LIMIT 3") or die(mysql_error());
echo $news;
?>

 

thank you very much

 

ps

 

im trying to display the info on 3 different lines but i have no idea how

 

thx

Link to comment
https://forums.phpfreaks.com/topic/56822-solved-last-3-dates/#findComment-280738
Share on other sites

thx for the help

 

yet i have another problem

 

the following code is for only for today's date i guess?

 

<?php
include 'connect.php';
mysql_query("SELECT date,title FROM news ORDER BY date desc LIMIT 3") or die(mysql_error());
$date1=$row->appdate;
$date=date('m-d-Y',strtotime($date1));
echo $date;
?>

 

because i guess all i get is 06-23-2007

 

but i'm trying to see the the dates and titles in chronological order

 

im sorry if i dont make sense

 

plz help me

Link to comment
https://forums.phpfreaks.com/topic/56822-solved-last-3-dates/#findComment-280745
Share on other sites

try this code bcoz u have to fetch ur data 1st than assign it to variables.

ok try:

<?php
include 'connect.php';
$query=mysql_query("SELECT date,title FROM news ORDER BY date desc LIMIT 3") or die(mysql_error());
$row=mysql_fetch_object($query);
$date1=$row->date;
$title=$row->tiltle;
$date=date('m-d-Y',strtotime($date1));
echo $date;
echo "<br>";
echo $title;
?>

Link to comment
https://forums.phpfreaks.com/topic/56822-solved-last-3-dates/#findComment-280751
Share on other sites

thank you very much

 

the following code works

 

<?php
include 'connect.php';
$query=mysql_query("SELECT date,title FROM news ORDER BY date desc LIMIT 3") or die(mysql_error());
$row=mysql_fetch_object($query);
$date1=$row->date;
$title=$row->title;
$date=date('m-d-Y',strtotime($date1));
echo $date;
echo " ";
echo $title;
?>

 

but it doesn't display the last 3 rows

 

it only displays one

 

how can i make it all 3?

 

thank you

Link to comment
https://forums.phpfreaks.com/topic/56822-solved-last-3-dates/#findComment-280755
Share on other sites

Oh sorry for that u have to use while loop here.

<?php
include 'connect.php';
$query=mysql_query("SELECT date,title FROM news ORDER BY date desc LIMIT 3") or die(mysql_error());
while($row=mysql_fetch_object($query));{
$date1=$row->date;
$title=$row->title;
$date=date('m-d-Y',strtotime($date1));
echo $date;
echo " ";
echo $title;
}
?>

 

Try it and let me know it works or not.

Link to comment
https://forums.phpfreaks.com/topic/56822-solved-last-3-dates/#findComment-280757
Share on other sites

so u want me to do this?

 

<?php
include 'connect.php';
$query=mysql_query("SELECT newsnumber,title FROM news ORDER BY date desc LIMIT 3") or die(mysql_error());
while($row=mysql_fetch_object($query));
{
$date1=$row->date;
$title=$row->title;
$date=date('m-d-Y',strtotime($date1));
echo $date;
echo " ";
echo $title;
}
?>

 

still doesn't work though

 

im sorry im a complete noob at this

Link to comment
https://forums.phpfreaks.com/topic/56822-solved-last-3-dates/#findComment-280764
Share on other sites

No

like this:

<?php
include 'connect.php';
$query=mysql_query("SELECT * FROM news ORDER BY newsnumber desc LIMIT 3") or die(mysql_error());
while($row=mysql_fetch_object($query));
{
$date1=$row->date;
$title=$row->title;
$date=date('m-d-Y',strtotime($date1));
echo $date;
echo " ";
echo $title;
}
?>

 

Link to comment
https://forums.phpfreaks.com/topic/56822-solved-last-3-dates/#findComment-280766
Share on other sites

still didnt work

 

so i tryed this:

<?php
require_once('connect.php');
$query=mysql_query("SELECT date,title FROM news ORDER BY date desc LIMIT 3") or die(mysql_error());
while($row=mysql_fetch_array($query));
{
print_r($row);
$date1=$row['date'];
$title=$row['title'];
$date=date('m-d-Y',strtotime($date1));
echo $date;
echo " ";
echo $title;
}
?>

that didnt work either

 

wow

 

i have no idea what to do

Link to comment
https://forums.phpfreaks.com/topic/56822-solved-last-3-dates/#findComment-280769
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.