NoDoze Posted March 16, 2007 Share Posted March 16, 2007 Is it possible? Can you provide me an example of code? Thanks... Quote Link to comment Share on other sites More sharing options...
tauchai83 Posted March 16, 2007 Share Posted March 16, 2007 please be more detailed because I could not understand what do you want. You mean multiple query using pull down menu? example, user select pull down menu A, then the value is passed and used for the second pull down menu B. Do you mean like this? if yes, it is possible. Quote Link to comment Share on other sites More sharing options...
NoDoze Posted March 22, 2007 Author Share Posted March 22, 2007 I mean.... Sort by 'insert pull down menu here' So that users could choose what to sort the table by... I'm pretty sure it's possible cause I've seen it before... But I need an example of code. Thanks. Quote Link to comment Share on other sites More sharing options...
UTAlan Posted March 22, 2007 Share Posted March 22, 2007 <select name="sortBy"> <option value="name">Name</option> <option value="date">Date</option> </select> Submit that form and on the resulting page, use the following form: $query = "SELECT * FROM table WHERE field1 = 'value'"; if(isset($_POST['sortBy'])) { $query .= " ORDER BY " . $_POST['sortBy']; } $result = mysql_query($query); Quote Link to comment Share on other sites More sharing options...
NoDoze Posted March 22, 2007 Author Share Posted March 22, 2007 Hmmm...looks straight forward, but for some reason I can't get it to work...??? Here is my code: <tr class="table-header"> <td> <div align="right">Sort by: </div> </td> <td colspan="2" class="sortby"> <form action="viewall2-sort.php" method="post"> <div align="left"> <select name="sortBy" class="txtbox"> <option value="date">Initiation Date</option> <option value="project_number">Project Number</option> <option value="responsible_individual">Responsible Individual</option> <option value="off_project_name">Official Project Name</option> <option value="inv_project_des">Invoice Job Description</option> <option value="serv_project_name">Project Folder Name</option> <option value="region">Region</option> <option value="clientend">End Client</option> <option value="solesource">Sole Source</option> </select> </div> </form> </td> <td align="left"><input name="Submit" type="submit"></td> <td> <?php $query = "SELECT * FROM pil WHERE field1 = 'value'"; if(isset($_POST['sortBy'])) { $query .= " ORDER BY " . $_POST['sortBy']; } $result = mysql_query($query); ?> </td> <td> </td> <td> </td> <td> </td> <td> </td> Quote Link to comment Share on other sites More sharing options...
NoDoze Posted August 22, 2007 Author Share Posted August 22, 2007 I'm revisiting this.... Can someone help me? Thanks... Quote Link to comment Share on other sites More sharing options...
lemmin Posted August 22, 2007 Share Posted August 22, 2007 What about your code doesn't work? Is there an error message? Is nothing returned? Is it in the wrong order? Quote Link to comment Share on other sites More sharing options...
NoDoze Posted August 22, 2007 Author Share Posted August 22, 2007 <?php include 'config.php'; include 'opendb.php'; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title></title> <link href="../css/index2.css" rel="stylesheet" type="text/css" /> <link href="../css/viewall.css" rel="stylesheet" type="text/css"> <style type="text/css"> <!-- .body-base { text-decoration: none; position: relative; top: 140px; left: 25px; } .sort { font-family: Arial; font-size: 10pt; text-decoration: none; color: #FFFFFF; position: absolute; left: 0px; top: -25px; } .sort-pull { text-decoration: none; background-color: #0554A3; margin-top: 19px; } --> </style> </head> <body> <div class="body-base"> <table border="0"> <tr> <td> <div align="right">Sort by: </div> </td> <td colspan="2" class="sortby"> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <div align="left"> <select name="sortBy" class="txtbox"> <option value="date">Initiation Date</option> <option value="project_number">Project Number</option> <option value="responsible_individual">Responsible Individual</option> <option value="off_project_name">Official Project Name</option> <option value="inv_project_des">Invoice Job Description</option> <option value="serv_project_name">Project Folder Name</option> <option value="region">Region</option> <option value="clientend">End Client</option> <option value="solesource">Sole Source</option> </select> </div> </form> </td> <td align="left"><input name="Submit" type="submit"></td> <td> <?php $query = "SELECT * FROM projects WHERE field1 = 'value'"; if(isset($_POST['sortBy'])) { $query .= " ORDER BY " . $_POST['sortBy']; } $result = mysql_query($query); ?> </td> </tr> </table> </div> </body> </html> This is the complete code.... Nothing shows up when submit is clicked. Quote Link to comment Share on other sites More sharing options...
Jessica Posted August 22, 2007 Share Posted August 22, 2007 Because you're not doing anything with the result. You can't just copy and paste without understanding what you're doing You didn't change the code given to make it work with your code. Does your table actually have a field1 that will equal 'value'? Probably not... There are tons of tutorials on PHP/Mysql so I think you need to read one to find out how to use the $result you got and make it display info. Quote Link to comment Share on other sites More sharing options...
NoDoze Posted August 22, 2007 Author Share Posted August 22, 2007 Ok this was a bit of a rush job, so the code is probably ot it's best.... <?php include 'config.php'; include 'opendb.php'; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title></title> <link href="../css/index2.css" rel="stylesheet" type="text/css" /> <link href="../css/viewall.css" rel="stylesheet" type="text/css"> <style type="text/css"> <!-- .body-base { text-decoration: none; position: relative; top: 140px; left: 25px; } .sort { font-family: Arial; font-size: 10pt; text-decoration: none; color: #FFFFFF; position: absolute; left: 0px; top: -25px; } .sort-pull { text-decoration: none; background-color: #0554A3; margin-top: 19px; } --> </style> </head> <body> <div class="body-base"> <table border="0"> <tr> <td> <div align="right">Sort by: </div> </td> <td colspan="2" class="sortby"> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <div align="left"> <select name="sortBy" class="txtbox"> <option value="date">Initiation Date</option> <option value="project_number">Project Number</option> </select> </div> </form> </td> <td align="left"><input name="Submit" type="submit"></td> <td> <?php $query = "SELECT * FROM projects WHERE field1 = 'value'"; if(isset($_POST['sortBy'])) { $query .= " ORDER BY " . $_POST['sortBy']; } $result = mysql_query($query); $num=mysql_numrows($result); mysql_close(); echo "<br><br><br><b><center>Database Output</center></b><br><br>"; $i=0; while ($i < $num) { $date=mysql_result($result,$i,"date"); $project_number=mysql_result($result,$i,"project_number"); echo "<b>$date</b><br>$project_number<hr><br>"; $i++; } ?> </td> </tr> </table> </div> </body> </html> Still get nothing.... Quote Link to comment Share on other sites More sharing options...
lemmin Posted August 22, 2007 Share Posted August 22, 2007 You have mysql_close() before your output functions. I would suggest using "or die(mysql_error());" at the end of all your mysql statements, it will make it a lot easier to debug. Quote Link to comment Share on other sites More sharing options...
bboundy Posted August 23, 2007 Share Posted August 23, 2007 Why have you ended the form before the submit button? ??? And what is the txtbox attribute for? (Or the sortby attribute on the table for that matter?) <select name="sortBy"> <option value="date">Initiation Date</option> <option value="project_number">Project Number</option> </select> <input name="Submit" type="submit"> </form> (removed the formatting tags cause they aren't relevant, you should be able to figure out where they go) And Jesirose is right. You need to actually change the mysql statement to fit your database. Quote Link to comment Share on other sites More sharing options...
lemmin Posted August 23, 2007 Share Posted August 23, 2007 Those (txtbox and sortby) are likely css classes that are in a different file that he links to with the link object. Quote Link to comment Share on other sites More sharing options...
NoDoze Posted September 12, 2007 Author Share Posted September 12, 2007 Yes, those are css.... Well, I made the changes, but still get nothing.... <?php include 'config.php'; include 'opendb.php'; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title></title> <link href="../css/index2.css" rel="stylesheet" type="text/css" /> <link href="../css/viewall.css" rel="stylesheet" type="text/css"> <style type="text/css"> <!-- .body-base { text-decoration: none; position: relative; top: 140px; left: 25px; } .sort { font-family: Arial; font-size: 10pt; text-decoration: none; color: #FFFFFF; position: absolute; left: 0px; top: -25px; } .sort-pull { text-decoration: none; background-color: #0554A3; margin-top: 19px; } --> </style> </head> <body> <div class="body-base"> <table border="0"> <tr> <td> <div align="right">Sort by: </div> </td> <td colspan="2" class="sortby"> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <div align="left"> <select name="sortBy" class="txtbox"> <option value="date">Initiation Date</option> <option value="project_number">Project Number</option> </select> </div> </form> </td> <td align="left"><input name="Submit" type="submit"></td> <td> <?php $query = "SELECT * FROM projects WHERE field1 = 'value'" or die(mysql_error()); if(isset($_POST['sortBy'])) { $query .= " ORDER BY " . $_POST['sortBy']; } $result = mysql_query($query); $num=mysql_numrows($result); echo "<br><br><br><b><center>Database Output</center></b><br><br>"; $i=0; while ($i < $num) { $date=mysql_result($result,$i,"date"); $project_number=mysql_result($result,$i,"project_number"); echo "<b>$date</b><br>$project_number<hr><br>"; $i++; } mysql_close(); ?> </td> </tr> </table> </div> </body> </html> Please help... Thanks! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.