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@#2123 4";
$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($qu ery);
$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($r esult,$i,"area" );
$equiptype = mysql_result($r esult,$i,"equip type");
$equipname = mysql_result($r esult,$i,"equip name");
$motorsize = mysql_result($r esult,$i,"motor size");
$motorframe = mysql_result($r esult,$i,"motor frame");
$beltspec = mysql_result($r esult,$i,"belts pec");
$beltspeed = mysql_result($r esult,$i,"belts peed");
/* print even-numbered rows with a grey background,
odd-numbered with a white background */
if ($i%2 == 0) {
print "<tr bgcolor=lightgr ey>";
} else {
print "<tr>";
}
print "<td>$area</td>
<td>$equiptyp e</td>
<td>$equipnam e</td>
<td>$motorsiz e</td>
<td>$motorframe </td>
<td>$beltspec </td>
<td>$beltspee d</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($qu ery);
$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($r esult,$i,"area" );
$equiptype = mysql_result($r esult,$i,"equip type");
$equipname = mysql_result($r esult,$i,"equip name");
$motorsize = mysql_result($r esult,$i,"motor size");
$motorframe = mysql_result($r esult,$i,"motor frame");
$shakerstroke = mysql_result($r esult,$i,"shake rstroke");
$shaker_rpm = mysql_result($r esult,$i,"shake r_rpm");
/* print even-numbered rows with a grey background,
odd-numbered with a white background */
if ($i%2 == 0) {
print "<tr bgcolor=lightgr ey>";
} else {
print "<tr>";
}
print "<td>$area</td>
<td>$equiptyp e</td>
<td>$equipnam e</td>
<td>$motorsiz e</td>
<td>$motorframe </td>
<td>$shakerstro ke</td>
<td>$shaker_rpm </td>";
}
print "</table>";
// Close the database connection
mysql_close();
?> 3 1962
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("shakerst roke" => "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($co mmonFields,$var Fields[$equiptype]);
# This will set $fields to "field,field,fi eld,..."
$fields = implode(",",arr ay_keys($queryF ields));
# Build full query
$query = "SELECT $fields FROM $table ".
"WHERE 1=1 AND equiptype='$equ iptype'".
($area != "All" ? " AND area='$area'" : "");
$result = mysql_query($qu ery);
# Output table
echo "<table ...>";
# Header
echo "<tr>";
foreach ($queryFields as $field=>$title) {
echo "<th>$title </th>";
}
echo "</tr>";
# Rows
while ($row = mysql_fetch_ass oc($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@#2123 4"; $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($qu ery);
$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($r esult,$i,"area" ); $equiptype = mysql_result($r esult,$i,"equip type"); $equipname = mysql_result($r esult,$i,"equip name"); $motorsize = mysql_result($r esult,$i,"motor size"); $motorframe = mysql_result($r esult,$i,"motor frame"); $beltspec = mysql_result($r esult,$i,"belts pec"); $beltspeed = mysql_result($r esult,$i,"belts peed"); /* print even-numbered rows with a grey background, odd-numbered with a white background */ if ($i%2 == 0) { print "<tr bgcolor=lightgr ey>"; } else { print "<tr>"; } print "<td>$area</td> <td>$equiptyp e</td> <td>$equipnam e</td> <td>$motorsiz e</td> <td>$motorframe </td> <td>$beltspec </td> <td>$beltspee d</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($qu ery);
$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($r esult,$i,"area" ); $equiptype = mysql_result($r esult,$i,"equip type"); $equipname = mysql_result($r esult,$i,"equip name"); $motorsize = mysql_result($r esult,$i,"motor size"); $motorframe = mysql_result($r esult,$i,"motor frame"); $shakerstroke = mysql_result($r esult,$i,"shake rstroke"); $shaker_rpm = mysql_result($r esult,$i,"shake r_rpm"); /* print even-numbered rows with a grey background, odd-numbered with a white background */ if ($i%2 == 0) { print "<tr bgcolor=lightgr ey>"; } else { print "<tr>"; } print "<td>$area</td> <td>$equiptyp e</td> <td>$equipnam e</td> <td>$motorsiz e</td> <td>$motorframe </td> <td>$shakerstro ke</td> <td>$shaker_rpm </td>"; } print "</table>";
// Close the database connection mysql_close(); ?>
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. :-)
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.c om... $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 "; This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 think I need to put this application in the Start-up group and have the application handle A&A using the Integrated Security. My question is how do I accomplish using Windows Integrated Security for A&A into a Windows Forms application? The OS is...
|
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 table could in some cases have
10.000 records, and hase to be as fast as possible (Index).
Is it possible to have a integrated small MSSQL-Database and use SQL?
Or do i have to use a hashtable or a array and load it from a file at
startup, and save...
|
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. :)
|
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 the live server, it throws
errors and i've to set the "UserName" and "Password" for the directory Entry
to be able to enumerate the users !!, i don't know why this happen although
i'm using domain integrated authentication, and it was working fine...
|
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 to login again.
Any help?
| |
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 security info=False
and I have execute sp_grantlogin 'ServerName\ASPNET' in Sql Query Analyzer
But when I execute my web application, it result an error at line:
|
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 some
experience with Java and LAMP (Linux/Apache/MySQL/PHP) but don't
consider me one of those boring OS advocates please. ;-)
I also have done a little bit with Visual Basic (and GwBasic in a long
forgotten past) and nowadays my job involves...
|
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 database. Say if I have 10 apps,
I'd need 10 logins, one login for each DB. Now throw in the windows
integrated security, I need 10 windows account. However, in order to run an
ASP.NET app under a certain identity, it has to have its own application...
|
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 the the reports "integrated security" from TRUE to
FALSE via the "Set Location" dialog in the report designer with no
success. It is not intuitive (at least not to me.)
I get the following error:
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |