Jump to content

Date not showing up...


davinci

Recommended Posts

I added paging to one of my scripts and now the date doesn't show up. Can someone catch my mistake?

At first I had this:

[code]<?php include 'header.php' ?>
<?php include 'left.php' ?>

<?php

include 'library/config.php';
include 'library/opendb.php';

$id = $_GET['id'];

if ($id == "") {
$query = "SELECT id, name, path, title, thumbnail, playcount, DATE_FORMAT(entry_date, '%M %D %Y') FROM upload2 ORDER BY id DESC";
$result = mysql_query($query) or die('Error, query failed');
while(list($id, $name, $path, $title, $thumbnail, $playcount, $date) = mysql_fetch_array($result)) { ?>

<div align="center">

<table cellpadding="2" width="100%"  border="0" cellspacing="0" cellpadding="0"><tr>

<td width="30%">

<a href="<?php echo $_SERVER['PHP_SELF'] ?>?id=<?= $id; ?>"><IMG BORDER="0" img src="media/thumbs/<?=$thumbnail;?>" height="80" width="80"><p>

</a></td>
<td width="70%">

<a href="<?php echo $_SERVER['PHP_SELF'] ?>?id=<?= $id; ?>"><b><?php echo $title;?></b></a><br>Added on <?=$date;?>
<br>Plays: <?=$playcount;?>

</td></tr></table>[/code]


Now wherever I put <?=$date;?> I don't get anything...
Then I changed it so that it has paging:

[code]<?php

include 'library/config.php';
include 'library/opendb.php';

$id = $_GET['id'];

if ($id == "") {

$rowsPerPage = 6;
$pageNum = 1;
if(isset($_GET['page']))
{
    $pageNum = $_GET['page'];
}
$offset = ($pageNum - 1) * $rowsPerPage;

$query = "SELECT id, name, path, title, thumbnail, playcount, DATE_FORMAT(entry_date, '%M %D %Y') FROM upload2 ORDER BY id DESC LIMIT $offset, $rowsPerPage";
$result = mysql_query($query) or die('Error, query failed');

?>

<div class="title">Video Archive</div><p>

<?php
while($row = mysql_fetch_array($result)) { ?>

<div align="center">

<table cellpadding="2" width="75%"  border="0" cellspacing="0" cellpadding="0"><tr>

<td width="50%">

<a href="<?php echo $_SERVER['PHP_SELF'] ?>?id=<?= $row['id'];?>"><IMG BORDER="0" img src="media/thumbs/<?=$row['thumbnail'];?>" height="80" width="80"><p>

</a></td>
<td width="50%">

<a href="<?php echo $_SERVER['PHP_SELF'] ?>?id=<?= $row['id'];?>"><b><?php echo $row['title'];?></b></a>
<br>Added on <?=$row['date'];?>
<br>Plays: <?=$row['playcount'];?>

</td></tr></table><? } ?>[/code]

Thank you to whoever can clear me up!
Link to comment
https://forums.phpfreaks.com/topic/4501-date-not-showing-up/
Share on other sites

[!--quoteo(post=353296:date=Mar 9 2006, 11:26 AM:name=litebearer)--][div class=\'quotetop\']QUOTE(litebearer @ Mar 9 2006, 11:26 AM) [snapback]353296[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Could be just time for my meds, but....

shouldn't this..
[code]?id=<?= $row['id'];?[/code]

be this...

[code]?id=<?echo $row['id'];?[/code]

Lite...
[/quote]

actually, that's correct syntax. if you're only echoing a variable, you can use the shorthand <?= opening tag instead.

as to the question at hand:
you're formatting your date in your query, but you're not defining the results as "date", yet you're trying to echo "date" out of the array. i think you should be able to change your query to this and be ok:
[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']SELECT[/span] id, name, path, title, thumbnail, playcount, DATE_FORMAT(entry_date, [color=red]'%M %D %Y'[/color]) [color=green]AS[/color] date [color=green]FROM[/color] [color=orange]upload2[/color] [color=green]ORDER BY[/color] id [color=green]DESC[/color] LIMIT $offset, $rowsPerPage
[!--sql2--][/div][!--sql3--]

by using the "AS date", you are naming the results 'date' in your array, so you can just <?= $row['date'] ?> where you want it displayed.

hope this helps
Link to comment
https://forums.phpfreaks.com/topic/4501-date-not-showing-up/#findComment-15829
Share on other sites

[!--quoteo(post=353305:date=Mar 9 2006, 12:00 PM:name=obsidian)--][div class=\'quotetop\']QUOTE(obsidian @ Mar 9 2006, 12:00 PM) [snapback]353305[/snapback][/div][div class=\'quotemain\'][!--quotec--]
actually, that's correct syntax. if you're only echoing a variable, you can use the shorthand <?= opening tag instead.

as to the question at hand:
you're formatting your date in your query, but you're not defining the results as "date", yet you're trying to echo "date" out of the array. i think you should be able to change your query to this and be ok:
[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']SELECT[/span] id, name, path, title, thumbnail, playcount, DATE_FORMAT(entry_date, [color=red]'%M %D %Y'[/color]) [color=green]AS[/color] date [color=green]FROM[/color] [color=orange]upload2[/color] [color=green]ORDER BY[/color] id [color=green]DESC[/color] LIMIT $offset, $rowsPerPage [!--sql2--][/div][!--sql3--]

by using the "AS date", you are naming the results 'date' in your array, so you can just <?= $row['date'] ?> where you want it displayed.

hope this helps
[/quote]


You guys rock! Adding the "AS date" did the trick!
Link to comment
https://forums.phpfreaks.com/topic/4501-date-not-showing-up/#findComment-15962
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.