complicated blog problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jiggajames
Forum Newbie
Posts: 3
Joined: Thu Aug 04, 2005 8:39 pm

complicated blog problem

Post by jiggajames »

I am making a website for a fraternity and I am working on this blog and its getting complicated and I can't get it to work. The blog can be posted to by two different user groups, brothers and alumni. If a brother posts I want the link at the bottom to say posted by and then a link to "brotherprofile.php..." where as when an alumni posts I want the link at the bottom to go to "alumniprofile.php..." . Currently I am determining whether someone is an alumni or not by selecting the email address from a list of alumni and then using and if statement. RIght now when I run the script the links at the bottom are all the same and are controled by who ever is the last person that posted. Anyway heres the code:

Code: Select all

<?php
session_start();
require '../req.php';
require 'header.php';
require_once '../pager.php';
require 'auth.php';
adminsessionAuthenticate();
$connection = mysql_connect($hostname, $username, $password);
$p = new Pager;
$limit = 5;
$start = $p->findStart($limit);
mysql_select_db("betasigma", $connection);
$result = mysql_query ("SELECT Subject FROM alumniblog", $connection);
$count = mysql_num_rows($result);
$pages = $p->findpages($count, $limit);
print "\n<table width='650' class='blogtitle'>\n<tr>\n<td align='left' valign='top'>Alumni Blog\n</td>\n</tr>\n</table>\n<br>";
print "\n<table width='650'>\n<tr>\n<td width='450' valign='top' align='left'>";
mysql_select_db("betasigma", $connection);
$result = mysql_query ("SELECT Date, Subject, FirstName, LastName, Year, Email, Message, Picture FROM alumniblog LIMIT ".$start.", ".$limit, $connection);
while($row = mysql_fetch_array($result))
{
$posttime = "{$row["Date"]}";
$offset = "3600";
$posttime += $offset;
$date = date("F jS Y", $posttime);
$time = date("g:i A", $posttime);
$message = "{$row["Message"]}";
$firstname = "{$row["FirstName"]}";
$lastname = "{$row["LastName"]}";
$year = "{$row["Year"]}";
$subject = "{$row["Subject"]}";
$picture = "{$row["Picture"]}";
$messagestripped = stripslashes($message);
$email = "{$row["Email"]}";
$result1 = mysql_query ("SELECT Email FROM regalumni WHERE Email = '$email'", $connection);
while($row = mysql_fetch_array($result1))
{
$alum = "{$row["Email"]}";
}
if ($alum == "")
{
print "\n<span class='blogsubject'> $subject \n</span><br><img src='".$picture."'><br><span class='blogtext'>$messagestripped \n</span>\n<br>\n<span class='blogstamp'>Posted by: \n<a href='brotherprofile.php?brother=".$lastname."'>$firstname $lastname</a> (".$year.") on $date at $time EST\n</span>\n<br>\n<br>";
}
else
{
print "\n<span class='blogsubject'> $subject \n</span><br><img src='".$picture."'><br><span class='blogtext'>$messagestripped\n</span>\n<br>\n<span class='blogstamp'>Posted by: \n<a href='alumniprofile.php?lastname=".$lastname."&firstname=".$firstname."&year=".$year."'>$firstname $lastname</a> (".$year.") on $date at $time EST\n</span>\n<br>\n<br>";
}
}
$next_prev = $p->nextPrev($_GET['page'], $pages);
print "\n<table width='100%'><tr><td align='right'><span class='text'>$next_prev</span></td></tr></table>";
print "\n</td>\n<td width='200' valign='top' align='left'>";
include "alumrecentupdates.php";
print "\n</td>\n</tr>\n</table>";
require 'footer.php';
?>

feyd | :roll:
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

what's the actual problem?

you can make the alumni data come in through using a LEFT JOIN...
jiggajames
Forum Newbie
Posts: 3
Joined: Thu Aug 04, 2005 8:39 pm

not sure

Post by jiggajames »

Im not sure what you mean. The problem resides in:

Code: Select all

$result = mysql_query ("SELECT Date, Subject, FirstName, LastName, Year, Email, Message, Picture FROM alumniblog LIMIT ".$start.", ".$limit, $connection); 
while($row = mysql_fetch_array($result)) 
{ 
$posttime = "{$row["Date"]}"; 
$offset = "3600"; 
$posttime += $offset; 
$date = date("F jS Y", $posttime); 
$time = date("g:i A", $posttime); 
$message = "{$row["Message"]}"; 
$firstname = "{$row["FirstName"]}"; 
$lastname = "{$row["LastName"]}"; 
$year = "{$row["Year"]}"; 
$subject = "{$row["Subject"]}"; 
$picture = "{$row["Picture"]}"; 
$messagestripped = stripslashes($message); 
$email = "{$row["Email"]}"; 
$result1 = mysql_query ("SELECT Email FROM regalumni WHERE Email = '$email'", $connection); 
while($row = mysql_fetch_array($result1)) 
{ 
$alum = "{$row["Email"]}"; 
} 
if ($alum == "") 
{ 
print "\n<span class='blogsubject'> $subject \n</span><br><img src='".$picture."'><br><span class='blogtext'>$messagestripped \n</span>\n<br>\n<span class='blogstamp'>Posted by: \n<a href='brotherprofile.php?brother=".$lastname."'>$firstname $lastname</a> (".$year.") on $date at $time EST\n</span>\n<br>\n<br>"; 
} 
else 
{ 
print "\n<span class='blogsubject'> $subject \n</span><br><img src='".$picture."'><br><span class='blogtext'>$messagestripped\n</span>\n<br>\n<span class='blogstamp'>Posted by: \n<a href='alumniprofile.php?lastname=".$lastname."&firstname=".$firstname."&year=".$year."'>$firstname $lastname</a> (".$year.") on $date at $time EST\n</span>\n<br>\n<br>"; 
} 
}
instead of printing the first thing when it is posted by a brother, and the second when it is posted by a alumni for each post (row) the script is printing which ever is true for the first post (row) for all the posts (rows).


feyd | you can start using [php tags anytime now...
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Re: not sure

Post by timvw »

jiggajames wrote:Im not sure what you mean
He said that if you use JOIN, you don't have to an extra query for each blogmessage that is returned. (In case you recieve a NULL, it means that there was no such e-mail, and thus is not an alumni)
jiggajames wrote: $year = "{$row["Year"]}";
Do you have a clue what the above does? Or where did you copy it?
Imho, a more sane way to do exactly the same thing:

Code: Select all

$year = $row['Year'];
jiggajames wrote: $result1 = mysql_query ("SELECT Email FROM regalumni WHERE Email = '$email'", $connection);
while($row = mysql_fetch_array($result1))
{
$alum = "{$row["Email"]}";
}
Actually, because you use a while loop it seems that you are expecting multiple rows to be returned.
jiggajames wrote: if ($alum == "")
{

The problem is that you haven't initialised $alum properly... As soon as you find something with an alumemail, the following blogs will have $alum set to that value..
Post Reply