Looping mysql php
Posted: Mon Sep 24, 2007 8:37 pm
Hi
I am wondering if there is some way I could list the CategoryID and the heading I wanted and could get it to loop trough the mysql query and html table, so I don’t have to do the query and html table evert time
Connect.php
Networking.php
I am wondering if there is some way I could list the CategoryID and the heading I wanted and could get it to loop trough the mysql query and html table, so I don’t have to do the query and html table evert time
Connect.php
Code: Select all
<?php
$location = "localhost";
$username = "computer_test";
$password = "test1";
$database = "computer_price";
$connection = mysql_connect("$location","$username","$password");
if (!$connection) die ("Could not connect MySQL");
mysql_select_db($database,$connection) or die ("Could not open database");
$profit = "1.3";
?>Networking.php
Code: Select all
<?PHP
include("Connect.php");
//Defining HTML table
$query="SELECT p.PartNumber, p.Description, round((p.IncTax*($profit)),1) AS Price FROM `price list` p WHERE p.CategoryID = '3800' order by PartNumber";
$data_resource=mysql_query($query,$connection);
//Defining HTML table
Echo '<p align="center"><font size="6" color="#4F55A6" face="Verdana">Networking (Wired)</font></p>';
$rowcount = 0;
$table="<table align=center cellspacing=0 cellpadding=0 width=400>";
while ($row = mysql_fetch_array($data_resource)) {
$rowcount++;
$table.=sprintf('<tr bgcolor="%s"><td>'.$row['Description'].'</td>', $rowcolor);
$table.=sprintf('<td ALIGN="RIGHT"> $'.$row['Price'].'0</td></tr>', $rowcolor);
$rowcolor = $rowcount % 2 == 0 ? "#FFFFFF" : "#C4DAFA";
}
//Closing HTML table
$table.="</table>";
echo $table;
$query="SELECT p.PartNumber, p.Description, round((p.IncTax*($profit)),1) AS Price FROM `price list` p WHERE p.CategoryID = '3700' order by PartNumber";
$data_resource=mysql_query($query,$connection);
Echo '<p align="center"><font size="6" color="#4F55A6" face="Verdana">Networking (Wireless)</font></p>';
$rowcount = 0;
$table="<table align=center cellspacing=0 cellpadding=0 width=400>";
while ($row = mysql_fetch_array($data_resource)) {
$rowcount++;
$table.=sprintf('<tr bgcolor="%s"><td>'.$row['Description'].'</td>', $rowcolor);
$table.=sprintf('<td align="right"> $'.$row['Price'].'0</td></tr>', $rowcolor);
$rowcolor = $rowcount % 2 == 0 ? "#FFFFFF" : "#C4DAFA";
}
//Closing HTML table
$table.="</table>";
echo $table;
mysql_close();
?>