PHP - Multiple Dropdowns To Filter Query
Hello,
I have a drop down box that filters my table data by City and displays the results. It works! Now I am trying to add a second drop down menu to filter by name. When name is selected AND city is selected, the display should be the same names that live in the same city. Can anyone ties these 2 drop downs together for me? Here is my table: Code: [Select] CREATE TABLE IF NOT EXISTS `data` ( `id` int(11) NOT NULL auto_increment, `from_date` date NOT NULL, `to_date` date NOT NULL, `full_name` varchar(250) NOT NULL, `email` varchar(250) NOT NULL, `city` varchar(250) NOT NULL, PRIMARY KEY (`id`) ) And here is the html and PHP in one file: Code: [Select] <?php error_reporting(0); include("config.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=utf-8" /> <title>MySQL table search</title> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"></script> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js"></script> <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/> <style> BODY, TD { font-family:Arial, Helvetica, sans-serif; font-size:12px; } </style> </head> <body> <form id="form1" name="form1" method="post" action="search.php"> <label>Name</label> <select name="name"> <option value="">--</option> <?php $sql = "SELECT * FROM ".$SETTINGS["data_table"]." GROUP BY full_name ORDER BY full_name"; $sql_result = mysql_query ($sql, $connection ) or die ('request "Could not execute SQL query" '.$sql); while ($row = mysql_fetch_assoc($sql_result)) { echo "<option value='".$row["full_name"]."'".($row["full_name"]==$_REQUEST["full_name"] ? " selected" : "").">".$row["full_name"]."</option>"; } ?> </select> <label>City</label> <select name="city"> <option value="">--</option> <?php $sql = "SELECT * FROM ".$SETTINGS["data_table"]." GROUP BY city ORDER BY city"; $sql_result = mysql_query ($sql, $connection ) or die ('request "Could not execute SQL query" '.$sql); while ($row = mysql_fetch_assoc($sql_result)) { echo "<option value='".$row["city"]."'".($row["city"]==$_REQUEST["city"] ? " selected" : "").">".$row["city"]."</option>"; } ?> </select> <input type="submit" name="button" id="button" value="Filter" /> </label> <a href="search.php"> reset</a> </form> <br /><br /> <table width="700" border="1" cellspacing="0" cellpadding="4"> <tr> <td width="90" bgcolor="#CCCCCC"><strong>From date</strong></td> <td width="95" bgcolor="#CCCCCC"><strong>To date</strong></td> <td width="159" bgcolor="#CCCCCC"><strong>Name</strong></td> <td width="191" bgcolor="#CCCCCC"><strong>Email</strong></td> <td width="113" bgcolor="#CCCCCC"><strong>City</strong></td> </tr> <?php if ($_REQUEST["city"]<>'') { $search_city = " AND city='".mysql_real_escape_string($_REQUEST["city"])."'"; } if ($_REQUEST["from"]<>'' and $_REQUEST["to"]<>'') { $sql = "SELECT * FROM ".$SETTINGS["data_table"]." WHERE from_date >= '".mysql_real_escape_string($_REQUEST["from"])."' AND to_date <= '".mysql_real_escape_string($_REQUEST["to"])."'".$search_string.$search_city; } else if ($_REQUEST["from"]<>'') { $sql = "SELECT * FROM ".$SETTINGS["data_table"]." WHERE from_date >= '".mysql_real_escape_string($_REQUEST["from"])."'".$search_string.$search_city; } else if ($_REQUEST["to"]<>'') { $sql = "SELECT * FROM ".$SETTINGS["data_table"]." WHERE to_date <= '".mysql_real_escape_string($_REQUEST["to"])."'".$search_string.$search_city; } else { $sql = "SELECT * FROM ".$SETTINGS["data_table"]." WHERE id>0".$search_string.$search_city; } $sql_result = mysql_query ($sql, $connection ) or die ('request "Could not execute SQL query" '.$sql); if (mysql_num_rows($sql_result)>0) { while ($row = mysql_fetch_assoc($sql_result)) { ?> <tr> <td><?php echo $row["from_date"]; ?></td> <td><?php echo $row["to_date"]; ?></td> <td><?php echo $row["full_name"]; ?></td> <td><?php echo $row["email"]; ?></td> <td><?php echo $row["city"]; ?></td> </tr> <?php } } else { ?> <tr><td colspan="5">No results found.</td> <?php } ?> </table> </body> </html> Similar TutorialsOk so i want to grab an id from the checkbox then grab the option drop down associated with that check box and update a mysql row here is my code so far any help is awesome help taaaanks guys <?php mysql_connect("localhost", "root", "root") or die(mysql_error()); mysql_select_db("db1") or die(mysql_error()); $query = "SELECT * FROM tickets ORDER BY id DESC"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)) { print "<input name='delete[]' value='{$row['id']}' type='checkbox'>"; mysql_connect("localhost", "root", "root") or die(mysql_error()); mysql_select_db("db1") or die(mysql_error()); $query2 = "SELECT * FROM admin"; $result2 = mysql_query($query2) or die(mysql_error()); print "<form name='namestoupdate' method='post' action='update.php'>\n"; print '<select>'; while($row2 = mysql_fetch_array($result2)) { if ($row2['priv']==prov){print '<option value="'.$row2['user'].'" name="prov['.$i++.']">'.$row2['user'].'</option>';} } print '</select>'; print "<input type='submit' value='submit' />"; print "</form>"; } ?> Visual aid I have two drop down menus in a table side by side being populated exactly the same from a msql database. The first menu populates fine but the second one is blank. They are both supposed to be identical, the same info from the same table so I assume that's my problem. I tried moving the while loop so it encapsulates both drop downs but then it messes up the table structure. I tried changing the name of some of the variables by adding "2" on the end & that didn't work either. Is it because once a while loop is executed it can't be used again on the same instance? Heres my code so far: <tr> <td > <select name="wall_type" size="1" style="width: 175px;" > <?php while ($walls_row=mysql_fetch_array($result_walls)) { $type_name=$walls_row["type"]; $type_id=$walls_row["id"]; ?> <option value="<?php echo $type_id; ?>"><?php echo $type_name; ?> </option> <?php } ?> </select> </td> <td > <select name="wall_type2" size="1" style="width: 175px;"> <?php while ($walls_row2=mysql_fetch_array($result_walls)) { $type_name2=$walls_row2["type"]; $type_id2=$walls_row2["id"]; ?> <option value="<?php echo $type_id2; ?>"><?php echo $type_name2; ?> </option> <?php } ?> </select> </td> </tr> Hi all, iv been trying to compile a script that will allow users to select multiple checkboxs that will filter results from db..but to no avail. I have my data stored in mysql and have the queries saved seperatley. i.e. price = 0-500, 500-1000.etc. What im trying to achieve is to allow users to select a checkbox that will execute that particular query and also more importantly allow them to select 'multiple' checkboxes that will filter the results accordingly. I have never attempted to code this before although I am aware that it might involve arrays. If someone could give me a nudge in the right direction that would be great :-) This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=351561.0 these DB are on the same server sp inter query how do i combine the mysql_db()? Code: [Select] SELECT * FROM `sp.bookings` LEFT JOIN sp.bookings_items ON sp.bookings.id_item = sp.bookings_items.id LEFT JOIN inter.apartments ON inter.apartments.ID = sp.bookings_items.id_ref_external WHERE sp.bookings.the_date BETWEEN '$from_date' and '$to_date' and id_state=1 LIMIT 0 , 30 I can use the first while loop, but there is no data in the second while loop. Is there a better way as I have never done this before... Code: [Select] <?php $featured_results = mysql_query("SELECT * FROM products LEFT JOIN product_images ON products.product_id=product_images.product_id WHERE products.product_featured='1' AND products.product_active='1' AND thumb='1'"); $fa=0; while($featured_row = mysql_fetch_assoc($featured_results)) { $fthumb_result = mysql_query("SELECT image_name FROM product_images WHERE product_id='".$featured_row['product_id']."' AND thumb='1'"); $fthumb = mysql_fetch_row($fthumb_result); if ($fa==0) { echo "\n<img id=\"home-slider-photo-".$fa."\" class=\"home-slider-photo preload\" src=\"/includes/getimage.php?img=".$fthumb[0]."&w=370&h=370\" alt=\"\" />"; } else { echo "\n<img id=\"home-slider-photo-".$fa."\" class=\"home-slider-photo preload home-slider-photo-unsel\" src=\"/includes/getimage.php?img=".$fthumb[0]."&w=370&h=370\" alt=\"\" />"; } $fa++; } echo "<div id=\"home-slider-photo-price\">"; $fb=0; while($featured_row2 = mysql_fetch_assoc($featured_results)) { if ($fb==0) { echo "\n<div id=\"home-slider-photo-price-".$fb."\" class=\"home-slider-photo-price\">\n<span>only</span>$".$featured_row2['product_price']."\n</div>"; } else { echo "\n<div id=\"home-slider-photo-price-".$fb."\" class=\"home-slider-photo-price home-slider-photo-price-unsel\">\n<span>only</span>$".$featured_row2['product_price']."\n</div>"; } $fb++; } echo "</div>"; ?> According to http://www.phpfreaks.com/forums/index.php?topic=350872.0: Is this a correct usage of what I am trying to create? Code: [Select] <?php $connect = mysql_connect("mysql12.000webhost.com","***","***") or die(mysql_error()); mysql_select_db("***") or die(mysql_error()); $id = mysql_real_escape_string($_GET['id']); $extract = mysql_query("SELECT * FROM webclientcreate WHERE id='$id' LIMIT 1 WHERE ip='$ip' WHERE port='$port' WHERE name='$name' WHERE background='$background'"); ?> Code: [Select] <applet name=client width=765 height=503 archive='<?php echo $jars; ?>' code='client.class'> <PARAM name='java_arguments' value='-Xmx700m'> <PARAM name='server_name' value='<?php echo $name; ?>'> <PARAM name='detail' value='low'> <PARAM name='ip' value='<?php echo $ip; ?>'> <PARAM name='port' value='<?php echo $port; ?>'> <PARAM name='background_image' value='<?php echo $background; ?>'> <PARAM name='headicons' value=''> I've tried several types of the query line such as : Code: [Select] webclientcreate WHERE id='$id' LIMIT 1, WHERE ip='$ip', WHERE port='$port' Code: [Select] webclientcreate WHERE id='$id' LIMIT 1, ip='$ip', port='$port' Code: [Select] webclientcreate WHERE id='$id' LIMIT 1 ip='$ip' port='$port'Without any success I appreciate any help I can get! Hey, I have a query running inner joins... which currently works, but I need some more information pulled from other tables... Code: [Select] define('WPSC_TABLE_PRODUCT_LIST', "{$wp_table_prefix}wpsc_product_list"); define('WPSC_TABLE_PRODUCTMETA', "{$wp_table_prefix}wpsc_productmeta"); define('WPSC_TABLE_CATREF', "{$wp_table_prefix}wpsc_item_category_assoc"); define('WPSC_TABLE_CATNAME', "{$wp_table_prefix}wpsc_product_categories"); $cf="Linked Products"; $sku = get_post_meta($post->ID, $cf, true); $array = explode(",",$sku); $products = array_count_values($array); foreach($products as $key => $value) { $product = $wpdb->get_row("SELECT meta.product_id AS pid, list.name AS name, list.price AS price, retailer.category_id AS catid FROM ".WPSC_TABLE_PRODUCTMETA." AS meta INNER JOIN ".WPSC_TABLE_PRODUCT_LIST." AS list ON ( list.id = meta.product_id ) INNER JOIN ".WPSC_TABLE_SHOPNAME." AS retailer ON ( retailer.product_id = meta.product_id ) WHERE `meta_key` IN ( 'sku' ) AND `meta_value` IN ( '{$key}' ) ORDER BY list.id DESC"); ?> But I also need the category name - So I have to cross reference the following... wordpdem_wpsc_product_list id name 433 itemone 432 itemtwo 431 itemthree wordpdem_wpsc_item_category_assoc id product_id category_id 1 433 1 2 432 2 3 410 3 wordpdem_wpsc_product_categories id name 1 Bread 2 Fish 3 Snacks I've now written: Code: [Select] SELECT meta.product_id AS pid, list.name AS name, list.price AS price, retailer.category_id AS catid, category.name AS catname FROM wordpdem_wpsc_productmeta AS meta INNER JOIN wordpdem_wpsc_product_list AS list ON ( list.id = meta.product_id ) INNER JOIN wordpdem_wpsc_item_category_assoc AS retailer ON ( retailer.product_id = meta.product_id ) INNER JOIN `wordpdem_wpsc_product_categories``wordpdem_wpsc_product_list` AS category ON ( retailer.category_id = category.id ) WHERE `meta_key` IN ( 'sku' ) AND `meta_value` IN ( '{$key}' ) ORDER BY list.id DESC However it fails on line 12 (the Where statement...) Any ideas what I've done wrong? $query = mysql_query("SELECT COUNT(tickets.id),tickets.id,tickets.status,tickets.date,tickets.question,tickets.title,users.position FROM tickets,users WHERE tickets.id='$existing' users.username='$username'"); How do I get it so it selects data from the table tickets where id='$existing', but I also want to get a user's (who is viewing the ID) position (rank). $username is a session. So, any thoughts on how I would do so? My updated code: <?php session_start(); include("../includes/mysql.php"); include("../includes/config.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" /> <link href="../style.css" rel="stylesheet" type="text/css" /> <title><?php echo $title; ?></title> </head> <body> <div id="container"> <div id="content"> <div id="left"> <div class="menu"> <?php include("../includes/navigation.php"); ?> <div class="menufooter"></div> </div> <?php include("../includes/menu.php"); ?> </div> <div id="middle"> <?php $existing = $_POST['existing']; $ip = $_SERVER['REMOTE_ADDR']; $username = $_SESSION['user']; $query = mysql_query("SELECT COUNT(tickets.id),tickets.id,tickets.status,tickets.date,tickets.question,tickets.title,users.position FROM tickets,users WHERE tickets.id='$existing' OR users.username='$username'"); $get = mysql_fetch_assoc($query); if(!$existing) { echo ' <div class="post"> <div class="postheader"><h1>Error</h1></div> <div class="postcontent"> <p>You have not enetered in a ticket ID. Please go back and do so.</p> </div> <div class="postfooter"></div> </div> '; } elseif($get['COUNT(id)'] < 1) { echo ' <div class="post"> <div class="postheader"><h1>Error</h1></div> <div class="postcontent"> <p>The ticket ID you are trying to use doesnt exist. Please go back or submit another ticket.</p> </div> <div class="postfooter"></div> </div> '; } elseif($get['tickets.ip']==$ip || $get['user.position'] >= 1) { $status["tickets.status"]["0"] = "Waiting for support..."; $status["tickets.status"]["1"] = "Waiting for user..."; $status["tickets.status"]["2"] = "Ticket Closed..."; $status["tickets.status"]["3"] = "Ticket Opened..."; echo ' <div class="post"> <div class="postheader"><h1>View Ticket Status - ID '. $get["id"] .'</h1></div> <div class="postcontent"> <p>Title: '. $get["tickets.title"] .' - Posted on: '. $get["tickets.date"] .'</p> <p>Ticket Status: '. $status[$get["tickets.status"]] .'</p> <p>Question: '. nl2br($get["tickets.question"]) .'</p> </div> <div class="postfooter"></div> </div> '; } else { echo ' <div class="post"> <div class="postheader"><h1>Error</h1></div> <div class="postcontent"> <p>This is not your ticket. You only have permission to view your tickets. Please go back.</p> </div> <div class="postfooter"></div> </div> '; } ?> </div> </div> </div> </body> </html> Hi guys, I need your help! I have two tables "sp_users" and "sp_schools" in the same database. Now I want to add column "time" from "sp_schools" to a phpfile which displays "sp_users". The column "time" should be after column "update". I made it upto here, but to get the second query and display Please help. I am devastated... Code: [Select] <?php $host="xxx"; // Host name $username="xxx"; // Mysql username $password="xxx"; // Mysql password $db_name="xxx"; // Database name $tbl_name="sp_users"; // Table name // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $sql="SELECT * FROM $tbl_name ORDER BY user_id"; $result=mysql_query($sql); ?> <style type="text/css"> <!-- .style2 {font-weight: bold} .style3 { font-family: Arial, Helvetica, sans-serif; color: #000033; } .style8 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; color: #003333; } --> </style> <title>User overview</title><table width="486" border="0" align="center" cellpadding="0" cellspacing="1"> <tr> <td width="427"> <div align="left"> <table width="486" border="1" cellspacing="0" cellpadding="3"> <tr> <td colspan="4"><div align="center" class="style1 style3"><strong>SchoolPorta Users </strong></div></td> </tr> <tr> <td width="26" align="center"><span class="style2">id</span></td> <td width="70" align="center"><span class="style2">Name</span></td> <td width="114" align="center"><span class="style2">Lastname</span></td> <td width="146" align="center"><span class="style2">Email</span></td> <td width="88" align="center"><span class="style2">Update</span></td> </tr> <?php while($rows=mysql_fetch_array($result)){ ?> <tr> <td><span class="style8"><? echo $rows['user_id']; ?></span></td> <td><span class="style8"><? echo $rows['user_first_name']; ?></span></td> <td><span class="style8"><? echo $rows['user_surname']; ?></span></td> <td><span class="style8"><? echo $rows['user_login']; ?></span></td> <td align="center"><a href="update.php?id=<? echo $rows['user_id']; ?>" class="style8">update</a></td> </tr> <?php } ?> </table> </div></td> </tr> </table> <div align="center"> <?php mysql_close(); ?> </div> Hi guys I need your help, I am trying already for days to sort it out but does not work. My file "pback.php" displays the mysql table "sp_users". I want to add the columns "school_name" and "school_address" from another table "sp_schools" (same database) at the right end of the displayed table in "pback.php" (after the column update) I tried with leftjoin but it does not work. Please help me. I am getting really frustrated. Thank you... Code: [Select] <?php $host="xxx"; // Host name $username="xxx"; // Mysql username $password="xxx"; // Mysql password $db_name="xxxx"; // Database name $tbl_name="sp_users"; // Table name // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $sql="SELECT * FROM $tbl_name ORDER BY user_id"; $result=mysql_query($sql); ?> <style type="text/css"> <!-- .style2 {font-weight: bold} .style3 { font-family: Arial, Helvetica, sans-serif; color: #000000; } .style10 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; color: #000000; } --> </style> <title>User overview</title><table width="486" border="0" align="left" cellpadding="0" cellspacing="1" bgcolor="#996600"> <tr> <td width="427"> <div align="left"> <table width="486" border="1" cellspacing="0" cellpadding="3"> <tr> <td colspan="4"><div align="center" class="style1 style3"><strong>SchoolPorta.com Users </strong></div></td> </tr> <tr> <td width="26" align="center"><span class="style2">id</span></td> <td width="70" align="center"><span class="style2">Name</span></td> <td width="114" align="center"><span class="style2">Lastname</span></td> <td width="146" align="center"><span class="style2">Email</span></td> <td width="88" align="center"><span class="style2">Update</span></td> </tr> <?php while($rows=mysql_fetch_array($result)){ ?> <tr> <td><span class="style10"><? echo $rows['user_id']; ?></span></td> <td><span class="style10"><? echo $rows['user_first_name']; ?></span></td> <td><span class="style10"><? echo $rows['user_surname']; ?></span></td> <td><span class="style10"><a href="mailto:<?php echo $rows['user_login']; ?>"><?php echo $rows['user_login']; ?></a></span></td> <td align="center"><a href="update.php?id=<? echo $rows['user_id']; ?>" class="style10">update</a></td> </tr> <?php } ?> </table> </div></td> </tr> </table> <div align="left"> <p> </p> <p> </p> <p> </p> <p> <?php mysql_close(); ?> </p> </div> mysql_query("UPDATE mods SET version='$version' AND name='$title' AND descritpion='$description' AND lastupdate='$date' WHERE id='$id'"); I don't think I'm doing it correctly. :/ Hi, I am currently working on a very detailed personal project during my vacation to keep me busy, but I have a problem, I am trying to create a unique id, without having the chance of a repetition of the id, even if its infinitely small. So I found the flickr ticket id system to be a good choice, since it was sequential and effective. My problem now is, how can I execute 2 queries simultaneously, given the hypothetical change that if I execute them with two separate queries (mysql_query), that there is the chance that another query could be executed in between the break, causing two id's to be the same. Since mysql_query can only execute a single query I am a bit stuck. I thought about possibly using CGI, but then again I have never used it, so I don't know its limitations. Can anyone suggestion anything to me for this problem, as to how I can execute two query strings in the same query. Hello, I'm fairly new to php and I'm working on a website for a chess club. I'd like the user to select all of his or her personal results from a general results table. The results table looks as follows: id name_white name_black result season_id 1 john pete 1-0 2010-2011 2 charles steve 0-1 2010-2011 3 richard john 1-0 2010-2011 etc 11 isaac john 1-0 2011-2012 12 william kate 0-1 2011-2012 13 john bobby 1-0 2011-2012 etc Let us say that the user wants to see all the results of player john in the 2010-2011 season. The following query (probably quite naively) gives me the error "supplied argument is not a valid MySQL result resource": Code: [Select] $result_personal = mysql_query("SELECT * FROM results WHERE name_white = '$seleted_name' AND name_black = '$selected_name' AND season id ='$selected_season'"); Could anyone help me steer in the right direction? Should I use a JOIN query instead? Or a IN query? All the best and thanks in advance for your time, Wouter. Hello
We have a database table that confirms the installations started and completed for our game... and I am looking to confirm how many installs start but never complete...
So, this is my current query...
SELECT description, ip from error_log where description like '%install%' order by ip; What I am trying to do is create a search box to search for a specific piece of information in my client database, say last name, or account number, invoice number, etc. is there a way i can use the keyword to match the query to multiple columns? here is my code, the script works if i use the $query to select just 1 column. but how do i add other columns to match it to? I know its where "different columns" LIKE search my problem is this line basically. Code: [Select] mysql_select_db("terra_elegante_operations", $con); $searchfor = $_GET['search_term']; $query = "select * from client_information where name_last like \"%$searchfor%\""; $result = mysql_query($query) or die("Couldn't execute query"); $row = mysql_fetch_array($result); echo $row['0']; Hi there, This is what I need to do, blow that is the code I have knocked up to do it but it doesn't seem to work. The main problem is the query that matches the atc callsigns to the pilots destinations.. can't fathom it myself. 1. Pull all the records from my database. 2. Assign their unique user id's, callsigns and destinations. 3. Execute a query in which you: SELECT * FROM CLIENTS WHERE (The 'clienttype' = 'ATC') AND match the callsign of the ATC users to the 'planned_destairport' of the 'clienttype' = 'PILOT'. For example if three people are going to Heathrow, then it would return 3 results. 4. Then do a mysql_num_rows of the result. 5. Lastly, execute a query that would update the 'atcarrivals' collumn in the database with the count number using the unique 'cid' as the identifier. All in a loop of course. // Selects all of the ATC Records. $atc_arrivals_selectquery = mysql_query ("SELECT * FROM CLIENTS"); // Starts the loop for fetching the records of the previous query. while($atc_arrivals_row = mysql_fetch_array($atc_arrivals_selectquery)){ // Sets the users cid, planned_destairport and callsign. $atc_cid = $atc_arrivals_row['cid']; $atc_destinations = $atc_arrivals_row['planned_destaiport']; $atc_callysign = $atc_arrivals_row['callsign']; // Searches the database and selects all records where the callsign is LIKE the destination airport. $atc_arrivals_check = mysql_query("SELECT * FROM CLIENTS WHERE clienttype = 'ATC' AND callsign LIKE '%$atc_destinations'"); // Counts previous query results. $atc_arrivals_count = mysql_num_rows($atc_arrivals_check); // Updates the atcarrivals column with the count.. $atc_arrivals_updatequery = mysql_query("UPDATE CLIENTS SET atcarrivals = '$atc_arrivals_count' WHERE cid = '$atc_cid' AND clienttype = 'ATC'"); // End loop. } Concerned columns are these: "cid" - Unique client id. "atcarrivals" - Number of arrivals from count. (This is the problem.) "planned_destairport" - Destination airport of pilot. Usually four letters long. IE. EGLL = Heathrow. Thanks. This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=315554.0 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. This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=305991.0 |