Jump to content


Photo

Date not showing up...


  • Please log in to reply
3 replies to this topic

#1 davinci

davinci
  • Members
  • PipPip
  • Member
  • 29 posts

Posted 09 March 2006 - 04:02 AM

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:

<?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>


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

<?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><? } ?>

Thank you to whoever can clear me up!

#2 litebearer

litebearer
  • Members
  • PipPipPip
  • Advanced Member
  • 2,357 posts
  • Locationwhite lake michigan

Posted 09 March 2006 - 04:26 PM

Could be just time for my meds, but....

shouldn't this..


?id=<?= $row['id'];?

be this...

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

Lite...

all the brothers were valiant!

[br][br]The truely intelligent people are not those who create the dots; rather they are they ones with the ability to connect the dots into a coherent picture

#3 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 09 March 2006 - 05:00 PM

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

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

be this...

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

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, '%M %D %Y') AS date FROM upload2 ORDER BY id DESC 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
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#4 davinci

davinci
  • Members
  • PipPip
  • Member
  • 29 posts

Posted 09 March 2006 - 11:59 PM

[!--quoteo(post=353305:date=Mar 9 2006, 12:00 PM:name=obsidian)--][div class=\'quotetop\']QUOTE(obsidian @ Mar 9 2006, 12:00 PM) View Post[/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, '%M %D %Y') AS date FROM upload2 ORDER BY id DESC 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!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users