0
<?php

$id = $_GET['id'];

$dbhost = 'localhost';
$dbuser = 'idc_champ';
$dbpass = 'Gx%#_$D{rT#';
$rec_limit = 10;



$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
  die('Could not connect: ' . mysql_error());
}
mysql_select_db('idc_central');

/* Get total number of records */
$sql = "SELECT count(id) FROM page where type='News'";
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
  die('Could not get data: ' . mysql_error());
}
$row = mysql_fetch_array($retval, MYSQL_NUM );
$rec_count = $row[0];

if( isset($_GET{'page'} ) )
{
   $page = $_GET{'page'} + 1;
   $offset = $rec_limit * $page ;
}
else
{
   $page = 0;
   $offset = 0;
}
$left_rec = $rec_count - ($page * $rec_limit);


if (empty($id))
{
$sql = "SELECT * ".
       "FROM page where type='News'".
       "ORDER BY date DESC";
       "LIMIT $offset, $rec_limit";

}
else
{
$sql = "SELECT * ".
       "FROM page where type='News' and id =$id ".
       "LIMIT $offset, $rec_limit";

}
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
  die('Could not get data: ' . mysql_error());
}

echo "<h1>News</h1><hr>";
while($row = mysql_fetch_array($retval, MYSQL_ASSOC))
{

    if (empty($row['Image']))
    {
    echo  

            "<h3>{$row['date']}</h3>".
            "<h2>{$row['title']}</h2>".
            "<p>{$row['content']}</p>".
          "<hr>";
          }else
          {
          echo "<h3>{$row['date']}</h3>".
          "<h2>{$row['title']}</h2>".
        "<img src=\"http://indiandiasporacouncil/admin/images/upload_file/{$row['Image']}\" class=\"postimage\">".
         "<p>{$row['content']}</p>".
          "<hr>";

          }
} 

if( $page > 0 )
{
   $last = $page - 2;
   echo "<a href=\"$_PHP_SELF?page=$last\">< Last </a> |";
   echo "<a href=\"$_PHP_SELF?page=$page\">Next ></a>";
}
else if( $page == 0 )
{
    if ($row > 10)
    {
   echo "<a href=\"$_PHP_SELF?page=$page\">Next ></a>";
    }
}
else if( $left_rec < $rec_limit )
{
   $last = $page - 2;
   echo "<a href=\"$_PHP_SELF?page=$last\"> < Last</a>";
}
mysql_close($conn);



?>

I am new to php coding, I am a learner. How can I change the date format from yyyymmdd to ddmmyyyy. I am echoing the date as {$row['date']} and it is showing date as 2017-06-24, but I want the date to be shown as 24-06-2017. Please help

  • https://stackoverflow.com/questions/2487921/convert-date-format-yyyy-mm-dd-dd-mm-yyyy – rbaskam Jun 26 '17 at 10:55
  • 1
    Every time you use [the `mysql_`](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php) database extension in new code **[this happens](https://media.giphy.com/media/kg9t6wEQKV7u8/giphy.gif)** it is deprecated and has been for years and is gone for ever in PHP7. If you are just learning PHP, spend your energies learning the `PDO` or `mysqli` database extensions and prepared statements. [Start here](http://php.net/manual/en/book.pdo.php) – RiggsFolly Jun 26 '17 at 10:56
  • 1
    Please do a search before asking a question [How much research effort is expected of Stack Overflow users?](https://meta.stackoverflow.com/questions/261592/how-much-research-effort-is-expected-of-stack-overflow-users) – RiggsFolly Jun 26 '17 at 10:57
  • Date functions in PHP will help you!! – masterFly Jun 26 '17 at 11:11

0 Answers0