I have looked through the forums for four hours now, since my search didn't seem to answer my question. (There's alot of good stuff here!) So here goes:
I have a table, which I am trying to let users select the order they want their search results returned in. (See code at bottom) It returns the correct record-set, but doesn't seem to be sorting at all. In fact, the records where imported into the mySQL table already ordered by incident_num. What I am trying to do is pass the ORDER BY as a variable from a drop-down box on a form on the previous page. Users can type in an incident_num, select plant_name from a drop-down box, and type in a supplier_number and get the subset that they want. The only thing that isn't working is passing the sort order. Can anyone assist me with this?
Thanks, here's the code I'm using so far:
<?php
include ("test.inc");
$title = "MPG SIR Search Results";
html_begin ($title, $title);
# Connect to Database
test_db_connect()
or die("Please check SIR server status");
mysql_select_db (sirlogid);
if ($incident_num =="")
{$incident_num='%';}
if ($plant =="")
{$plant='%';}
if ($supp_num =="")
{$supp_num='%';}
if ($order =="")
{$order='incident_number';}
$result = mysql_query ("SELECT incident_num, plant_name, supplier_number, date_open FROM sirlogid
WHERE incident_num LIKE '$incident_num%'
AND plant_name LIKE '$plant%'
ORDER by '$order%' ");
print ("<table border=1> \n");
print("<tr><th>Incident Number</th><th>Plant</th><th>Supplier Number</th><th>Date Opened</th></tr>\n");
if ($row = mysql_fetch_array($result)) {
do {
print ("<TR><TD bgcolor=gray align=right><font color=white>\n");
print $row["incident_num"];
print ("</font></TD><TD>\n");
print $row["plant_name"];
print ("</TD><TD>\n");
print $row["supplier_number"];
print ("</TD><TD>\n");
print $row["date_open"];
print ("</TD></TR>\n");
} while($row = mysql_fetch_array($result));
print ("</table> \n");
} else {print "Sorry, no matching records found.";}
html_footer ();
?>
== I have also tried SELECT * FROM ... and using
if ($order =="")
{$order='%';}
I have a table, which I am trying to let users select the order they want their search results returned in. (See code at bottom) It returns the correct record-set, but doesn't seem to be sorting at all. In fact, the records where imported into the mySQL table already ordered by incident_num. What I am trying to do is pass the ORDER BY as a variable from a drop-down box on a form on the previous page. Users can type in an incident_num, select plant_name from a drop-down box, and type in a supplier_number and get the subset that they want. The only thing that isn't working is passing the sort order. Can anyone assist me with this?
Thanks, here's the code I'm using so far:
<?php
include ("test.inc");
$title = "MPG SIR Search Results";
html_begin ($title, $title);
# Connect to Database
test_db_connect()
or die("Please check SIR server status");
mysql_select_db (sirlogid);
if ($incident_num =="")
{$incident_num='%';}
if ($plant =="")
{$plant='%';}
if ($supp_num =="")
{$supp_num='%';}
if ($order =="")
{$order='incident_number';}
$result = mysql_query ("SELECT incident_num, plant_name, supplier_number, date_open FROM sirlogid
WHERE incident_num LIKE '$incident_num%'
AND plant_name LIKE '$plant%'
ORDER by '$order%' ");
print ("<table border=1> \n");
print("<tr><th>Incident Number</th><th>Plant</th><th>Supplier Number</th><th>Date Opened</th></tr>\n");
if ($row = mysql_fetch_array($result)) {
do {
print ("<TR><TD bgcolor=gray align=right><font color=white>\n");
print $row["incident_num"];
print ("</font></TD><TD>\n");
print $row["plant_name"];
print ("</TD><TD>\n");
print $row["supplier_number"];
print ("</TD><TD>\n");
print $row["date_open"];
print ("</TD></TR>\n");
} while($row = mysql_fetch_array($result));
print ("</table> \n");
} else {print "Sorry, no matching records found.";}
html_footer ();
?>
== I have also tried SELECT * FROM ... and using
if ($order =="")
{$order='%';}