Forum Moderators: coopster
function getEntryInfo($username){
$q = "SELECT * FROM ".JOURNAL_ENTRIES." WHERE journal_id = '$username' ORDER by entry_id DESC LIMIT 0, 30";
$result = mysql_query($q, $this->connection);
$dbarray = mysql_fetch_array($result);
return $dbarray;
} Thats the database query, heres the code that displays the results;
<?
$entry = trim($_GET['user']);
if(!$entry ¦¦ strlen($entry) == 0 ¦¦
!eregi("^([0-9a-z])+$", $entry) ¦¦
!$database->usernameTaken($entry)){
die("Username not registered");
}
$journal_info = $database->getJournalInfo($entry);
$entry_info = $database->getEntryInfo($entry);
?>
<?php echo "<h2>".$journal_info['journal_name']."</h2>";?>
<div style="border: 1px solid #000000;">
<div align="center"><b><?php echo " ".$entry_info['entry_subject']."<br><br>";?></b><?php echo " ".$entry_info['entry_time']."<br><br>";?></div>
<div align="center"><?php echo " ".$entry_info['entry_text']."";?></div>
</div>
<?php
if(strcmp($session->username,$entry) == 0){
echo "<br><a href=\"update.php\">Update</a><br>";
}
echo "<br>Back To [<a href=\"index.php\">Home</a>]<br>";
?> Im fairly new to php, but im fairly sure this should return the last 30 entries, but it only returns one. Can anybody help?
you would require something of the sort:
function getEntryInfo($username){
$q = "SELECT * FROM ".JOURNAL_ENTRIES." WHERE journal_id = '$username' ORDER by entry_id DESC LIMIT 0, 30";
$result = mysql_query($q, $this->connection);
while ($row = mysql_fetch_array($result))
$dbarray[] = $row;
return $dbarray;
}
and then in the page code
$entry_info = $database->getEntryInfo($entry);
$info_found = count($entry_info); // number of journal posts found (max 30 due to limit)<?php echo "<h2>".$journal_info['journal_name']."</h2>";?> // display once (outside for loop)
for ($i = 0; $i < $info_found; $i++) {
$current_entry_info = $entry_info[$i];
?>
<div style="border: 1px solid #000000;">
<div align="center"><b><?php echo " ".$current_entry_info['entry_subject']."<br><br>";?></b><?php echo " ".$current_entry_info['entry_time']."<br><br>";?></div>
<div align="center"><?php echo " ".$current_entry_info['entry_text']."";?></div>
</div>
<?php
if(strcmp($session->username,$entry) == 0){
echo "<br><a href=\"update.php\">Update</a><br>";
}} // ends for loop
echo "<br>Back To [<a href=\"index.php\">Home</a>]<br>";
?>