t3chguy
asked on
Three Random Stories one page, weird table layout
I have a query that pulls three random news stories from a table, and displays them on the page. The random order works perfectly if i have one per row in a table, or put a line break between each one. The problem is that i want two of the stories to be side by side with the third story being underneath them in a new row that spans across both columns.
When I do this, however, all three stories are the same, which obviously is not what I'm trying to do.
Screenshot of page and code is attached.
When I do this, however, all three stories are the same, which obviously is not what I'm trying to do.
Screenshot of page and code is attached.
<?php
//News Index page
require_once($_SERVER['DOCUMENT_ROOT']."/includes/verifyaccess.php");
if ($permgrpid == '0' or $permgrpid == '')
{
header("Location: login.php?error=unauthaccess");
die;
}
require_once($_SERVER['DOCUMENT_ROOT']."/includes/header.php");
$interval = 240;
$compquery = "";
$stickysql = "";
if (isset($sticky)) $stickysql = " and newsid != " . $sticky;
$randhour = (date("j") * 100 + date("g"));
$query = "SELECT DISTINCT(news_stories.newsid), news_stories.title, news_stories.story, news_stories.date, news_stories.author, news_stories.image, news_stories.apprauth,
news_stories.apprmod, news_comments.date, news_comments.sentby, news_comments.newsitem, news_comments.comment FROM news_stories LEFT JOIN news_comments ON news_stories.newsid = news_comments.newsitem WHERE DATE_SUB(CURDATE(),INTERVAL $interval DAY) <= news_stories.date AND image = '1' AND apprmod = '1' AND apprauth = '1' group by news_stories.newsid order by rand() limit 0,1";
$res = mysql_query($query) or die (mysql_error());
//echo $query . "<br />";
echo "<table width='95%' align='center' cellspacing = '3' cellpadding='3'>";
while ($row = mysql_fetch_array($res))
{
$newsid = $row['newsid'];
$newsid2 = $row['newsid'];
$newsid3 = $row['newsid'];
$title = $row['title'];
$story = $row['story'];
$date = $row['date'];
$author = $row['author'];
$image = $row['image'];
$commentdate = $row['date'];
$sentby = $row['sentby'];
$commentnewsitem = $row['newsitem'];
$comment = $row['comment'];
echo "<tr>";
echo "<td><span class='newsheadline'>" . fixQuotes($title) . "</span><br />" . fixQuotes($story) . "</td>";
echo "<td><span class='newsheadline'>" . fixQuotes($title) . "</span><br />" . fixQuotes($story) . "</td>";
echo "</tr>";
echo "<tr><td> </td></tr>";
echo "<tr><td colspan = '2'><span class='newsheadline'>" . fixQuotes($title) . "</span><br />" . fixQuotes($story) . "</td></tr>";
}
echo "</table>";
?>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Jay, thank you so much for the help. This worked like a charm!!
echo "<tr><td> </td></tr>";
echo "<tr><td colspan = '2'>
the first td cell needs to be colspan = 2 also
echo "<tr><td colspan = '2'> </td></tr>";
echo "<tr><td colspan = '2'>