Jump to content

mikemcg36

New Members
  • Posts

    7
  • Joined

  • Last visited

    Never

Everything posted by mikemcg36

  1. Sorry, I noticed some of this code is not necessary so I took some out and added a little myself. Here are the important lines if someone can combine the 2 select drop downs to query the table data. <?php if ($_REQUEST["city"]<>'') { $search_city = " AND city='".mysql_real_escape_string($_REQUEST["city"])."'"; } if ($_REQUEST["full_name"]<>'') { $search_name = " AND full_name='".mysql_real_escape_string($_REQUEST["full_name"])."'"; } 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); ?>
  2. 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: 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: <?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>
  3. Figured it out! It was a problem with the way I concatenated the date, I used this format and it worked. $date = $year ."-". $month ."-". $day;
  4. Sorry, can you explain the easiest way to echo the date input?
  5. I am trying to insert a date into a mySQL table from html drop downs with php. Right now when I enter the date it goes into the database as 0000-00-00. Can anybody see why it might be doing this? My html: <label for='birthdate' >Birthdate (Optional):</label><br/> <select name='month' id='month' value='<?php echo $fgmembersite->SafeDisplay('month') ?>'> <option value="01" selected="January">January</option> <option value="02">February</option> <option value="03">March</option> etc... </select> <select name='day' id='day' value='<?php echo $fgmembersite->SafeDisplay('day') ?>'> <option value="01" selected="1">1</option> <option value="02">2</option> <option value="03">3</option> etc... </select> <select name='year' id='year' value='<?php echo $fgmembersite->SafeDisplay('year') ?>'> <option value="2010" selected="2010">2010</option> <option value="2009">2009</option> <option value="2008">2008</option> etc... </select> And my php to collect info: $formvars['birthdate'] = $this->Sanitize($_POST['year'], $_POST['month'], $_POST['day']); php where I make table: "birthdate DATE NOT NULL ,". php to insert into mysql: $insert_query = 'insert into '.$this->tablename.'( name, address, birthdate, sex, program, guide, email, username, password, confirmcode ) values ( "' . $this->SanitizeForSQL($formvars['name']) . '", "' . $this->SanitizeForSQL($formvars['address']) . '", "' . $this->SanitizeForSQL($formvars['birthdate']) . '", "' . $this->SanitizeForSQL($formvars['sex']) . '", "' . $this->SanitizeForSQL($formvars['program']) . '", "' . $this->SanitizeForSQL($formvars['guide']) . '", "' . $this->SanitizeForSQL($formvars['email']) . '", "' . $this->SanitizeForSQL($formvars['username']) . '", "' . md5($formvars['password']) . '", "' . $confirmcode . '" )'; Thank you!
  6. Not sure I completely understand this jquery method. Is there no way to do it how I am doing it?
  7. Hello, I need help filtering an SQL query based on the combination of drop down menus. I have tried using this code found in another thread but I am still getting all rows selected. Any ideas?? Thank you. Here is my html <form name="xml.php" method="POST"> <input type="button" id="showmarkers" value="Show Markers" /> <select name="meetingType"> <option value="All Types" selected="All Types">All Types</option> <option value="fun">fun</option> <option value="work">work</option> </select> <select name="meetingDay"> <option value="All Days" selected="All Days">All Days</option> <option value="Monday">Monday</option> <option value="Tuesday">Tuesday</option> <option value="Wednesday">Wednesday</option> <option value="Thursday">Thursday</option> <option value="Friday">Friday</option> <option value="Saturday">Saturday</option> <option value="Sunday">Sunday</option> </select> <select name="meetingTime"> <option value="All Times" selected="All Times">All Times</option> <option value="Early">Early</option> <option value="Noon">Noon</option> <option value="Late">Late</option> </select> </form> And the PHP: $whereClauses = array(); if (! empty($_POST['meetingType'])) $whereClauses[] ="meetingType='".mysql_real_escape_string($_POST['meetingType'])."'"; if (! empty($_POST['meetingDay'])) $whereClauses[] ="meetingDay='".mysql_real_escape_string($_POST['meetingDay'])."'"; if (! empty($_POST['meetingTime'])) $whereClauses[] ="meetingTime='".mysql_real_escape_string($_POST['meetingTime'])."'"; $where = ''; if (count($whereClauses) > 0) { $where = ' WHERE '.implode(' AND ',$whereClauses); } $resultID = mysql_query("SELECT * FROM meetings".$where);
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.