
bickyz
Members-
Posts
60 -
Joined
-
Last visited
Everything posted by bickyz
-
search multiple fields using multiple form elements
bickyz replied to bickyz's topic in PHP Coding Help
thank you very much Barand, now it displays results based on the form element selections. currently results are displayed in one column i.e. RESULT1 RESULT2 RESULT3 RESULT4 RESULT5 RESULT6 how can i display in three columns like RESULT1 RESULT2 RESULT3 RESULT4 RESULT5 RESULT6 also if there is not results I would like to display a mesage like "no results found", how can i achieve this. <?php $where = array(); $whereclause = ''; if (!empty($_POST['duration'])) { $val = intval($_POST['duration']); $where[] = "(acdur = $val)"; } if (!empty($_POST['transport'])) { $val = mysql_real_escape_string($_POST['transport']); $where[] = "(actransp = '$val')"; } if (!empty($_POST['datepicker'])) { $val = mysql_real_escape_string($_POST['datepicker']); $where[] = "(acdate = '$val')"; } // assuming you change you checkbox names if (isset($_POST['activity'])) { $val = join(",", array_map('intval', $_POST['activity'])); $where[] = "(incl_activity.incid IN ($val))"; } if (count($where)) $whereclause = "WHERE " . join(' AND ', $where); // and you search query is /*$query = "SELECT * FROM activities, incl_activity, inclusion JOIN incid $whereclause";*/ $query = "SELECT * FROM activities JOIN incl_activity on activities.acid = incl_activity.acid JOIN inclusion on incl_activity.incid = inclusion.incid JOIN teamleader on activities.tlid2 = teamleader.tlid $whereclause"; //echo $query; $test= mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_assoc($test)){ echo "<b>Title: </b>"; echo $row['actitle']; echo "<br />"; echo "<b>Team Leader: </b>"; echo $row['tlname']; echo "<br />"; echo "<b>Start Date: </b>"; echo $row['acdate']; echo "<br />"; echo "<b>Duration: </b>"; echo $row['acdur']; echo "<br />"; echo "<b>Cost: </b>"; echo $row['accost']; echo "<br />"; echo "<b>Incl. Activities: </b>"; echo $row['incdesc']; echo "<br />"; echo "<b>Transportation: </b>"; echo $row['actransp']; echo "<br />"; echo "------------"; echo "<br />"; } ?> -
search multiple fields using multiple form elements
bickyz replied to bickyz's topic in PHP Coding Help
my checkbox has value="incid", just for the test I tried changin value="testing" but still it gives same as before. <!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>Intranet Activities Search</title> <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.2/themes/smoothness/jquery-ui.css" /> <script src="http://code.jquery.com/jquery-1.9.1.js"></script> <script src="http://code.jquery.com/ui/1.10.2/jquery-ui.js"></script> <link rel="stylesheet" href="http://jqueryui.com/resources/demos/style.css" /> <script> $(function() { $("#datepicker").datepicker({dateFormat: 'yy-mm-dd'}); }); </script> <style type="text/css" media="screen"> table { font-size: 14px; } </style> </head> <body> <form id="form1" name="form1" method="post" action="listactivities.php"> <table width="400" border="0" cellspacing="0" cellpadding="0"> <tr> <td>Duration (days)</td> <td><select name="duration" id="duration"> <option selected="selected" value="">Any</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10</option> <option value="11">11</option> <option value="12">12</option> <option value="13">13</option> <option value="14">14</option> </select></td> </tr> <tr> <td> </td> <td> </td> </tr> <tr> <td width="45%">Date (YYYY-MM-DD)</td> <td width="55%"><input type="text" id="datepicker" name="datepicker" /> </td> </tr> <tr> <td> </td> <td> </td> </tr> <tr> <td>Transportation</td> <td><select name="transport" id="transport"> <option selected="selected" value="0">Any</option> <option value="included">included</option> <option value="excluded">excluded</option>> </select></td> </tr> <tr> <td> </td> <td> </td> </tr> <tr> <td>Fishing</td> <td><input name="activity[]" type="checkbox" id="chkfishing" value="incid" /></td> </tr> <tr> <td>Gliding</td> <td><input name="activity[]" type="checkbox" id="chkgliding" value="incid" /></td> </tr> <tr> <td>Flying</td> <td><input name="activity[]" type="checkbox" id="chkflying" value="incid" /></td> </tr> <tr> <td> </td> <td> </td> </tr> <tr> <td><input type="submit" name="searchbtn" id="searchbtn" value="Search" /></td> <td> </td> </tr> </table> </form> </body> </html> -
search multiple fields using multiple form elements
bickyz replied to bickyz's topic in PHP Coding Help
If I select no checkboxes then it gives: SELECT * FROM activities JOIN incl_activity on activities.acid = incl_activity.acid JOIN inclusion on incl_activity.incid = inclusion.incid JOIN teamleader on activities.tlid2 = teamleader.tlid If I select all three checkboxes then it gives: SELECT * FROM activities JOIN incl_activity on activities.acid = incl_activity.acid JOIN inclusion on incl_activity.incid = inclusion.incid JOIN teamleader on activities.tlid2 = teamleader.tlid WHERE (incl_activity.incid IN (0,0,0)) If I select two checkboxes then it gives: SELECT * FROM activities JOIN incl_activity on activities.acid = incl_activity.acid JOIN inclusion on incl_activity.incid = inclusion.incid JOIN teamleader on activities.tlid2 = teamleader.tlid WHERE (incl_activity.incid IN (0,0)) If I select onecheckboxes then it gives: SELECT * FROM activities JOIN incl_activity on activities.acid = incl_activity.acid JOIN inclusion on incl_activity.incid = inclusion.incid JOIN teamleader on activities.tlid2 = teamleader.tlid WHERE (incl_activity.incid IN (0)) -
search multiple fields using multiple form elements
bickyz replied to bickyz's topic in PHP Coding Help
I tried that already but still no results <?php $where = array(); $whereclause = ''; if (!empty($_POST['duration'])) { $val = intval($_POST['duration']); $where[] = "(acdur = $val)"; } if (!empty($_POST['transport'])) { $val = mysql_real_escape_string($_POST['transport']); $where[] = "(actransp = '$val')"; } // assuming you change you checkbox names if (isset($_POST['activity'])) { $val = join(",", array_map('intval', $_POST['activity'])); $where[] = "(incl_activity.incid IN ($val))"; } if (count($where)) $whereclause = "WHERE " . join(' AND ', $where); // and you search query is /*$query = "SELECT * FROM activities, incl_activity, inclusion JOIN incid $whereclause";*/ $query = "SELECT * FROM activities JOIN incl_activity on activities.acid = incl_activity.acid JOIN inclusion on incl_activity.incid = inclusion.incid JOIN teamleader on activities.tlid2 = teamleader.tlid $whereclause"; $test= mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_assoc($test)){ echo "<b>Title: </b>"; echo $row['actitle']; echo "<br />"; echo "<b>Team Leader: </b>"; echo $row['tlname']; echo "<br />"; echo "<b>Start Date: </b>"; echo $row['acdate']; echo "<br />"; echo "<b>Cost: </b>"; echo $row['accost']; echo "<br />"; echo "<b>Incl. Activities: </b>"; echo $row['incdesc']; echo "<br />"; echo "------------"; echo "<br />"; } ?> -
search multiple fields using multiple form elements
bickyz replied to bickyz's topic in PHP Coding Help
hi barand, i have changed sql query to: $query = "SELECT * FROM activities JOIN incl_activity on activities.acid = incl_activity.acid JOIN inclusion on incl_activity.incid = inclusion.incid JOIN teamleader on activities.tlid2 = teamleader.tlid $whereclause"; If I deselect the checkboxes and search then it will list the results whereas if I select chkbox then results page is blank. -
search multiple fields using multiple form elements
bickyz replied to bickyz's topic in PHP Coding Help
hi barand, thank you. I have changed all the checkbox to have incID in the value, now when doing a search it is listing quite large amount of data. -
search multiple fields using multiple form elements
bickyz replied to bickyz's topic in PHP Coding Help
thank you to Zane and Barand. If i select one check box and do search then it says Column 'incid' in where clause is ambiguous If i leave all check box unticked and do search then whole pile of data are dsiplayed, demo here http://bickyz.byethost13.com/ Following is the php part of my code. <?php $where = array(); $whereclause = ''; if (!empty($_POST['duration'])) { $val = intval($_POST['duration']); $where[] = "(acdur = $val)"; } if (!empty($_POST['transport'])) { $val = mysql_real_escape_string($_POST['transport']); $where[] = "(actransp = '$val')"; } // assuming you change you checkbox names if (isset($_POST['activity'])) { $val = join(",", array_map('intval', $_POST['activity'])); $where[] = "(incid IN ($val))"; } if (count($where)) $whereclause = "WHERE " . join(' AND ', $where); // and you search query is $query = "SELECT * FROM activities, incl_activity, inclusion $whereclause"; $test= mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_assoc($test)){ echo $row['acid']; echo "<br />"; echo $row['actitle']; } ?> In the Form for the check box, do I put 1 in the value ? <tr> <td>Fishing</td> <td><input name="activity[]" type="checkbox" id="chkfishing" value="1" /></td> </tr> <tr> <td>Gliding</td> <td><input name="activity[]" type="checkbox" id="chkgliding" value="1" /></td> </tr> <tr> <td>Flying</td> <td><input name="activity[]" type="checkbox" id="chkflying" value="1" /></td> </tr> -
search multiple fields using multiple form elements
bickyz replied to bickyz's topic in PHP Coding Help
it is not echo-ing anything, page is blank but if i disable all the php code except the code between "test code starts - ends" then the page says Hello Array When all the codes are enabled dreamweaver says there is a syntax error on this line if (count($where)) $whereclause = "WHERE " join(' AND ', $where); <?php //test code starts ini_set('display_errors',1); error_reporting(E_ALL); ?> <?php if (! empty($_POST['activity'])){ echo 'Hello, ' . $_POST['activity']; } //test code ends ?> <?php $dbhost = 'aa'; $dbuser = 'bb'; $dbpass = 'cc'; $dbname = 'dd'; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); mysql_select_db($dbname); ?> <?php $where = array(); $whereclause = ''; if (!empty($_POST['duration'])) { $val = intval($_POST['duration']); $where[] = "(acdur = $val)"; } if (!empty($_POST['transport'])) { $val = mysql_real_escape_string($_POST['transport']); $where[] = "(actransp = '$val')"; } // assuming you change you checkbox names if (isset($_POST['activity'])) { $val = join(",", array_map('intval', $_POST['activity'])); $where[] = "(incid IN ($val))"; } if (count($where)) $whereclause = "WHERE " join(' AND ', $where); // and you search query is $query = "SELECT * FROM activities $whereclause"; $test= mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_assoc($test)){ echo $row['acid']; echo $row['actitle']; } ?> -
search multiple fields using multiple form elements
bickyz replied to bickyz's topic in PHP Coding Help
hi, i have amended the code but nothing is displayed on the results page http://bickyz.byethost13.com/index.php -
search multiple fields using multiple form elements
bickyz replied to bickyz's topic in PHP Coding Help
hi, i have done the tables as is this correct way ? -
search multiple fields using multiple form elements
bickyz replied to bickyz's topic in PHP Coding Help
hi barand, thank you I have now changed the table to include separate fields for activities (Fishing, Gliding, Flying). How will be the search code, your help will be much appreciated, thank you. index.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>Intranet Activities Search</title> <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.2/themes/smoothness/jquery-ui.css" /> <script src="http://code.jquery.com/jquery-1.9.1.js"></script> <script src="http://code.jquery.com/ui/1.10.2/jquery-ui.js"></script> <link rel="stylesheet" href="http://jqueryui.com/resources/demos/style.css" /> <script> $(function() { $("#datepicker").datepicker({dateFormat: 'yy-mm-dd'}); }); </script> <style type="text/css" media="screen"> table { font-size: 14px; } </style> </head> <body> <form id="form1" name="form1" method="post" action="listactivities.php"> <table width="400" border="0" cellspacing="0" cellpadding="0"> <tr> <tr> <tr> <td>Duration (days)</td> <td><select name="duration" id="duration"> <option selected="selected" value="">Any</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10</option> <option value="11">11</option> <option value="12">12</option> <option value="13">13</option> <option value="14">14</option> </select></td> </tr> </tr> <tr> <td> </td> <td> </td> </tr> <tr> <td width="45%">Date (YYYY-MM-DD)</td> <td width="55%"><input type="text" id="datepicker" name="datepicker" /> </td> </tr> </tr> <tr> <td> </td> <td> </td> </tr> <tr> <td>Transportation</td> <td><select name="transport" id="transport"> <option selected="selected" value="0">Any</option> <option value="included">included</option> <option value="excluded">excluded</option>> </select></td> </tr> <tr> <td> </td> <td> </td> </tr> <tr> <td>Fishing</td> <td><input name="chkact[]" type="checkbox" id="chkfishing" value="YES" /></td> </tr> <tr> <td>Gliding</td> <td><input name="chkact[]" type="checkbox" id="chkgliding" value="YES" /></td> </tr> <tr> <td>Flying</td> <td><input name="chkact[]" type="checkbox" id="chkflying" value="YES" /></td> </tr> <tr> <td> </td> <td> </td> </tr> <tr> <td><input type="submit" name="searchbtn" id="searchbtn" value="Search" /></td> <td> </td> </tr> </table> </form> </body> </html> listactivities.php <?php ini_set('display_errors',1); error_reporting(E_ALL); ?> <?php $dbhost = 'aa'; $dbuser = 'bb'; $dbpass = 'cc'; $dbname = 'dd'; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); mysql_select_db($dbname); ?> <!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>Intranet Activities Search</title> </head> <body> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td> <?php $where = array(); $whereclause = ''; if (!empty($_POST['duration'])) { $val = intval($_POST['duration']); $where[] = "(acdur = $val)"; } if (!empty($_POST['datepicker'])) { $val = mysql_real_escape_string($_POST['datepicker']); $where[] = "(acdate = '$val')"; } if (!empty($_POST['transport'])) { $val = mysql_real_escape_string($_POST['transport']); $where[] = "(actransp = '$val')"; } // assuming you change you checkbox names if (isset($_POST['chkact'])) { $val = join("','", array_map('mysql_real_escape_string', $_POST['chkact'])); $where[] = "(chkact IN ('$val'))"; } if (count($where)) $whereclause = "WHERE " join(' AND ', $where); // and you search query is $result = "SELECT * FROM activities $whereclause"; ?> <?php //$search=$_POST["duration"]; //if ($search == "") //{ //echo "<p>You forgot to enter a search term"; //exit; //} //$result = mysql_query("SELECT * FROM activities WHERE acdur LIKE '%$search%'"); if(mysql_num_rows($result)) { $i=1; echo '<table><tr>'; while($r=mysql_fetch_array($result)) { $tleaderid=$r["tlid2"]; $title=$r["actitle"]; $duration=$r["acdur"]; $includes=$r["acincl"]; $exurl=$r["acurl"]; $startdate=$r["acdate"]; $transport=$r["actransp"]; $cost=$r["accost"]; $info=$r["acinfo"]; $acid=$r["acid"]; echo '<td style="padding: 10px; border-right: solid 2px #990000; border-bottom: solid 2px #990000; background-color: #eee;">'." <div><b><u>ACTIVITIES</u></b></div> <div><b>Title: </b>$title</div> <div><b>Duration: </b>$duration <b>days</b></div> <div><b>Activities Includes: </b>$includes</div> <div><b>External Website: </b><a href=$exurl>click here</a></div> <div><b>Start Date: </b>$startdate</div> <div><b>Transportation: </b>$transport</div> <div><b>Cost: £</b>$cost</div> <div><b>Team Leader ID: </b>$tleaderid</div> <div><b>Overview: </b>$info</div><br> ".'</td>'; if($i % 3 == 0) echo '</tr><tr>'; $i++; } echo '</tr></table>'; } else { echo '<div align=center style="margin:20px; font-family:Arial, Helvetica, sans-serif; font-size: 20px; font-weight:bold; color: #ae1919;">Your search did not match any results.</div>'; } ?> </td> </tr> </table> </body> </html> <?php mysql_free_result($result); ?> -
hi, for my school intranet im trying to create a page that will search and list the activities. i am trying to create a search page with the multiple form elements that will filter and list the records from the mysql database. So far i have been using a single field search and I have no idea where to start this multi search project. Here is the demo of how I currently search http://bickyz.byethost13.com/oldsearch1.php (search for the workd Hiking) This is a http://bickyz.byethost13.com/index.php new search page I am trying to create. Currently it can only search by the duration drop down but I would like multiple form elements to be used. Following is my Database. mysql table: teamleader mysql table: activities index.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>Intranet Activities Search</title> <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.2/themes/smoothness/jquery-ui.css" /> <script src="http://code.jquery.com/jquery-1.9.1.js"></script> <script src="http://code.jquery.com/ui/1.10.2/jquery-ui.js"></script> <link rel="stylesheet" href="http://jqueryui.com/resources/demos/style.css" /> <script> $(function() { $("#datepicker").datepicker({dateFormat: 'yy-mm-dd'}); }); </script> <style type="text/css" media="screen"> table { font-size: 14px; } </style> </head> <body> <form id="form1" name="form1" method="post" action="listactivities.php"> <table width="400" border="0" cellspacing="0" cellpadding="0"> <tr> <tr> <tr> <td>Duration (days)</td> <td><select name="duration" id="duration"> <option selected="selected" value="">Any</option> <option value="7">7</option> <option value="8">8</option> <option value="9">8</option> <option value="10">10</option> <option value="11">11</option> <option value="12">12</option> <option value="13">13</option> <option value="14">14</option> </select></td> </tr> </tr> <tr> <td> </td> <td> </td> </tr> <tr> <td width="45%">Date (YYYY-MM-DD)</td> <td width="55%"><input type="text" id="datepicker" name="datepicker" /> </td> </tr> </tr> <tr> <td> </td> <td> </td> </tr> <tr> <td>Transportation</td> <td><select name="transport" id="transport"> <option selected="selected" value="0">Any</option> <option value="included">included</option> <option value="excluded">excluded</option>> </select></td> </tr> <tr> <td> </td> <td> </td> </tr> <tr> <td>Fishing</td> <td><input name="chkfishing" type="checkbox" id="chkfishing" value="Fishing" /></td> </tr> <tr> <td>Gliding</td> <td><input name="chkgliding" type="checkbox" id="chkgliding" value="Gliding" /></td> </tr> <tr> <td>Flying</td> <td><input name="chkflying" type="checkbox" id="chkflying" value="Flying" /></td> </tr> <tr> <td> </td> <td> </td> </tr> <tr> <td><input type="submit" name="searchbtn" id="searchbtn" value="Search" /></td> <td> </td> </tr> </table> </form> </body> </html> listactivities.php <?php ini_set('display_errors',1); error_reporting(E_ALL); ?> <?php $dbhost = 'aaa'; $dbuser = 'bbb'; $dbpass = 'ccc'; $dbname = 'ddd'; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); mysql_select_db($dbname); ?> <!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>Intranet Activities Search</title> </head> <body> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td> <?php $search=$_POST["duration"]; if ($search == "") { echo "<p>You forgot to enter a search term"; exit; } $result = mysql_query("SELECT * FROM activities WHERE acdur LIKE '%$search%'"); if(mysql_num_rows($result)) { $i=1; echo '<table><tr>'; while($r=mysql_fetch_array($result)) { $tleaderid=$r["tlid2"]; $title=$r["actitle"]; $duration=$r["acdur"]; $includes=$r["acincl"]; $exurl=$r["acurl"]; $startdate=$r["acdate"]; $transport=$r["actransp"]; $cost=$r["accost"]; $info=$r["acinfo"]; $acid=$r["acid"]; echo '<td style="padding: 10px; border-right: solid 2px #990000; border-bottom: solid 2px #990000; background-color: #eee;">'." <div><b><u>ACTIVITIES</u></b></div> <div><b>Title: </b>$title</div> <div><b>Duration: </b>$duration <b>days</b></div> <div><b>Activities Includes: </b>$includes</div> <div><b>External Website: </b><a href=$exurl>click here</a></div> <div><b>Start Date: </b>$startdate</div> <div><b>Transportation: </b>$transport</div> <div><b>Cost: £</b>$cost</div> <div><b>Team Leader ID: </b>$tleaderid</div> <div><b>Overview: </b>$info</div><br> ".'</td>'; if($i % 3 == 0) echo '</tr><tr>'; $i++; } echo '</tr></table>'; } else { echo '<div align=center style="margin:20px; font-family:Arial, Helvetica, sans-serif; font-size: 20px; font-weight:bold; color: #ae1919;">Your search did not match any results.</div>'; } ?> </td> </tr> </table> </body> </html> <?php mysql_free_result($result); ?> In the display result I would like: ACTIVITIES Title: Duration: Activities Includes: External Website: Start Date: Transportation: Cost: Overview: Team Leader Name: (this info to come from teamleader table) Team Leaer Phone: (this info to come from teamleader table) Team Leader Email: (this info to come from teamleader table) I am not a php developer but have good understanding of modifying file for my needs. Any help would be much appreciated, thank you.