You are here: Integrated Query Question « All PHP « IT news, forums, messages
Integrated Query Question

Posted by cover on 12/31/05 05:24

I have a table with 50 fields that receive input depending on whether
that input came in from a 'shaker' form or a 'conveyor' form. Input
from the 'conveyor' form might populate 25 fields while input from the
'shaker' form will populate another 20-25 fields but not the same
fields (however there are about 10 common fields to both). I'd
thought about using two tables (one for 'conveyor' and the other for
'shaker') but thought I'd try just the single table for now.

My query question: My pull down allows for selection of various areas
and also what type of equipment; i.e. 'shaker' or 'conveyor'. I have
the code started within a single query to cover the 'conveyor' 25
specific fields of data if the user selected 'conveyor' on their query
but what about if they'd selected 'shaker'? How do I write that
particular portion of code to return those different 20-25 fields?
Almost one for 'else if' but I don't know that this would work either.
Seems as though I'm looking for a conditional or compound query.

thanks,
Chris

The following code passes variable data from two pull downs on another
form (area and equiptype) to what I hope will be a single integrated
form below. Again, conveyor code example follows with needed shaker
code I'd like to integrate into a single query below that if that's
possible: Would something like what follows work?
---------------------------------------------------------------------

$DBhost = "localhost";
$DBuser = "dobey";
$DBpass = "#321@#21234";
$DBname = "equipment";
$table = "equipment_tbl";

$area = $_POST['area'];
$equiptype = $_POST['equiptype'];

mysql_connect($DBhost, $DBuser, $DBpass) or die("Unable to connect to
host $DBhost");

mysql_select_db($DBname) or die("Unable to select database $DBname");

$query =
"SELECT area, equiptype, equipname, motorsize, motorframe,
beltspec, beltspeed
FROM $table
WHERE 1 = 1 ";
if($area != "All") $query .= "and area = '".$area."'";
if($equiptype != "CONVEYOR") $query .= "and equiptype =
"'.$equiptype."'";
$result = mysql_query($query);

$number = mysql_numrows($result);

print "<h2>There are $number CONVEYOR records in the Equipment
Database:</h2>
<table cellpadding=5>
<tr bgcolor=black>
<td><font color=white><b>area</b></td></font></td>
<td><font color=white><b>equip type</b></td></font></td>
<td><font color=white><b>equip name</b></td></font></td>
<td><font color=white><b>motor size</b></td></font></td>
<td><font color=white><b>motor frame</b></td></font></td>
<td><font color=white><b>belt spec</b></font></td>
<td><font color=white><b>belt speed</b></td></font></td>";
for($i=0; $i<$number; $i++) {
$area = mysql_result($result,$i,"area");
$equiptype = mysql_result($result,$i,"equiptype");
$equipname = mysql_result($result,$i,"equipname");
$motorsize = mysql_result($result,$i,"motorsize");
$motorframe = mysql_result($result,$i,"motorframe");
$beltspec = mysql_result($result,$i,"beltspec");
$beltspeed = mysql_result($result,$i,"beltspeed");
/* print even-numbered rows with a grey background,
odd-numbered with a white background */
if ($i%2 == 0) {
print "<tr bgcolor=lightgrey>";
} else {
print "<tr>";
}
print "<td>$area</td>
<td>$equiptype</td>
<td>$equipname</td>
<td>$motorsize</td>
<td>$motorframe</td>
<td>$beltspec</td>
<td>$beltspeed</td>";
}
print "</table>";

// OTHERWISE IF SHAKER HAS BEEN SELECTED:

$query =
"SELECT area, equiptype, equipname, motorsize, motorframe,
shakerstroke, shaker_rpm
FROM $table
WHERE 1 = 1 ";
if($area != "All") $query .= "and area = '".$area."'";
if($equiptype != "SHAKER") $query .= "and equiptype =
"'.$equiptype."'";
$result = mysql_query($query);

$number = mysql_numrows($result);

print "<h2>There are $number SHAKER records in the Equipment
Database:</h2>
<table cellpadding=5>
<tr bgcolor=black>
<td><font color=white><b>area</b></td></font></td>
<td><font color=white><b>equip type</b></td></font></td>
<td><font color=white><b>equip name</b></td></font></td>
<td><font color=white><b>motor size</b></td></font></td>
<td><font color=white><b>motor frame</b></td></font></td>
<td><font color=white><b>shaker stroke</b></font></td>
<td><font color=white><b>shaker RPM</b></td></font></td>";
for($i=0; $i<$number; $i++) {
$area = mysql_result($result,$i,"area");
$equiptype = mysql_result($result,$i,"equiptype");
$equipname = mysql_result($result,$i,"equipname");
$motorsize = mysql_result($result,$i,"motorsize");
$motorframe = mysql_result($result,$i,"motorframe");
$shakerstroke = mysql_result($result,$i,"shakerstroke");
$shaker_rpm = mysql_result($result,$i,"shaker_rpm");
/* print even-numbered rows with a grey background,
odd-numbered with a white background */
if ($i%2 == 0) {
print "<tr bgcolor=lightgrey>";
} else {
print "<tr>";
}
print "<td>$area</td>
<td>$equiptype</td>
<td>$equipname</td>
<td>$motorsize</td>
<td>$motorframe</td>
<td>$shakerstroke</td>
<td>$shaker_rpm</td>";
}
print "</table>";

// Close the database connection
mysql_close();
?>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация