php and tables
| From: | b | Date: | Wed, 28 Nov 2001 07:04:35 +0000 |
| Subject: | php and tables | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-75850@lists.php.net to get a copy of this message | ||
i have created a program that allows users to make custom sql queries to
a mysql db and display the output to the browser.
the program works as desired but what i would like to do is display the
data in a table.
as there can be up to 4 columns with up to 13 different titles, i cannot
hard code this info in.
i would like to have the title used in the query to the be the title of
the table with the relevant data
below in an easily read format.
here is a sample of my code can any one help???
function db_search(){
global
$search,$search0,$search1,$search2,$search3,$where,$boulean,$variable;
// from the subnet and the host make the ip address
$ip_addr = $ip . $address;
// check to see if the variable is empty and discard other wise add the
contents to $field
if(!empty($search)) {
$field .= "$search, "; }
if(!empty($search0)) {
$field .= "$search0, "; }
if(!empty($search1)) {
$field .= "$search1, "; }
if(!empty($search2)) {
$field .= "$search2, "; }
if(!empty($where)) {
$field1 .= "$where "; }
if(!empty($search3)) {
$field1 .= "$search3 "; }
if(!empty($boulean)) {
$field1 .= "$boulean "; }
if(!empty($variable)) {
$field1 .= "'$variable' "; }
//strip the last character off of $field
$field = substr($field,0,strlen($field)-2);
//$field1 = substr($field1,0,strlen($field1)-2);
// prepare the query
$sql = "select $field from machine $field1 ";
print $field;
// action the query
$result = mysql_query($sql)
or die ("Cannot do query, query = $sql");
// Printing results in HTML
print "<table>\n";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC))
{
print "\t<tr>\n";
foreach ($line as $col_value) {
print "\t\t<td>$col_value</td>\n";
}
print "\t</tr>\n";
}
print "<hr width='100%'>";
print "</table>\n";
print "<hr width='100%'>";
echo "\n\n<center>Your Job has Completed</center>\n\n\n<a
href=\"javascript:history.back();\">\n\n<center>Back</center></a>";
}