PHP - Multiple Checkbox Query Search
After a few days of searching and running across a problem what is almost like mine on these forums (cant seem to find the link now) where the person was looking to search a database using checkboxes.
What I am trying to do is use a list of checkboxes (http://www.animeseason.com/anime-list/categories/) exactly like this link and search my table which has the genres as columns. I am new to PHP and don't really have a starting point. I have taken a bunch of examples and came up with this. My HTML form with a list of all my checkboxes. Code: [Select] <form method="post" ACTION = "php/do_search.php"> <ul class="cat_col"> <li><input type="checkbox" name="cat_check[]" value="1"> <a href="#Action">Action</a></li> <li><input type="checkbox" name="cat_check[]" value="2"> <a href="#Adventure">Adventure</a></li> <li><input type="checkbox" name="cat_check[]" value="3"> <a href="#Comedy">Comedy</a></li> <li><input type="checkbox" name="cat_check[]" value="4"> <a href="#Demons">Demons</a></li> <li><input type="checkbox" name="cat_check[]" value="5"> <a href="#Drama">Drama</a></li> <li><input type="checkbox" name="cat_check[]" value="6"> <a href="#Ecchi">Ecchi</a></li> <li><input type="checkbox" name="cat_check[]" value="7"> <a href="#Fantasy">Fantasy</a></li> <li><input type="checkbox" name="cat_check[]" value="8"> <a href="#Harem">Harem</a></li> <li><input type="checkbox" name="cat_check[]" value="9"> <a href="#Horror">Horror</a></li> <li><input type="checkbox" name="cat_check[]" value="10"> <a href="#Magic">Magic</a></li> <li><input type="checkbox" name="cat_check[]" value="11"> <a href="#Martial Arts">Martial Arts</a></li> <li><input type="checkbox" name="cat_check[]" value="12"> <a href="#Mecha">Mecha</a></li> <li><input type="checkbox" name="cat_check[]" value="13"> <a href="#Music">Music</a></li> </ul> <ul class="cat_col"> <li><input type="checkbox" name="cat_check[]" value="14"> <a href="#Mystery">Mystery</a></li> <li><input type="checkbox" name="cat_check[]" value="15"> <a href="#Ninja">Ninja</a></li> <li><input type="checkbox" name="cat_check[]" value="16"> <a href="#Parody">Parody</a></li> <li><input type="checkbox" name="cat_check[]" value="17"> <a href="#Psychological">Psychological</a></li> <li><input type="checkbox" name="cat_check[]" value="18"> <a href="#Reverse Harem">Reverse Harem</a></li> <li><input type="checkbox" name="cat_check[]" value="19"> <a href="#Romance">Romance</a></li> <li><input type="checkbox" name="cat_check[]" value="20"> <a href="#Samurai">Samurai</a></li> <li><input type="checkbox" name="cat_check[]" value="21"> <a href="#School Life">School Life</a></li> <li><input type="checkbox" name="cat_check[]" value="22"> <a href="#Science Fiction">Science Fiction</a></li> <li><input type="checkbox" name="cat_check[]" value="23"> <a href="#Seinen">Seinen</a></li> <li><input type="checkbox" name="cat_check[]" value="24"> <a href="#Shoujo">Shoujo</a></li> <li><input type="checkbox" name="cat_check[]" value="25"> <a href="#Shounen">Shounen</a></li> <li><input type="checkbox" name="cat_check[]" value="26"> <a href="#Slapstick">Slapstick</a></li> </ul> <ul class="cat_col"> <li><input type="checkbox" name="cat_check[]" value="27"> <a href="#Slice of Life">Slice of Life</a></li> <li><input type="checkbox" name="cat_check[]" value="28"> <a href="#Sports">Sports</a></li> <li><input type="checkbox" name="cat_check[]" value="29"> <a href="#Supernatural">Supernatural</a></li> <li><input type="checkbox" name="cat_check[]" value="30"> <a href="#Thriller">Thriller</a></li> <li><input type="checkbox" name="cat_check[]" value="31"> <a href="#Tragedy">Tragedy</a></li> <li><input type="checkbox" name="cat_check[]" value="32"> <a href="#Vampire">Vampire</a></li> </ul> <ul class="cat_col"> <li><input type="checkbox" name="cat_check[]" value="33"> <a href="#Movie">Movie</a></li> <li><input type="checkbox" name="cat_check[]" value="34"> <a href="#OVA">OVA</a></li> <li><input type="checkbox" name="cat_check[]" value="35"> <a href="#Top Rated">Top Rated</a></li> <li><input type="checkbox" name="cat_check[]" value="36"> <a href="#Currently Airing">Currently Airing</a></li> <li><input type="checkbox" name="cat_check[]" value="37"> <a href="#Ended">Ended</a></li> <li><input type="checkbox" name="cat_check[]" value="38"> <a href="#Ongoing">Ongoing</a></li> </ul> <div id="submit_btn_pos"> <input type="submit" name="search" value="Lets Make Magic" class="submit_btn"> <> </form> My PHP script that right now seems to do nothing. Code: [Select] <?php //if we got something through $_POST if (isset($_POST['cat_check'])) { $con = mysql_connect("localhost","USERNAME","PASSWORD") or die("Connection error"); mysql_select_db("DATABASENAME")or die("database doesn't exist"); // sanitize user input $cleanData = array(); foreach($_POST['cat_check'] as $_comp) { //$cleanData = mysql_real_escape_query($_comp); } // Build query $compStr = implode("'), ('", $cleanData); $sql = "SELECT anime_name WHERE $_comp='1'"; } ?> My database has a layout of "Name of show, (every genere listed above)". Thanks for any help. Similar TutorialsHi guys, I have a php file that will go to a site and scrape the data I need. However this site is setup to use pagination so when I try to scrape all the players names I have to do separate queries to search each page. Is there a way to find out by using code how many pages there are and query all the pages at same time? I use this code Code: [Select] <?php //first page //turn error reporting on libxml_use_internal_errors(true); //get data from this page $dom = new DOMDocument; $dom->loadHTMLFile('http://www.gametracker.com/server_info/76.73.3.42:1716/top_players/?searchipp=50#search'); $xpath = new DOMXPath($dom); // Get the total player count $rows2 = $xpath->query('//div[@class="block774"]/div'); // Get the rows from the search list $rows = $xpath->query('//table[@class="table_lst table_lst_spn"]/tr'); for ($i=1; $i<$rows->length-1; $i++) { $row = $rows->item($i); // Get the columns for a row $cols = $row->getElementsByTagName('td'); // Get the player rank (1st column) echo 'Rank:'.trim($cols->item(0)->textContent).PHP_EOL; // Get the player name (2nd column) echo 'Name:'.trim($cols->item(1)->textContent).PHP_EOL; // Get the player score (3rd column, actually 4th but number 3 is hidden) echo 'Sco '.trim($cols->item(3)->textContent).PHP_EOL; echo "<br />"; } ?> <?php //secondpage //turn error reporting on libxml_use_internal_errors(true); //get data from this page $dom = new DOMDocument; $dom->loadHTMLFile('http://www.gametracker.com/server_info/76.73.3.42:1716/top_players/?searchipp=50&searchpge=2#search'); $xpath = new DOMXPath($dom); // Get the rows from the search list $rows = $xpath->query('//table[@class="table_lst table_lst_spn"]/tr'); for ($i=1; $i<$rows->length-1; $i++) { $row = $rows->item($i); // Get the columns for a row $cols = $row->getElementsByTagName('td'); // Get the player rank (1st column) echo 'Rank:'.trim($cols->item(0)->textContent).PHP_EOL; // Get the player name (2nd column) echo 'Name:'.trim($cols->item(1)->textContent).PHP_EOL; // Get the player score (3rd column) echo 'Sco '.trim($cols->item(3)->textContent).PHP_EOL; echo "<br />"; } ?> I also have to go to that website first to see how many pages there are so I can have enough queries. I want to have a search product feature, but I would like members to be able to search multiple fields in one go i.e. product_code, Product_name in one MySQL query. The thing is, members have to be logged on, so the query must also only show results relating to that specific member, via the session[member_ID], my current query for listing products for that specific member is : Code: [Select] $sql = "SELECT productId, productCode, image, name, price, stock_level FROM product_inventory WHERE memberr_ID = '" . $_SESSION['SESS_mem_ID'] . "; How would I change the above into a search query to search for productcode, productname and still only show results beloging to this member using the session data ? all help appreciated Hello all, I am trying to learn OOP in PHP so please forgive my ignorance. I seem to be having difficulty inserting data into my database from checkbox items. My database has a column for each each fruit. I would like for each column to be populated with either a one(1) for checked or a zero(0) for not checked. Currently, my attempts have failed. I can either get all checkboxes to insert all zeros or I can get the first column to insert a one(1) while the others as zeros. Is there anybody here that can help me figure out what I am doing wrong and help me to re-work my code so I can get this to work? If anybody can help me using OOP methods that would be fantastic. Thank you all in advance.
$preffruit->create_preffruit(array( 'fruit_apple' => escape(Input::get(['fruit_selection'][0]) ? 1 : 0), 'fruit_orange' => escape(Input::get(['fruit_selection'][1]) ? 1 : 0), 'fruit_banana' => escape(Input::get(['fruit_selection'][2]) ? 1 : 0), 'fruit_pear' => escape(Input::get(['fruit_selection'][3]) ? 1 : 0), 'fruit_kiwi' => escape(Input::get(['fruit_selection'][4]) ? 1 : 0) )); <input type="checkbox" name="fruit_selection[]" value="fruit_apple"> <input type="checkbox" name="fruit_selection[]" value="fruit_orange"> <input type="checkbox" name="fruit_selection[]" value="fruit_banana"> <input type="checkbox" name="fruit_selection[]" value="fruit_pear"> <input type="checkbox" name="fruit_selection[]" value="fruit_kiwi"> public function insert_preffruit($table, $fields = array()) { $keys = array_keys($fields); $values = ''; $x = 1; foreach($fields as $field) { $values .= '?'; if($x < count($fields)) { $values .= ', '; } $x++; } $sql = "INSERT INTO preffruit (`user_id`, `" . implode('`, `', $keys) . "`) VALUES (LAST_INSERT_ID(), {$values})"; if(!$this->query($sql, $fields)->error()) { return true; } return false; } Edited September 23, 2020 by ke-jo Hello, Does anyone know a tutorial I can follow to create my own search engine over the items I have in my SQL database? I find a lot of tutorials but they are all 'one word searches' which means if you type two words you will get all results that contain either word (too many hits). If the search engine tutorial displays result with AJAX even better. Thanks for help. df Hi all How do I modify the below code to search multiple tables in mySQL database? $query = "select * from store_items where description like \"%$trimmed%\" or title like \"%$trimmed%\" or dimensions like \"%$trimmed%\" order by id ASC"; $numresults=mysql_query($query); $numrows=mysql_num_rows($numresults); It is for a search function and I need it to search another table called 'about_text' and 'faq_text' Thanks Pete This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=351561.0 Hi gang, new to posting but I've read the forum on and off. I'm coding a small community and will have a lot of questions for you over time. The first one is about a search function. We'll have users of different nationalities and languages and you will be able to search, only I was thinking there could be a better way. They'll enter those posts through a dropdown list and when you search it you will use checkboxes. I just don't see the results I want when I pick the array for info. Like I have this right now as the form (which is sent to the php page itself as POST): Nationality: <br /> <input type="checkbox"" name="natBox[]" size="30" value="all"/> All<br /> <input type="checkbox"" name="natBox[]" size="30" value="weuro"/> W Europe<br /> <input type="checkbox"" name="natBox[]" size="30" value="eeuro"/> E Europe<br /> <input type="checkbox"" name="natBox[]" size="30" value="wafrica"/> W Africa<br /> And the thing I was doing was to check the boxes with if (isset) and then make the query longer and longer, butI figure there could be a smarter way. Like if I was going to enter 200 countries I can't really check for all can I? After the check (now deleted) it sets the query to this: $query = "SELECT * FROM user_criteria WHERE (age BETWEEN '$ageFr' AND '$ageTo') AND nationality='$nationality'"; ...and the part I don't have now is to pick the array natBox and add every value so @nationality becomes for instance weuro OR wafrica etc. Got a more elegant approach? I have been having a bit of difficultly understanding how to submit a single checkbox values for a list of names and saving it in a MySQL database. The way it is meant to work is that a list of names from a table (Table1) is produced on the screen through a query. I have a checkbox that appears beside each individual name and if I tick the box I want it to save the value '1' to the database, otherwise the value remains as zero. When I tick the necessary boxes I wish to save it to another table (Table2, it is separate from Table1). The name and value needs to be saved to it. The problems that arises is how do I save the checkbox value for each individual name? Will I need to use a checkbox array or can I treat each name as independent? Hopefully you understand what I mean. does anyone have a code todo this? a snippet or soemthing ive tried a few diffrent ones ive seen but nothing that works.. it takes whats submited in search, then takes the words, breaks them up and creates a query string with all the diffrent feilds... here is what phpadmin produces when i search SELECT * FROM `breedclads`.`activeamahorse` WHERE (`id_entered` LIKE '%green%' OR `uuid` LIKE '%green%' OR `ama_hr_coat` LIKE '%green%' OR `breedable` LIKE '%green%' OR `ama_hr_sex` LIKE '%green%' OR `ama_hr_age` LIKE '%green%' OR `date_entered` LIKE '%green%' OR `ama_hr_eyes` LIKE '%green%' OR `ama_hr_eyes_type` LIKE '%green%' OR `ama_hr_mane` LIKE '%green%' OR `ama_hr_tail` LIKE '%green%' OR `ama_hr_luster_coat` LIKE '%green%' OR `ama_hr_luster_hair` LIKE '%green%' OR `ama_hr_gleam_coat` LIKE '%green%' OR `ama_hr_gleam_hair` LIKE '%green%' OR `ama_hr_parents` LIKE '%green%' OR `ama_hr_sale_type` LIKE '%green%' OR `ama_hr_sale_price` LIKE '%green%' OR `ama_hr_location` LIKE '%green%' OR `auction_date` LIKE '%green%' OR `picture_type` LIKE '%green%' OR `picture_name` LIKE '%green%' OR `picture_size` LIKE '%green%' OR `picture_content` LIKE '%green%' OR `ama_hr_coat_type` LIKE '%green%' OR `ama_hr_coat_gloom` LIKE '%green%' OR `ama_hr_hair_gloom` LIKE '%green%' OR `ama_hr_slurl` LIKE '%green%' OR `class_link_key` LIKE '%green%') AND (`id_entered` LIKE '%albino%' OR `uuid` LIKE '%albino%' OR `ama_hr_coat` LIKE '%albino%' OR `breedable` LIKE '%albino%' OR `ama_hr_sex` LIKE '%albino%' OR `ama_hr_age` LIKE '%albino%' OR `date_entered` LIKE '%albino%' OR `ama_hr_eyes` LIKE '%albino%' OR `ama_hr_eyes_type` LIKE '%albino%' OR `ama_hr_mane` LIKE '%albino%' OR `ama_hr_tail` LIKE '%albino%' OR `ama_hr_luster_coat` LIKE '%albino%' OR `ama_hr_luster_hair` LIKE '%albino%' OR `ama_hr_gleam_coat` LIKE '%albino%' OR `ama_hr_gleam_hair` LIKE '%albino%' OR `ama_hr_parents` LIKE '%albino%' OR `ama_hr_sale_type` LIKE '%albino%' OR `ama_hr_sale_price` LIKE '%albino%' OR `ama_hr_location` LIKE '%albino%' OR `auction_date` LIKE '%albino%' OR `picture_type` LIKE '%albino%' OR `picture_name` LIKE '%albino%' OR `picture_size` LIKE '%albino%' OR `picture_content` LIKE '%albino%' OR `ama_hr_coat_type` LIKE '%albino%' OR `ama_hr_coat_gloom` LIKE '%albino%' OR `ama_hr_hair_gloom` LIKE '%albino%' OR `ama_hr_slurl` LIKE '%albino%' OR `class_link_key` LIKE '%albino%') AND (`id_entered` LIKE '%69%' OR `uuid` LIKE '%69%' OR `ama_hr_coat` LIKE '%69%' OR `breedable` LIKE '%69%' OR `ama_hr_sex` LIKE '%69%' OR `ama_hr_age` LIKE '%69%' OR `date_entered` LIKE '%69%' OR `ama_hr_eyes` LIKE '%69%' OR `ama_hr_eyes_type` LIKE '%69%' OR `ama_hr_mane` LIKE '%69%' OR `ama_hr_tail` LIKE '%69%' OR `ama_hr_luster_coat` LIKE '%69%' OR `ama_hr_luster_hair` LIKE '%69%' OR `ama_hr_gleam_coat` LIKE '%69%' OR `ama_hr_gleam_hair` LIKE '%69%' OR `ama_hr_parents` LIKE '%69%' OR `ama_hr_sale_type` LIKE '%69%' OR `ama_hr_sale_price` LIKE '%69%' OR `ama_hr_location` LIKE '%69%' OR `auction_date` LIKE '%69%' OR `picture_type` LIKE '%69%' OR `picture_name` LIKE '%69%' OR `picture_size` LIKE '%69%' OR `picture_content` LIKE '%69%' OR `ama_hr_coat_type` LIKE '%69%' OR `ama_hr_coat_gloom` LIKE '%69%' OR `ama_hr_hair_gloom` LIKE '%69%' OR `ama_hr_slurl` LIKE '%69%' OR `class_link_key` LIKE '%69%') i need this to be made when people search with mutliple words as you can see it searchs each feilds for the green then each feild for albino, so on.. but i wont ever know what there searching for Please help me, thanks I have a form that has a list of checboxes, each checkbox has multiple values. IE. Checkbox1 has Date 1 and Cost1. Checkbox2 has Date2 and cost2 and so on. This is what I have in form. echo "<input type=checkbox name=service_id[] value=".$id."><label>".$description."</label> Date:<input type=date name=date[] value=".date('Y-m-d').">Date:<input type=number name=cost[] value=".$cost."><br>"; When i run the for loop to insert the values into a table i have this.
foreach($_POST['service_id'] as $key => $value){
The problem is that when I select certain boxes (ie, checkbox #2), it inserts Date1 and Cost1 but does use the correct service id (ie checkbox) Hi. I have a form with a selection of checkboxes. I am trying to use an array to store the results in a single column of a mysql database. The problem is, instead of the values, it just stores 'array'. Each checkbox is like so: <input name="previous_diseases[]" value="Tuberculosis"/> Here is my code: Code: [Select] <?php try{ $pdo_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION; $database = new PDO('mysql:host=localhost;dbname=db', 'username', 'password', $pdo_options); $execution=$database->prepare('INSERT INTO form(title, forename, surname, address_1, address_2, address_city, address_county, address_country, address_postcode, email, previous_diseases, hear) VALUES(:title, :forename, :surname, :address_1, :address_2, :address_city, :address_county, :address_country, :address_postcode, :email, :previous_diseases, :hear)'); $execution->execute(array('title' => $_POST['title'], 'forename' => $_POST['forename'], 'surname' => $_POST['surname'], 'address_1' => $_POST['address_1'], 'address_2' => $_POST['address_2'], 'address_city' => $_POST['address_city'], 'address_county' => $_POST['address_county'], 'address_country' => $_POST['address_country'], 'address_postcode' => $_POST['address_postcode'], 'email' => $_POST['email'], 'previous_diseases' => $_POST['previous_diseases'], 'hear' => $_POST['hear'])); Can anyone please show me what I need to change to get the values inserted into the database. Thank you Hi all: I start an application in PHP and SQL Server for a company car and I need some recommendations. The application tracked him to the maintenance of the cars. On one side are the car brands (Ford, Chevrolet, etc.) with the relevant goods and associated services. A relationship many-to-many. On the other hand, the executives (stage 1) enter the customer associated with their cars and the corresponding products and services. The customer goes to the mechanic who performs the action (step 2) and finally counter that the collection (step 3). My main problem is how to link Client - Automobile - Services in the first form. Enter the name and telephone number after a multi-select will select the brand and asynchronously checkbox must be loaded in all services and check the corresponding to that mark. I find it difficult to incorporate all the links on the form. Appreciate design recommendations database (customer table) and how to assemble the form. Maybe some of you made any similar application or know a reference. Finally thank you in advance for the time can provide for review this post. Hi I just barely made it through sending form to email using php. now I have another problem with checkboxes. please help! whenever I select multiple checkbox options. the form only sends me the last check box option checked. not all checked options. here's my php code : Code: [Select] <?php /*Subject and Email Variables*/ $emailSubject = 'Inquiry'; $emailAddress = 'inquiry@topazbranch.com'; /*Gathering Data Variables*/ $firstname = $_POST['firstname']; $lastname = $_POST['lastname']; $contact = $_POST['contact']; $email = $_POST['email']; $newsletter = $_POST['newsletter']; $projects = $_POST['ch']; $trippingSchedule = $_POST['tripping']; $source = $_POST['source']; $agent = $_POST['agent']; $comments = $_POST['comments']; if($_POST['submit']) { $projects = $_POST['projects']; foreach($projects as $ch) } $body = <<<EOD <br/><hr/><br/> Firstname : $firstname<br/> Lastname : $lastname<br/> Contact: $contact<br/> Email : $email<br/> Newsletter : $newsletter<br/> Projects : $ch<br/> Tripping Schedule : $trippingSchedule<br/> Source : $source<br/> Agent name : $agent<br/> Additional Comments : $comments<br/> EOD; $headers = "From: $email\r\n"; $headers .= "content-type: text/html\r\n"; $success = mail($emailAddress, $emailSubject, $body, $headers); /* Results render as HTML*/ $theResults = <<<EOD (some html here) EOD; echo "$theResults"; ?> MOD EDIT: code tags added. Is is possible to give multiple values in a single checkbox? i need to have a checkbox that holds multiple values. Help Anyone.. Hey phpFreaks, im having some troubles getting my script to work correctly and im also not sure if this issue is in the right section of the forum. but heres what i have going on. I have a query result that displays a list of images with a checkbox and a couple buttons for edit and delete. everything works fine other than the checkbox stuff. I had it working when i was using a submit button, but i wanted to get rid of that button cuz it was only dealing with the checkboxes. so whats going on when using the checkboxes is that when checked or uncheck it would submit the form. It works to submit but its not submitting any data to the database. heres what i got for code for this section of checkbox. Code: [Select] <?php echo '<form method="post">'; if(isset($_POST['submit'])){ foreach($_POST['id'] as $id){ $value = (isset($_POST['location'][$id]) && $_POST['location'][$id]=="0" ? '0' : '1'); $insert = mysql_query("UPDATE items SET location='$value' WHERE id='$id'") or die('Insert Error: '.mysql_error()); } } $result = mysql_query("SELECT * FROM items") or die("Query Failed: ".mysql_error()); $counter = 0; echo '<div class="specialcontainer">'; while($row = mysql_fetch_array($result)){ list($id, $item_info, $item_img, $price, $sale, $location) = $row; if($location == '0'){ $set_checked = 'checked="checked"'; }else{ $set_checked = ''; } if($counter % 5==0) { echo '</div>'; echo '<div class="specialcontainer">'; } echo '<div class="special"><img src="../images/items/'.$item_img.'" width="130" /><br />'.$item_info.'<br />$'.$price.'<br />$'.$sale.'<br />Slide Show: <input type="checkbox" id='.$id.' value="0" name="location['.$id.']" '.$set_checked.' onchange="this.form.submit()"/><br /><input type="button" value="Edit" name="edit" id="'.$id.'" onclick="window.location.href=\'specials.php?action=edit&id='.$id.'\'"><input type="button" value="Delete" name="Delete" id="'.$id.'" onclick="window.location.href=\'specials.php?action=delete&id='.$id.'\'"><input type="hidden" name="id[]" value='.$id.' /></div>'; $counter++; } echo '</div>'; echo '</form>'; ?> What I have is a page with a list of cars, each with a checkbox next to them. Code: [Select] <?php $sth = null; $count = 0; $sth = $dbh->prepare("SELECT * FROM garage WHERE warehouse_id = ? ORDER BY car_name ASC"); $sth->execute(array($_POST['ware_id'])); echo "<table>"; echo "<tr>"; echo '<td>Choose Vehicles:</td>'; echo "</tr>"; echo "<tr>"; echo "<td>"; echo "<form action='warehouse_ship_3.php' method='POST'>"; while($row = $sth->fetch()){ echo "<input type='checkbox' name='cars' value='".$row['uci']."' /> ID: ".$row['uci'].", ".$row['car_year']." ".$row['car_name']."<br />"; } echo "<input type='hidden' name='ware_id' value='".$_POST['ware_id']."' />"; echo "<hr />"; echo '<div class="center"><input class="myButton" type="submit" name="submit" value="Next" /></div></form>'; echo "</td>"; echo "</tr>"; echo "</table>"; ?> That works fine. What I'm trying to do with this second page, is select all the car's info from a table called "garage" which stores data for all the cars (car name, year, etc) and display it. UCI stands for Unique car id, every car has a different id. It works when the user only selects one car on the previous page, but if they select two or more cars, only the car with the highest UCI number shows up. How would I work it to display info on every car that they selected? Code: [Select] <?php if(empty($_POST['cars'])) { echo("You didn't select any cars."); } else { $sth = $dbh->prepare("SELECT * FROM `garage` WHERE `uci` = ?"); $sth->execute(array($_POST['cars'])); while($cars = $sth->fetch()){ echo" ".$cars['uci'].", ".$cars['car_year']." ".$cars['car_name']." "; } } ?> Hi, I m trying to add items from a master list to each sub process. But, I failed to proceed on what i intend to do. 1) i need to select an process from the combo box. 2) from the master list, i hv to check the item which belong to the process. 3) upon submitting, save into database. 4) the it will show those are already checked or unchecked. here is the codes i hv done: Code: [Select] <?php require_once '../../connectDB.php'; require_once '../include/paginator.class.php'; $sql="SELECT * FROM tb_item"; $result = mysql_query($sql) or die(mysql_error()); $pages = new Paginator; $pages->items_total = mysql_num_rows($result); $pages->mid_range = 5; $pages->items_per_page = 100; $pages->paginate(); $sql="SELECT * FROM tb_item ORDER BY itm_tcpd ASC $pages->limit"; $result = mysql_query($sql) or die(mysql_error()); function createComboBox() { $sql = "SELECT tb_process.pro_name, tb_process.pro_id, tb_sub_process.sub_id, tb_sub_process.sub_name FROM tb_process INNER JOIN tb_sub_process ON tb_process.pro_id = tb_sub_process.pro_id ORDER BY pro_name"; $result = mysql_query($sql) or die('Cannot get Process. ' . mysql_error()); $group = array(); while ($row = mysql_fetch_assoc($result)) { $group[$row['pro_name']][] = $row; } echo "<table> <tr> <td>Add item into :</td> <td> <select name='cboSub' id='cboSub'> <option value='0' selected='selected'>----- Selection -----</option>"; foreach ($group as $key => $values) { echo " <optgroup label='$key'>"; foreach ($values as $value) { $select = ($id == $value['sub_id']) ? 'selected="selected"' : NULL; echo '<option value="'.$value['sub_id'].'"'.$select.'>'.$value['sub_name'].'</option>'; } echo " </optgroup>"; } echo " </select> </td> </tr> </table>"; } if(isset($_POST['add'])) { $id = $_POST['checkbox']; foreach($id as $key=>$val) { $sql = "INSERT INTO tb_record (rec_tpcd, sub_id) VALUES ('$key', '$sub_id')"; $result = mysql_query($sql); } echo(" <SCRIPT LANGUAGE='JavaScript'> window.alert('Items has been added into the database.'); window.location='addItem.php'; </SCRIPT>"); } ?> <!DOCTYPE div PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <script type="text/javascript"> $().ready(function() { $("#cboSub").change("get_tpcd.php", { }); }); </script> </head> <body> <div> <table width="100%"> <tr> <td width="65%"><?php createComboBox(); ?></td> <td width="30%"><?php echo $pages->display_pages(); ?></td> <td width="5%"><?php echo $pages->display_jump_menu(); ?></td> </tr> </table> </div> <div> <form method='post' action=''> <table width='100%' border='1' align='left' cellpadding='5' cellspacing='1'> <tr> <?php $numCol = 5; $count = 0; for($i=0; $i<$numCol; $i++) { echo "<th align='center'>TPCD No.</th> <th align='center'>Check / Uncheck</th>"; } while ($row = mysql_fetch_array($result)) { extract($row); if($count % $numCol == 0) { echo '</tr><tr>'; } echo " <td align='center'>".$itm_tcpd."</td> <td align='right'><input type='checkbox' name='checkbox[".$itm_tcpd."]' id='checkbox' ".$checked."></td>"; $count++; } ?> </tr> <tr> <td colspan='10' align='right'> <input type='submit' name='add' id='add' value='Add TPCD'> </td> </tr> </table> </form> </div> </body> </html> the output is something similar as in the attachment. any helps are vy welcome and appreciated. regards, juz [attachment deleted by admin] |