Two queries - best way?
Posted: Mon Sep 18, 2006 3:27 pm
My goal is here is to simplify. There are two sections to a website, "news" and "events". I have "view.php" which I want to use to view both of them. When you are at view.php, the URL would be "view.php?nid=XX" OR "view.php?eid=XX".
While I know my code below is not 100% funcitional, is using this method a good idea? A bad habit to get into?
While I know my code below is not 100% funcitional, is using this method a good idea? A bad habit to get into?
Code: Select all
<?php
require 'includes/connect.inc';
if (nid == TRUE) {
$nid = $_GET['nid'];
$query = "SELECT * FROM news WHERE nid='$nid'";
$result = mysql_query($query) or die('Error : ' . mysql_error());
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$ntitle = $row['ntitle'];
$nfull = $row['nfull'];
$ndate = $row['ndate'];
$ntimestamp = strtotime($ndate);
$ndate = date('F d Y', $ntimestamp);
$news = '<p class="title-big">' . $ntitle . '</p>' . $ndate;
$news .= '<p class="text-body">' . $nfull . '</p>';
echo $news;
} elseif (eid == TRUE) {
$eid = $_GET['eid'];
$query = "SELECT * FROM events WHERE eid='$eid'";
$result = mysql_query($query) or die('Error : ' . mysql_error());
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$etitle = $row['etitle'];
$edate = $row['edate'];
$etime = $row['etime'];
$edescription = $row['edescription'];
$etimestamp = strtotime(edate);
$edate = date('F d Y', $etimestamp);
$events = '<p class="title-big">' . $etitle . '</p>' . $edate;
$events .= '<p class="text-body">' . $edescription . '</p>';
echo $events;
}
mysql_close()
?>