Jump to content

Recommended Posts

im completely new to php and programing all together

 

and i have a question.

 

I have a mysql database that has a date and info columns

 

i want to be echo the last three rows in chronological order starting from the latest one on top

 

how can i do this?

 

plz help me

 

thank you

 

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

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.