nicedad Posted November 12, 2015 Share Posted November 12, 2015 Hello everyone,I'm trying to create a search drop down menu to search a Mysql table, unfortunately the search does work. even though it was working but I don't know what I did in wrong way.can anyone help and locate the mistake, please notice that there is not any error. it just does not retrieve any record from the DB. <?php session_start(); require_once("common/DAO.php"); require_once("./common/config.php"); require_once("classes/class.jobs.php"); require_once("services/MemberService.php"); $objUser = new Jobs(); $location = ""; $Jqualify = ""; $searchCondition = ""; if(!empty($_POST["search"])) { foreach($_POST["search"] as $k=>$v){ if(!empty($v)) { $queryCases = array("location","Jqualify"); if(in_array($k,$queryCases)) { } switch($k) { case "location": $location = $v; $searchCondition .= "where location LIKE '" . $v . "%'"; break; case "Jqualify": $Jqualify = $v; if(strlen($searchCondition)>1) $searchCondition .= "and Jqualify LIKE '" . $v . "%'"; else $searchCondition .= "where Jqualify LIKE '" . $v . "%'"; break; } } } } $userList = $objUser->getJobs($searchCondition); ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Integrationsdienste</title> <link href="css/style.css" rel="stylesheet" type="text/css" /> <meta name="description" content=""> <meta name="author" content="templatemo"> <link href="css/bootstrap.min.css" rel="stylesheet"> <link href="css/templatemo_justified.css" rel="stylesheet"> <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries --> <!--[if lt IE 9]> <script src="js/html5shiv.js"></script> <script src="js/respond.min.js"></script> <![endif]--> <style> .btnjoin { padding: 5px 20px; border-radius: 4px; margin-bottom: 10px; color: #F0F8FF; background-color: #3CB6CB; border: none; cursor: pointer; } .table-striped>tbody>tr:nth-child(odd)>td, .table-striped>tbody>tr:nth-child(odd)>th { background-color: #DDDDDD; } .table-striped>tbody>tr:nth-child(odd)>th { background-color: #bbb; } .space5 { margin-top: 5px; } p.test { width: 27em; word-wrap: break-word; } </style> </head> <body> <div id="container" class="container"> <a href="http://www.templatemo.com/preview/templatemo_382_simplex" rel="nofollow"> <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" width="468" height="60" <param name="movie" value="banner.swf"<param name="quality" value="high" /><param name="bgcolor" value="#ffffff"/> <embed src="banner.swf" quality="high" bgcolor="#ffffff" width="1140" height="300" name="banner" align="" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"> </embed></object> </a> <ul class="nav nav-justified"> <ul class="nav nav-justified"> <li class=""><a href="index.html">Home</a></li> <li><a href="about.html">Über Uns</a></li> <li><a href="services.html">Service</a></li> <li><a href="datenbank.php">Datenbank</a></li> <li><a href="jobs.html">Jobs</a></li> <li><a href="contact.html">Contact</a></li> </ul> <div class="row space30"> <!-- row 1 begins --> <div class="col-md-12"> <a href="login.php" class="btnjoin pull-right" style="padding:5px 29px;margin-right:10px;"> Login/ Anmelden</a> <a href="jobs.php" class="btnjoin pull-right">Jobs</a> <a href="datenbank.php" class="btnjoin pull-right">Bewerber</a> <?php if(!empty($userList["total_records"])) { ?> <div class="left"> <span style="color: #240CF7"><strong> <?php echo $userList["total_records"]; ?></strong></span> <span style="color: #0E3CEF; font-size: 14px;">Jobs verfügbar </span></div> <?php } ?> <form method="post"> <div class="row space30"> <!-- row 2 begins --> <div class="col-md-12 text-center"> <?php $userCity = $objUser->getJobByLocation(); ?> <select name="search[location]" style="min-width: 150px;padding: 3px;margin-right:25px;"> <option value="">Kanton auswählen</option> <?php if(!empty($userCity)) { foreach($userCity as $k=>$v) { ?> <option value="<?php echo $userCity[$k]["location"]; ?>" <?php if($userCity[$k]["location"] == $location) { echo "selected"; } ?>><?php echo $userCity[$k]["location"]; ?></option> <?php } } ?> </select> <?php $userOccupation = $objUser->getQualification(); ?> <select name="search[location]" style="min-width: 150px;padding: 3px;"> <option value="">Beruf auswählen</option> <?php if(!empty($userOccupation)) { foreach($userOccupation as $k=>$v) { ?> <option value="<?php echo $userOccupation[$k]["Jqualify"]; ?>" <?php if($userOccupation[$k]["Jqualify"] == $Jqualify) { echo "selected"; } ?>> <?php echo $userOccupation[$k]["Jqualify"]; ?></option> <?php } } ?> </select> <input type="submit" name="go" value="Search" style="border-color: none;border: 2px outset buttonface;padding: 2px 45px;margin-left: 20px;" > <input type="reset" value="Reset" style="border-color: none;border: 2px outset buttonface;padding: 2px 45px;margin-left: 10px;" onclick="window.location='jobs.php'"> </div> </div> <?php if(!empty($userList)) { ?> <div class="row space5"> <!-- row 3 begins --> <div class="col-md-12"> <table class="table table-striped"> <tr> <th style="width: 10%;">Firmenname</th> <th style="width: 10%;">Job Title</th> <th style="width: 30%;">Job Beschreibung</th> <th style="width: 10%;">Erfahrung</th> <th style="width: 10%;">Kanton</th> <th style="width: 10%;">Branche</th> <!--<th style="width: 10%;">Job Type</th>!--> <!--<th style="width: 10%;">Qualifikation</th>!--> <th style="width: 10%;">Vertragsart</th> <th style="width: 10%;">Gehalt/ Stunde</th></tr> <?php foreach($userList as $i => $value) { if(is_numeric($i)) { ?> <tr> <td><?php echo $userList[$i]["comp_name"]; ?></td> <td><?php echo $userList[$i]["jobtitle"]; ?></td> <!--<?php echo $userList[$i]["job_description"];?></td>!--> <td><?php echo nl2br($userList[$i]["job_description"], "<br/>\n"); ?></td> <td><?php echo $userList[$i]["minexp"]; ?> - <?php echo $userList[$i]["maxexp"]; ?></td> <td><?php echo $userList[$i]["location"]; ?></td> <td><?php echo $userList[$i]["Jqualify"]; ?></td> <td><?php echo $userList[$i]["JContract"]; ?></td> <!--<td><?php echo $userList[$i]["Jtype"]; ?></td>!--> <!--<td><?php echo $userList[$i]["Jqualify"]; ?></td>!--> <td><?php echo $userList[$i]["minsal"]; ?> - <?php echo $userList[$i]["maxsal"]; ?></td> </tr> <?php } }//for close ?> </table> </div> </div> <?php if(!empty($userList["perpage"])) { ?> <div class="pagination center"><?php echo $userList["perpage"]; ?></div> <?php } ?> <?php }//if close ?> </form> <!-- Site footer --> <div class="footer"> <p><center>© Copyright 2015 | Ausländer und Integrations Dienste | <a rel="nofollow" href="http://www.a-Integrationsdienste.ch">www.a-Integrationsdienste.ch</a></center> </div> </div> <!-- /container --> <!-- Bootstrap core JavaScript ================================================== --> <!-- Placed at the end of the document so the pages load faster --> </ul> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/299459-search-a-mysql-table-using-php/ Share on other sites More sharing options...
QuickOldCar Posted November 13, 2015 Share Posted November 13, 2015 Hard to say because do not see the rest of the code for all your includes. //This part does nothing useful as is $queryCases = array("location","Jqualify"); if(in_array($k,$queryCases)) { } switch($k) { case "location": $location = $v;//why define this as $v and not use it $searchCondition .= " where location LIKE '" . $v . "%'"; break; case "Jqualify": $Jqualify = $v;//why define this as $v and not use it if(strlen($searchCondition)>1){ $searchCondition .= " and Jqualify LIKE '" . $v . "%'"; }else{ $searchCondition .= " where Jqualify LIKE '" . $v . "%'"; } break; } echo out the value of $searchCondition do a var_dump() on $userList and post it here Quote Link to comment https://forums.phpfreaks.com/topic/299459-search-a-mysql-table-using-php/#findComment-1526298 Share on other sites More sharing options...
nicedad Posted November 16, 2015 Author Share Posted November 16, 2015 Hi QuickOldCar, thanx for your replay, you're right the Problem has to do with another file. Quote Link to comment https://forums.phpfreaks.com/topic/299459-search-a-mysql-table-using-php/#findComment-1526491 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.