I have a site where I built two tables that house user information and their story information. The site is kind of like a blog in that people can post their own own stories about their relationships. Basically the story table has all the stories information like id, title, body etc and the posting persons id. The second table has the users info such as id first name, last name, etc. I have a story.php which is dynamic in that it grabs information based on the url so if there is story 2 the link would be story.php?sid=2. So what happens is the information is pulled based on that sid and in turn the posting users id is pulled via a while loop where i create variables for every column in the table. What I want is to be able to run basically two while loops on inside the other in order to get information based on the initial while loop column uid (users id). I don't know if this is clear but this is what I've build:
function story() {
// connection information
include 'includes/connection.php';
$sid = "23";
// mysql connection
mysql_connect("$host", "$user", "$pass") or die(mysql_error());
mysql_select_db("$dbname") or die(mysql_error());
// grabs all story information
$squery = ("SELECT * FROM $stable WHERE sid = '$sid'");
$sresult = mysql_query($squery) or die(mysql_error());
$fullstory = '';
while($srow = mysql_fetch_array($sresult)){
// grab variables for the story
$ssid = $srow['sid']; // stories id
$title = $srow['title'];
$body = $srow['body'];
$keywords = $srow['keywords'];
$suid = $srow['uid']; // the posting users id
$sdate = $srow['date'];
$accusedfname = $srow['accusedfname'];
$accusedlname = $srow['accusedlname'];
$location = $srow['location'];
$accusedfacebook = $srow['accusedfacebook'];
$accusedmyspace = $srow['accusedmyspace'];
$accusedimage = $srow['accusedimage'];
// mysql connection
mysql_connect("$host", "$user", "$pass") or die(mysql_error());
mysql_select_db("$dbname") or die(mysql_error());
// grabs all information on the posting user
$uquery = ("SELECT * FROM $utable WHERE uid = '$suid'");
$uresult = mysql_query($uquery) or die(mysql_error());
// grabs the posting users information
while($urow = mysql_fetch_array($uresult)){
$uid = $urow['uid'];
$fname = $urow['fname'];
$lname = $urow['lname'];
$image = $urow['image'];
$fullstory .= '
<div id="story-wrap">
<div class="story-image">
<p>
The Accused: '.$accusedfname.' '.$accusedlname.'<br/>
<a target="_blank" href="'.$accusedimage.'"><img src="'.$accusedimage.'" alt="'.$accusedfname.' '.$accusedlname.'" title="'.$accusedfname.' '.$accusedlname.'" /></a>
</p>
<p>
The Accuser: <a href="user-profile.php?uid='.$uid.'">'.$fname.' '.$lname.'</a><br/>
<a target="_blank" href="'.$image.'"><img src="'.$image.'" alt="'.$fname.' '.$lname.'" title="'.$fname.' '.$lname.'" /></a>
</p>
</div>
<div class="story-copy">
<h3><a href="user-profile.php?uid='.$uid.'">'.$fname.' '.$lname.'</a> wrote: '.$title.'</h3>
<p>'.$body.'</p>
<p>Posted on: '.$sdate.'<br/>
The accused"s <a href="'.$accusedfacebook.'">Facebook</a><br/>
The accused"s <a href="'.$accusedmyspace.'">Myspace</a><br/>
The accused"s <a href="'.$location.'">'.$location.'</a>
</div>
</div>
';
}
}
return $fullstory;
}
When I run this I get some errors, I tried tweaking the code ending the loops once the variables had been built then just echoing the information out after but that just wouldn't echo anything out and what I got was a blank screen. If anyone can help it would be greatly appreciated! Thanks