Three Column Population - php

So, I took over a project from someone else, and I am trying to populate three columns in a table where there was previously two columns. I've almost got things figured out, but can't quite get my third column to fill. I've got it so its separating the the data into thirds, but only the left column actually has exactly one third of the data. The middle column has the other two thirds of data, and the right column has no data.
Here is the code I am working with. However, I've changed what we produce to "stuff" and left out the url for privacy reasons:
$iUp = 1;
$pQuery = mysql_query($query) or die(mysql_error());
$pExist = mysql_num_rows($pQuery);
if(!empty($pExist)){
//$this->stuffPackageOut .= '<form action="https://*************.111/cart" method="GET" name="stuff" onsubmit="return anyCheck()">';
//$this->stuffPackageOut .= '<form action="index.php" method="GET" name="stuff" onsubmit="return anyCheck()">';
$this->stuffPackageOut .= '<input type="hidden" name="cart!addFamily">';
$pCnt = $pExist;
$pCntHalf = floor($pCnt/3);
$stuff[0] = NULL;
$stuff[1] = NULL;
$stuff[2] = NULL;
$div = 0;
while($pRow = mysql_fetch_object($pQuery)){
if($pCntHalf < $iUp){
$div = 2;
$div = 1;
}else{
$div = 0;
}
$contribName = strtolower(str_replace(" ", "", $pRow->conName));
$stuffName = strtolower(str_replace(" ", "", $pRow->stfName));
$stuff[$div] .= '<tr><td valign="top"><input type="checkbox" name="cart_family'.$iUp.'" value="'.$pRow->familyId.'" id="package"> <a href="http://****************.com/stuff/'.$stuffName.'.php" class="packagestufflinks">'.$pRow->fntName.'</td></tr>';
$iUp++;
}
$stuffLeft = '<table width="137" border="0" cellspacing="8" cellpadding="0" height="10" valign="top">';
$stuffLeft .= $stuff[0];
$stuffLeft .= '</table>';
$stuffMiddle = '<table width="137" border="0" cellspacing="8" cellpadding="0" height="10" valign="top">';
$stuffMiddle .= $stuff[1];
$stuffMiddle .= '</table>';
$stuffRight = '<table width="137" border="0" cellspacing="8" cellpadding="0" height="10" valign="top">';
$stuffRight .= $stuff[2];
$stuffRight .= '</table>';
$this->stuffPackageOut .= '<table width="100%" height="10"><tr><td align="left" valign="top" width="238" height="10">'.$stuffLeft.'</td><td width="29" valign="top" background="verticaldivider.gif"><img src="http://www.****************.com/pageimages/spacer.GIF" width="29" height="5"></td><td align="left" valign="top" width="238">'.$stuffMiddle.'<td><td width="29" valign="top" background="verticaldivider.gif"><img src="http://www.****************.com/pageimages/spacer.GIF" width="29" height="5"></td><td align="left" valign="top" width="238">'.$stuffRight.'</td></tr></table>';
I know it has something to do with everything following the "while" coding, but since I don't do this for a living I have no idea what coding is necessary to make my three columns populate.
Please help me.

Try this... it should work for you... used this logic before and worked well:
<?php
$iUp = 1;
$pQuery = mysql_query($query) or die(mysql_error());
$pExist = mysql_num_rows($pQuery);
if(!empty($pExist)){
$this->stuffPackageOut .= '<input type="hidden" name="cart!addFamily">';
$pCnt = $pExist;
$pCntHalf = floor($pCnt/3);
while($pRow = mysql_fetch_object($pQuery)){
$contribName = strtolower(str_replace(" ", "", $pRow->conName));
$stuffName = strtolower(str_replace(" ", "", $pRow->stfName));
if($iUp <= $pCntHalf){
$stuff_left_a .= '<tr><td valign="top"><input type="checkbox" name="cart_family'.$iUp.'" value="'.$pRow->familyId.'" id="package"> <a href="http://****************.com/stuff/'.$stuffName.'.php" class="packagestufflinks">'.$pRow->fntName.'</td></tr>';
}
elseif($iUp >= $pCntHalf +1 && $iUp <= ($pCntHalf * 2)){
$stuff_middle_a .= '<tr><td valign="top"><input type="checkbox" name="cart_family'.$iUp.'" value="'.$pRow->familyId.'" id="package"> <a href="http://****************.com/stuff/'.$stuffName.'.php" class="packagestufflinks">'.$pRow->fntName.'</td></tr>';
}
elseif($iUp >= ($pCntHalf *2) +1){
$stuff_right_a .= '<tr><td valign="top"><input type="checkbox" name="cart_family'.$iUp.'" value="'.$pRow->familyId.'" id="package"> <a href="http://****************.com/stuff/'.$stuffName.'.php" class="packagestufflinks">'.$pRow->fntName.'</td></tr>';
}
$iUp++;
}
$stuffLeft = '<table width="137" border="0" cellspacing="8" cellpadding="0" height="10" valign="top">';
$stuffLeft .= $stuff_left_a;
$stuffLeft .= '</table>';
$stuffMiddle = '<table width="137" border="0" cellspacing="8" cellpadding="0" height="10" valign="top">';
$stuffMiddle .= $stuff_middle_a;
$stuffMiddle .= '</table>';
$stuffRight = '<table width="137" border="0" cellspacing="8" cellpadding="0" height="10" valign="top">';
$stuffRight .= $stuff_right_a;
$stuffRight .= '</table>';
$this->stuffPackageOut .= '<table width="100%" height="10">
<tr>
<td align="left" valign="top" width="238" height="10">'.$stuffLeft.'</td>
<td width="29" valign="top" background="verticaldivider.gif">
<img src="http://www.****************.com/pageimages/spacer.GIF" width="29" height="5">
</td>
<td align="left" valign="top" width="238">'.$stuffMiddle.'<td>
<td width="29" valign="top" background="verticaldivider.gif">
<img src="http://www.****************.com/pageimages/spacer.GIF" width="29" height="5">
</td>
<td align="left" valign="top" width="238">'.$stuffRight.'</td>
</tr>
</table>';
?>
I found the error... it was in my math in the middle... notice the change:
elseif($iUp >= $pCntHalf +1 && $iUp <= ($pCntHalf * 2))

Related

php and mysql. view topics date

I can final exams assignment of lecturers to create a website forum.
and now there is a problem in my coding.
please fix.
when creating a topic / thread, and we opened the topic / threadnya, there is a date that tell us when the topic / thread made.
but in my coding, showing all existing date in the database.
<?php
session_start();
if($_SESSION['logged'] == true)
{
if(isset($_SESSION['username']))
{ echo $username=$_SESSION["username"];
}else
{
header('Location:login.php');
}
}
?>
<!DOCTYPE html>
<html>
<head>
<!==CSS>
<style>
#clock{
pointer-events: none
}
</style>
<!close css>
<img src="head1.jpg" alt="icon" width="100%" height="110">
<img src="line1.jpg" alt="icon" width="100%" height="20">
<title>Venray</title>
<body background="alienbackground.jpg">
<font face="comic sans MS">
<!==Table Login==>
<table border="0" style="width:99%" bgcolor="#424242" align="center">
<tr>
<table border="0" style="width:98%" bgcolor="#424242" align="center">
<tr>
<td> <img src="start.gif" alt="icon" width="26" height="26"> </td>
<td rowspan="2" align="right">
<table border="0" bgcolor="#2E2E2E">
<tr>
<td><b>
<?php
{
echo "<tr><td><b><font color=green> Welcome, ";
echo $username;
echo '<span>, [Log Out]</span></li>';
echo "</tr></td></b></font>";
}
?>
</b></td>
</tr>
<tr>
<td id=clock align="right"><b><iframe src="http://free.timeanddate.com/clock/i4eh41xm/n108/tlsg/fn7/fs12/tct/pct/ftb/tt0/tw1/tm1/th1" frameborder="0" width="182" height="20" allowTransparency="true"></iframe>
</b></td>
</tr>
</table>
</td>
</tr>
<tr>
<td valign="top"><b><font size="4">Community</font></b></td>
</tr>
</table>
</tr>
<p style="color:#ff0000">
<!==Table please welcome==>
<table border="0" style="width:98%" bgcolor="#424242" align="center">
<tr>
<td align="right">
<?php
error_reporting(E_ALL ^ E_DEPRECATED);
require("conn.php");
$con = mysql_connect($server,$user,$pass);
$db = mysql_select_db($db);
$sql = "select * from d_admin order by username";
//echo $sql;
$ambil_data = mysql_query($sql);
while($data = mysql_fetch_array($ambil_data))
$result = mysql_query("SELECT * FROM d_admin");
$rows = mysql_num_rows($result);
echo "Member " . $rows . " * ";
?>
Post 1 * Topics 1 </td>
</tr>
</table>
<br>
<table border="1" width="98%" height="6%" align="center" bgcolor=#424242 >
<tr>
<td align="left" ><img src="hometopic.gif" width="40" height="40"> </td>
</tr>
<tr>
<table border="1" width="98%" height="40" align="center" bgcolor="#86B404" bordercolor=green>
<tr>
<th width="70%" align="left"><img src="open.png" width="40" height="40">Posting Display</th>
<td align="right"><img src="replay.png" width="150" height="40"></td>
</tr>
</tr>
<tr>
<table border="1" width="98%" height="70" align="center" bgcolor=#424242>
***<?php
error_reporting(E_ALL ^ E_DEPRECATED);
$con = mysql_connect($server,$user,$pass);
$db = mysql_select_db($db);
$sql = "select * from tabel_topik ";
$ambil_data = mysql_query($sql);
while($data = mysql_fetch_array($ambil_data))
{
echo '<tr><th align="left" valign="top" colspan="2" >'.$data['date'].'</th></tr>';
echo '</tr>';
}
?>***
<tr><th align="center" width="15%">Venray</th><td align="left" width="85%">title</td></tr>
<tr><th align="top" width="15%">join dates</th><td align="left" rowspan="2" valign="top">awd</td></tr>
<tr><th align="center" valign="top" width="15%" height="400">9 Post</th></tr>
<tr>
<td align="left">*</td>
<td align="right" width="85%"><img src="replay.png" width="150" height="40"></td></tr>
</table>
</tr>
</table>
</body>
</font>
</head>
</html>
Get forum specific datas by passing the ID or any similar field in the query for starters. Then if you are looking to format the way in which the date is displayed, you could use the php date function like this:
while($data = mysql_fetch_array($ambil_data))
{
echo '<tr><th align="left" valign="top" colspan="2" >'.date('jS M, Y',strtotime($data['date'])).'</th></tr>'; //format the date as required
echo '</tr>';
}

php generated td overlaps data when data is longer than column width

I have the following generated column for "Detail"
echo '<td width="100" align="left" bgcolor="#FFFFFF">Cheque (' . $row4['number'] . ')'. $row1['date_added'] .'</td>';
which gives me overall following table of results, where the particular column data overlaps when it is too long. What should I do? I have tried adding a '<br/>' in between, but it never worked.
Unfortunately this table had no external CSS file but the following is the full table
<table cellspacing="1" width="900" cellpadding="3" bgcolor="#CCCCCC" style="line-height:0px;margin-left: auto;margin-right: auto">
<col width="64" span="10" />
<tr height="46">
<td height="46" width="600" colspan="10" bgcolor="#FFFFFF"><h1>Blah Blah</h1></td>
</tr>
<?php
include './DatabaseConnection.php';
$db = new DatabaseConnection();
$db->createDatabaseConnection();
$cusid = $_GET['cusid'];
$startDate=$_GET['startDate'];
$endDate=$_GET['endDate'];
$query2 = mysql_query("select cusname from customers where cusid='$cusid'");
while ($row5 = mysql_fetch_array($query2)) {
echo '<tr height="20" width="1000">
<td height="10" colspan="10" bgcolor="#F3F3F3"><h2>Payment History of ' . $row5['cusname'] . ' (Credit)</h2></td>
</tr><tr height="20">
<td width="120" height="20" bgcolor="#FFFFFF"><h3>Date Added</h3></td>
<td width="120" bgcolor="#FFFFFF"><h3 align="center">Invoice Number</h3></td>
<td width="120" bgcolor="#FFFFFF"><h3 align="center">Invoice Amount</h3></td>
<td width="120" bgcolor="#FFFFFF"><h3 align="center">Payed Amount</h3></td>
<td width="120" bgcolor="#FFFFFF"><h3 align="center">Detail</h3></td>
<td width="120" bgcolor="#FFFFFF"><h3 align="center">Balance</h3></td>
</tr>';
}
//$query = mysql_query("SELECT * from payments where cusid ='$cusid' and ingrtype = '1' and payment_status = '1' and (date_added >= '$startDate' and date_added <= '$endDate') order by invoiceGRN_id") or die(mysql_error());
$query = mysql_query("SELECT * from payments where cusid ='$cusid' and ingrtype = '1' and payment_status = '1' and (date_added >= '$startDate' and date_added <= '$endDate') order by invoiceGRN_id") or die(mysql_error());
$lastinvoicenumber = null;
while ($row1 = mysql_fetch_array($query)) {
$invoiceAmount = $row1['subtotal'];
$payedAmount = $row1['payment'];
$invoicenumber = $row1['invoiceGRN_id'];
$invoicetotal = 0;
//$balanceAmount = $invoiceAmount - $payedAmount;
$balanceAmount = $invoiceAmount;
//diluk
$queryinv = mysql_query("SELECT invoice_subtotal from invoice where invoice_number ='$invoicenumber' limit 1") or die(mysql_error());
//diluk
while ($rowinv = mysql_fetch_array($queryinv)) {
$invoicetotal = $rowinv['invoice_subtotal'];
}
echo '<tr height="20">
<td width="100" align="left" bgcolor="#FFFFFF">' . $row1['date_added'] . '</td>';
if($lastinvoicenumber!=$invoicenumber){
echo '<td width="100" height="20" bgcolor="#FFFFFF">' . $row1['invoiceGRN_id'] . '</td>';
echo '<td width="100" align="right" bgcolor="#FFFFFF">' . $invoicetotal . '</td>';
}else{
echo '<td width="100" height="20" bgcolor="#FFFFFF"></td>';
echo '<td width="100" align="right" bgcolor="#FFFFFF"></td>';
}
echo '<td width="100" align="right" bgcolor="#FFFFFF">' . $row1['payment'] . '</td>';
$invId = $row1['invoiceGRN_id'];
if ($row1['paymentType'] == "Cheque") {
$query3 = mysql_query("select * from cheque where invoiceno='$invId'");
if ($row4 = mysql_fetch_array($query3)) {
echo '<td width="100" align="left" bgcolor="#FFFFFF">Cheque (' . $row4['number'] . ')'. $row1['date_added'] .'</td>';
}else{
echo '<td width="100" align="left" bgcolor="#FFFFFF">Cheque -' . $row1['date_added'] .'</td>';
}
} else {
echo '<td width="100" align="left" bgcolor="#FFFFFF">' . $row1['paymentType'] . '</td>';
}
echo '<td width="100" align="right" bgcolor="#FFFFFF">' . $balanceAmount . '</td>
</tr>';
$lastinvoicenumber = $invoicenumber;
}
echo '<tr height="20" width="1000">
<td height="10" colspan="10" bgcolor="#F3F3F3"><h2></h2></td></tr>';
$queryx = mysql_query("SELECT * from invoice where customer_id ='$cusid' and payment_type !='Credit' group by invoice_number order by invoice_date") or die(mysql_error());
while ($rowx = mysql_fetch_array($queryx)) {
echo '<tr height="20">
<td width="100" align="left" bgcolor="#FFFFFF">' . $rowx['invoice_date'] . '</td>
<td width="100" height="20" bgcolor="#FFFFFF">' . $rowx['invoice_number'] . '</td>
<td width="100" height="20" bgcolor="#FFFFFF">' . $rowx['invoice_subtotal'] . '</td>
<td width="100" height="20" bgcolor="#FFFFFF">' . $rowx['invoice_subtotal'] . '</td>';
$invId1 = $rowx['invoice_number'];
if ($rowx['payment_type'] == "Cheque") {
$queryx1 = mysql_query("select * from cheque where invoiceno='$invId1'");
if ($rowx2 = mysql_fetch_array($queryx1)) {
echo '<td width="100" align="left" bgcolor="#FFFFFF">Cheque (' . $rowx2['number'] . ')</td>';
}
} else {
echo '<td width="100" align="left" bgcolor="#FFFFFF">' . $rowx['payment_type'] . '</td>';
}
echo '<td width="100" align="right" bgcolor="#FFFFFF">0</td>
</tr>';
}
?>
</table>
There are 2 things you have to consider:
1. table-layout: fixed; this for table, and
2. word-wrap: break-word; to td itself.
For detailed see this question: How to force table cell <td> content to wrap?
I have also faced the same problem, just add \n to the end of every <tr> tag like this
echo "<tr><td></td><td></td></tr> \n"
you can check
echo '<td width="100" align="left" bgcolor="#FFFFFF"><div style="width:200px; word-wrap: break-word;overflow: auto;">Cheque (' . $row4['number'] . ')'. $row1['date_added'] .'</div></td>';
I solved the isue by making the table's "line-height" attribute to 20px like below,
<table cellspacing="1" width="900" cellpadding="3" bgcolor="#CCCCCC" style="line-height:20px;margin-left: auto;margin-right: auto">

trying to select a certain category from database

im a real newbie when it comes to sql but im trying to pick up the pieces of my friends site... It all seems to be working fine apart from the left hand navigation to certain categories.
This is the site: http://tyresinwigan.co.uk/new/
The individual manufacturers should point to each manufacturer direct but they seem to be listing the results for all manufacturers.
Here is the code from the search.php:
<?php
require_once('const.php');
$link = dbConnect();
$manufacturer_id = 0;
$name = '';
if (isset($_GET['make']) && is_numeric($_GET['make'])) {
$manufacturer_id = (int) $_GET['make'];
}
$query = "SELECT manufacturer_name FROM manufacturer_tbl WHERE manufacturer_id = $manufacturer_id";
$result = false;
$result = #mysql_query($query, $link);
if (($result) && (#mysql_num_rows($result) > 0)) {
$row = #mysql_fetch_array($result, MYSQL_ASSOC);
$name = stripslashes($row['manufacturer_name']);
}
$query = "SELECT *,
v.vehicle_id AS vehicle_id_alias
FROM vehicle_tbl AS v
LEFT JOIN image_tbl AS i ON v.vehicle_id = i.vehicle_id
GROUP BY v.vehicle_id
HAVING v.manufacturer_id = $manufacturer_id";
$offers = false;
$offers = #mysql_query($query, $link);
$items = 0;
if ($offers) $items = mysql_num_rows($offers);
function nextOffer() {
global $offers;
global $items;
$items --;
if ($offers && ($row = mysql_fetch_array($offers))) {
if (! isset($row['image_name'])) { // no image
$image = 'images/noimagesml.jpg';
} else {
$image = 'images/vehicles/sml/'.stripslashes($row['image_name']);
}
$title = stripslashes($row['manufacturer_name']).' '.stripslashes($row ['vehicle_model']);
$price = number_format((float) $row['vehicle_price_pcm'], 2);
$id = (int) $row['vehicle_id_alias'];
echo '<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="contenthead"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="11" height="40" align="left" valign="top"><img src="images/featre_left_hd.gif" width="11" height="23"></td>
<td width="100%" align="left" valign="middle" class="contenthead">'.$title.'</td>
<td width="11" height="40" align="right" valign="top"><img src="images/featre_rght_hd.gif" width="11" height="23"></td>
</tr>
</table></td>
</tr>
<tr>
<td class="contentpane"><table width="100%" border="0" cellspacing="5" cellpadding="0">
<tr>
<td align="center" valign="middle"><img src="'.$image.'" width="100" height="58" class="bordered" alt="'.$title.'"></td>
</tr>
<tr>
<td align="center" valign="top" class="princing">from just &pound'.$price.' pcm</td>
</tr>
<tr>
<td align="right" valign="middle"><img src="images/more_butt.gif" width="54" height="20" border="0"></td>
</tr>
</table></td>
</tr>
</table>';
} else {
echo ' ';
}
}
?>
Change:
$query = "SELECT * FROM vehicle_tbl LEFT JOIN image_tbl ON vehicle_tbl.vehicle_id = image_tbl.vehicle_id
WHERE vehicle_tbl.manufacturer_id = $manufacturer_id
GROUP BY vehicle_tbl.vehicle_id";
to:
$query = "SELECT * FROM vehicle_tbl LEFT JOIN image_tbl ON vehicle_tbl.vehicle_id = image_tbl.vehicle_id
GROUP BY vehicle_tbl.vehicle_id
HAVING vehicle_tbl.manufacturer_id = $manufacturer_id";
You are looking at the wrong query. The problem isnt in the left menu, but the query on the resulting page. You need to look at that one, and make sure it is formatted properly.

SQL Help - Newbie

I'm picking up the pieces for a friend. His website used to work and pull featured products from his database, but it doesn't seem to be working. Its just showing the Error!!
Any help would be appreciated.... I'm not really up to date with SQL.
Here's the code:
<?php
require_once('const.php');
$link = dbConnect();
$query = "SELECT *
FROM vehicle_tbl, manufacturer_tbl
LEFT JOIN image_tbl ON vehicle_tbl.vehicle_id = image_tbl.vehicle_id
WHERE vehicle_tbl.manufacturer_id = manufacturer_tbl.manufacturer_id AND
vehicle_tbl.vehicle_feature2 = '1'
GROUP BY vehicle_tbl.vehicle_id
ORDER BY RAND()
LIMIT 1";
$result = false;
$result = #mysql_query($query, $link);
$fmain = false;
if (($result) && (#mysql_num_rows($result) > 0)) {
$fmain = #mysql_fetch_array($result, MYSQL_ASSOC);
#mysql_free_result($result);
}
$query = "SELECT *
FROM vehicle_tbl, manufacturer_tbl
LEFT JOIN image_tbl ON vehicle_tbl.vehicle_id = image_tbl.vehicle_id
WHERE vehicle_tbl.manufacturer_id = manufacturer_tbl.manufacturer_id AND
vehicle_tbl.vehicle_feature1 = '1'
GROUP BY vehicle_tbl.vehicle_id
ORDER BY RAND()
LIMIT 6";
$offers = false;
$offers = #mysql_query($query, $link);
function nextOffer() {
global $offers;
if ($offers && ($row = mysql_fetch_array($offers))) {
if (! isset($row['image_name'])) { // no image
$image = 'images/noimagesml.jpg';
} else {
$image = 'images/vehicles/sml/'.stripslashes($row['image_name']);
}
$title = stripslashes($row['manufacturer_name']).' '.stripslashes($row['vehicle_model']);
$price = number_format((float) $row['vehicle_price_pcm'], 2);
$id = (int) $row['vehicle_id'];
echo '<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="contenthead"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="11" height="40" align="left" valign="top"><img src="images/featre_left_hd.gif" width="11" height="23"></td>
<td width="100%" align="left" valign="middle" class="contenthead">'.$title.'</td>
<td width="11" height="40" align="right" valign="top"><img src="images/featre_rght_hd.gif" width="11" height="23"></td>
</tr>
</table></td>
</tr>
<tr>
<td class="contentpane"><table width="100%" border="0" cellspacing="5" cellpadding="0">
<tr>
<td align="center" valign="middle"><img src="'.$image.'" width="100" height="58" class="bordered" alt="'.$title.'"></td>
</tr>
<tr>
<td align="center" valign="top" class="princing">from just &pound'.$price.' pcm</td>
</tr>
<tr>
<td align="right" valign="middle"><img src="images/more_butt.gif" width="54" height="20" border="0"></td>
</tr>
</table></td>
</tr>
</table>';
} else {
echo 'Error!!';
}
}
?>
Display mysql errors like this:
mysql_query($query, $link) or die(__FILE__ . ' Line ' . __LINE__ . ': ' . mysql_error());
This should help you debug.
P.S. the mysql_* functions are deprecated - http://php.net/manual/en/mysqlinfo.api.choosing.php

Displaying received data from a SQL Database in a list item

Old ASP developer migrating to PHP. I writ a PHP script to retrieve entries from an MS SQL Database and display. Looks like this:
<?php
$query = "SELECT DateUploaded, Title ";
$query .= "FROM TableName ";
$result = mssql_query($query);
$numRows = mssql_num_rows($result);
echo "<h1>" . $numRows . " Row" . ($numRows == 1 ? "" : "s") . " Returned </h1>";
while($row = mssql_fetch_array($result))
{
echo "<li>" . $row["DateUploaded"] . $row["Title"] . "</li>";
}
?>
Now when I want to get it to display echoing it just on the page works fine. Using this section of code:
while($row = mssql_fetch_array($result))
{
echo "<li>" . $row["DateUploaded"] . $row["Title"] . "</li>";
}
However when I try and put it into a table Ive created to display it it doesn't seem to work, although I've read a few tutorials and feel it should, it is also similar to a technique I used to use in ASP.
Looks like this:
<TABLE cellSpacing=1 cellPadding=2 align=center bgColor=#aaaaaa border=0 width="100%" class="logintbl">
<TR>
<TD bgColor=whitesmoke colSpan=0><B>News</B></td>
</tr>
<tr>
<td bgColor=#ffffff>
<table align="center" cellSpacing=0 cellPadding=2 border="0" width="100%">
<tr>
<td align="center" valign="bottom"> <font color="#4d71a1"><b>Date Uploaded</b></font> </td>
<td align="center" valign="bottom"> <font color="#4d71a1"><b>News Title</b></font> </td>
<td align="center"></td>
</tr>
<tr bgcolor="#eeeeee">
<tr bgcolor="#ffffff">
<td align="center"><?php echo $row["DateUploaded"]; ?></td>
<td align="center"><?php echo $row["Title"]; ?></td>
<td align="center">
<img src="images/0013-pen.gif" width="16" height="16" alt="" border="0">
<a href="NewsManage.php?do=del&id=" return false;">
<img src="images/1001-cancel16.gif" width="16" height="16" alt="" border="0">
</a>
</td>
</tr>
<tr><td colspan="7"> </td></tr>
<tr>
<td colspan="7" align="center">
</td>
</tr>
</table>
</td>
</tr>
</table>
I'm probably doing it totally wrong, but could someone point me in the right direction please?
Put the row into echo inside your loop:
<?php
while($row = mssql_fetch_array($result))
{
echo '<tr bgcolor="#ffffff">
<td align="center">'.$row["DateUploaded"].'</td>
<td align="center">'.$row["Title"].'</td>
<td align="center">
<img src="images/0013-pen.gif" width="16" height="16" alt="" border="0">
<img src="images/1001-cancel16.gif" width="16" height="16" alt="" border="0">
</td>
</tr>';
}
?>
Start the while loop right before the row with the data,
and end it right after that.
<table align="center" cellSpacing=0 cellPadding=2 border="0" width="100%">
<!-- header row here -->
<?php
$alterColor = true;
while ($row = mssql_fetch_array($result)) { // start while
// alternating bg color for rows
$color = ($alterColor) ? "#fff" : "#eee";
$alterColor = !$alterColor;
?>
<tr bgcolor="<?php echo $color; ?>">
<td align="center"><?php echo $row["DateUploaded"]; ?></td>
<td align="center"><?php echo $row["Title"]; ?></td>
<td align="center">
<img src="images/0013-pen.gif" width="16" height="16" alt="" border="0">
<a href="NewsManage.php?do=del&id=" return false;">
<img src="images/1001-cancel16.gif" width="16" height="16" alt="" border="0">
</a>
</td>
</tr>
<?php } // end while ?>
</table>
PS One of these seems to be extra, are they there for alternating color or something like that:
<tr bgcolor="#eeeeee">
<tr bgcolor="#ffffff">
You should not really have a tr within a tr directly.

Categories