phpstudent111 Posted March 27, 2009 Share Posted March 27, 2009 Hi Everyone, I have a resultset from mysql displayed on my front-end in table format. I have added two extra columns for an "Edit" and "Delete" button but am having trouble writing the functionality. Mainly, I need to store each cell from the resultset in it's own variable, so I can then pre-populate the "Edit" function with the appropriate variables, etc. Please let me know if that's not clear enough and please find my code below! Thanks for all of your help! $mymodel=$_POST['mymodel']; $mymanufacturer=$_POST['mymanufacturer']; $myyear=$_POST['myyear']; $mydoors=$_POST['mydoors']; $mypricemin=$_POST['mypricemin']; $mypricemax=$_POST['mypricemax']; $mycolor=$_POST['mycolor']; $myinteriorcolor=$_POST['myinteriorcolor']; $query='SELECT car.id , model.manufacturer , model.modelname , car.year , color.color_name , interior_color.interior_color , car.doors , car.retailprice , car.dealercost , transmission_type.transmission_type FROM car INNER JOIN model ON (car.model_id=model.id) INNER JOIN color ON (car.color_id=color.id) INNER JOIN interior_color ON (interior_color.id=car.interior_color_id) INNER JOIN transmission_type ON (car.transmission_type_id=transmission_type.id)'; //HERE $where = array(); if(!empty($_POST['mymodel'])) $where[] = sprintf("car.model_id='%s'",mysql_real_escape_string($_POST['mymodel'])); if(!empty($_POST['mymanufacturer'])) $where[] = sprintf("model.manufacturer_id='%s'",mysql_real_escape_string($_POST['mymanufacturer'])); if(!empty($_POST['myyear'])) $where[] = sprintf("car.year='%s'",mysql_real_escape_string($_POST['myyear'])); if(!empty($_POST['mydoors'])) $where[] = sprintf("car.doors='%s'",mysql_real_escape_string($_POST['mydoors'])); if(!empty($_POST['mypricemin'])) $where[] = sprintf("car.retailprice>='%d'",mysql_real_escape_string($_POST['mypricemin'])); if(!empty($_POST['mypricemax'])) $where[] = sprintf("car.retailprice<='%d'",mysql_real_escape_string($_POST['mypricemax'])); if(!empty($_POST['mycolor'])) $where[] = sprintf("car.color_id='%s'",mysql_real_escape_string($_POST['mycolor'])); if(!empty($_POST['myinteriorcolor'])) $where[] = sprintf("car.interior_color_id='%s'",mysql_real_escape_string($_POST['myinteriorcolor'])); if(count($where)) $query .= ' WHERE '.implode(' AND ',$where); $result=mysql_query($query) or die (mysql_error()); $fields_num=mysql_num_fields($result); echo "<p align='center'>Results:</p><table width='75%' border='1' align='center'><tr>"; //printing talbe headers for($i=0; $i<$fields_num; $i++) { $field=mysql_fetch_field($result); echo "<td>{$field->name}</td>"; } echo "</tr>\n"; //print table rows while($row=mysql_fetch_row($result)) { echo "<tr>"; foreach($row as $cell) echo "<td>$cell</td>"; echo "<td><form method='LINK' action='edit.php'><input type='submit'value='Edit'></form></td><td><form method='LINK' action='delete.php'><input type='submit'value='Delete'></form></td>\n"; echo "</tr>\n"; } mysql_free_result($result); ob_end_flush(); ?> 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.