Varma69 Posted April 20, 2009 Share Posted April 20, 2009 Hi am havign a problem where I want to return results based ona combo box where the values are generated for a table and when you make a selection it take that value and returns all results based on the value selected. here is the code. combo select <code> <form action="RecordView.php" method="POST"> <?php require ("dbconnect.php"); $query2 = "SELECT * FROM incidents"; $result = mysql_query($query2) or die (mysql_error()); ?> Please select where you would like to go:<br/> <select name="cmbper" id="cmbper"> <?php While($row=mysql_fetch_assoc($result)){ printf("<option value = %s> %s </option>", $row['inc_driverpermit'], $row['inc_driverpermit']); }//end..while ?> <input type="Submit" name="Submit" value="GO"> </form> </code> Record View <code> <?php require ("dbconnect.php"); // retrieve all the rows from the database $cmbper=$_POST['cmbper']; echo $cmbper; $query ="SELECT * FROM incidents WHERE inc_driverpermit=".$cmbper.""; //query set up $results = mysql_query($query,$db) or die (mysql_error()); //executes query if(mysql_num_rows($results) > 0) { ?> <table border="1"> <tr> <td>Location</td> <td>Date</td> <td>Police Badge</td> <td>Vehicle Number</td> <td>Vehicle Make</td> <td>Vehicle Model</td> <td>Vehicle Colour</td> <td>Driver Frist Name</td> <td>Driver Middle Name</td> <td>Driver Last Name</td> <td>Driver Permit</td> <td>Driver Permit Expiry</td> <td>Insurer</td> <td>Insurance Expiry</td> <td>Notes</td> <td>Type</td><!--table data last column--> </tr> <?php // print out the results while( $row = mysql_fetch_assoc( $results ) ) { // print out the info printf("<tr> <td>%s</td> <td>%s</td> <td>%s</td> <td>%s</td> <td>%s</td> <td>%s</td> <td>%s</td> <td>%s</td> <td>%s</td> <td>%s</td> <td>%s</td> <td>%s</td> <td>%s</td> <td>%s</td> <td>%s</td> <td>%s</td> </tr>", $row["inc_location"], $row["inc_datetime"], $row["inc_policebadge"], $row["inc_vehiclenum"], $row["inc_vehiclemake"], $row["inc_vehiclemodel"], $row["inc_vehiclecolour"], $row["inc_driverfirstname"], $row["inc_drivermiddlename"], $row["inc_driversurname"], $row["inc_driverpermit"], $row["inc_driverpermitexpiry"], $row["inc_insurer"], $row["inc_insuranceexpiry"], $row["inc_notes"], $row["inc_type"]); } } ?> </code> Link to comment https://forums.phpfreaks.com/topic/154938-help-with-a-database-query/ Share on other sites More sharing options...
premiso Posted April 20, 2009 Share Posted April 20, 2009 So...is it not working or what? And please change <code> to Link to comment https://forums.phpfreaks.com/topic/154938-help-with-a-database-query/#findComment-814980 Share on other sites More sharing options...
Varma69 Posted April 20, 2009 Author Share Posted April 20, 2009 sorry about the incorrect code tags. It not working......I just using the an actual value in the sql statement and it says Unknown column 'permit number here' in 'where clause' Link to comment https://forums.phpfreaks.com/topic/154938-help-with-a-database-query/#findComment-814998 Share on other sites More sharing options...
Mchl Posted April 20, 2009 Share Posted April 20, 2009 Put quotes around around any variables that are strings. $query ="SELECT * FROM incidents WHERE inc_driverpermit='$cmbper'"; //query set up Link to comment https://forums.phpfreaks.com/topic/154938-help-with-a-database-query/#findComment-815008 Share on other sites More sharing options...
Varma69 Posted April 20, 2009 Author Share Posted April 20, 2009 Okay so i tried just hard coding the variable in the query $query ="SELECT * FROM incidents WHERE inc_driverpermit='.qw.'"; //query set up And got nothing but a a blank page being displayed Link to comment https://forums.phpfreaks.com/topic/154938-help-with-a-database-query/#findComment-815013 Share on other sites More sharing options...
Mchl Posted April 20, 2009 Share Posted April 20, 2009 Do you have any entries that have .qw. in inc_driverpermit? Link to comment https://forums.phpfreaks.com/topic/154938-help-with-a-database-query/#findComment-815015 Share on other sites More sharing options...
Varma69 Posted April 20, 2009 Author Share Posted April 20, 2009 yep Link to comment https://forums.phpfreaks.com/topic/154938-help-with-a-database-query/#findComment-815017 Share on other sites More sharing options...
Mchl Posted April 20, 2009 Share Posted April 20, 2009 Run this query in phpMyAdmin, MySQL console or whatever you use, and see if it returns results. Link to comment https://forums.phpfreaks.com/topic/154938-help-with-a-database-query/#findComment-815029 Share on other sites More sharing options...
Varma69 Posted April 20, 2009 Author Share Posted April 20, 2009 Mchl thanks man it was the string quotes I got it to work. I changed the combo box to a normal text box also. Thanks a lot Link to comment https://forums.phpfreaks.com/topic/154938-help-with-a-database-query/#findComment-815079 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.