473,324 Members | 2,193 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Integrated Query Question

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();
?>
Dec 31 '05 #1
3 1935
If I understand correctly, you may have either 'conveyor' or 'shaker'
passed to the script, and depending on that value different columns
should be shown. If that's the case, I'd rather do it like this:

# Common to all queries fields

$commonFields = array("area" => "Area",
"equiptype" => "Equip Type",
"equipname" => "Equip Name",
"motorsize" => "Motor Size",
"motorframe" => "Motor Frame");

# Fields depending on a variable

$varFields = array("CONVEYOR" => array("beltspec" => "Belt Spec",
"beltspeed" => "Belt Speed"),
"SHAKER" => array("shakerstroke" => "Shaker Stroke",
"shaker_rpm" => "Shaker RPM"));

# Get vars

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

# Build query fields
# This will return an associative array of all fields needed

$queryFields = array_merge($commonFields,$varFields[$equiptype]);

# This will set $fields to "field,field,field,..."

$fields = implode(",",array_keys($queryFields));

# Build full query

$query = "SELECT $fields FROM $table ".
"WHERE 1=1 AND equiptype='$equiptype'".
($area != "All" ? " AND area='$area'" : "");
$result = mysql_query($query);

# Output table
echo "<table ...>";
# Header
echo "<tr>";
foreach ($queryFields as $field=>$title) {
echo "<th>$title</th>";
}
echo "</tr>";
# Rows
while ($row = mysql_fetch_assoc($result)) {
foreach ($queryFields as $field=>$title) {
echo "<td>{$row[$field]}</td>";
}
}
echo "</table ...>";
In case you get more equipment types, you can simply update $varFields
array and leave everything else unchanged - it'll still work :)
The idea is that since you have common and uncommon fields, it's easier
to describe them separately. You can then "choose" which uncommon fields
you want retrieved and merge them with common fields. Having that, you
can use loops to output a table. :)

cover wrote:
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();
?>

Dec 31 '05 #2
On Sat, 31 Dec 2005 04:07:54 GMT, L?pher Cypher
<lu***********@verizon.net> wrote:
If I understand correctly, you may have either 'conveyor' or 'shaker'
passed to the script, and depending on that value different columns
should be shown. If that's the case, I'd rather do it like this:


thanks very much - works great. :-)
Jan 2 '06 #3
if it's of any interest, you can get rid of the WHERE 1=1
it does nothing and is not needed.

"cover" <co****************@yahoo.com> wrote in message
news:0f********************************@4ax.com...
$query =
"SELECT area, equiptype, equipname, motorsize, motorframe,
beltspec, beltspeed
FROM $table
WHERE 1 = 1 ";
$query =
"SELECT area, equiptype, equipname, motorsize, motorframe,
shakerstroke, shaker_rpm
FROM $table
WHERE 1 = 1 ";

Jan 3 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Greg Busby | last post by:
I have a client who wants to use Windows Integrated Security for authentication and authorization to use this application. They also want this application to run as soon as Windows comes up. So, I...
2
by: Andrih | last post by:
Our .net Application requires a table with two columns. Both columns are text of 40 chars. The table has to be static, after reseting the application, all records must still be available. The...
4
by: Andrew | last post by:
Hey all, I would like to preface my question by stating I am still learning ASP.net and while I am confident in the basics and foundation, the more advanced stuff is still a challenge. Ok....
1
by: Mohamed Zaki | last post by:
Dear All, I've develop asp.net solution to enumerate the domain users, this solution using Windows Integrated Authentication, however on the staging server it's working fine, but when moving the...
3
by: Patrick.O.Ige | last post by:
Hi folks, How can i pass credentials to windows integrated authentication. I want to use my credentials from windows authentication and pass it on to different asp.net and asp pages without having...
4
by: ad | last post by:
I want to set integrated Secure in my connect string to SQL Server I set the connect string as: workstation id=xxx;packet size=4096;integrated security=SSPI;initial catalog=vvv;persist...
2
by: Amedee Van Gasse | last post by:
Hello, Since it is the first time I'm posting in these groups, I believe a (short) introduction of myself would not be a bad thing. I am mainly a support engineer, not a programmer. I do have...
2
by: Bob | last post by:
I would like to use integrated security for DB connection for my ASP.NET applications. Since these apps have different databases (SQL Server), I want each app to be able to access its own...
7
by: Henry | last post by:
I am writing a Windows forms VB.Net/MS SQL application via VS 2003 that utilizes Crystal Reports. I want to be able to dynamically set the report data source at run time. I'm trying to change...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.