php - How to display results from form search, connected to database? -


the code i'm going present not working. no results displaying if condition. else are. when call $service_id alone echo, gives me id searched when used in close: service_id = '$service_id' nothing displayed.

<form method="get" name="pesquisa" id="inserrifo" action="/services.php">     <input class="procurasalgo" id='pesqsign' name="keyword" value="<?php echo $keyword;?>" placeholder="inserir palavra"/><label for="pesqsign" id="pesqsigne"><img class="lupapesquisa" src="/img/search-26.png" /></label>     <select name="services">         <option disabled selected value=''>serviços</option>         <?php             $res = $dal->mysqlquery("select * services");             while($row = mysql_fetch_assoc($res)){                 echo "<option value='".$row['serv_id']."'>".$row['serv_name']."</option>";             }         ?>     </select>     <select name='distritos'>         <option disabled selected value=''>portugal</option>         <?php             $res = $dal->mysqlquery("select * distritos");             while($row = mysql_fetch_assoc($res)){                 echo "<option value='".$row['d_id']."'>".$row['d_nome']."</option>";             }         ?>     </select>     <button>procurar</button> </form> 

" placeholder="inserir palavra"/> serviços mysqlquery("select * services"); while($row = mysql_fetch_assoc($res)){ echo "".$row['serv_name'].""; } ?> portugal mysqlquery("select * distritos"); while($row = mysql_fetch_assoc($res)){ echo "".$row['d_nome'].""; } ?> procurar

<?php         $service_id = $_get['services'];     $district_id = $_get['distritos'];     $keywords = $_get['keyword'];       if ($service_id != '' || $district_id != '' || $keywords != '') {      $result = $dal->mysqlquery("select * users, services, distritos, users_services u_id = user_id && service_id = '$service_id' && distrito_id = '$district_id' ");      $row = mysql_fetch_assoc($result);      while($row = mysql_fetch_assoc($result)) {      $img_user = $row['u_foto'];           echo "<div class='services'><img src='http://mufip.pt/images/userimages/avatars/".$img_user."' /><br /><h5>".$row['u_name']."<h5><h6>".substr($row['u_descricao'],0, 140)."</h6></div>";          } //while      } //if      else {      $result = $dal->mysqlquery("select * users, services, distritos, users_services u_id = user_id && service_id = serv_id && distrito_id = d_id order rand()");      $num = mysql_numrows($result);     echo $num." resultados<br />";      while($row = mysql_fetch_assoc($result)) {      $img_user = $row['u_foto'];      echo "<div class='services'><img src='http://mufip.pt/images/userimages/avatars/".$img_user."' /><br /><h5>".$row['u_name']."<h5><h6>".substr($row['u_descricao'],0, 140)."</h6></div>";          } //while      } //else      ?> 

if ($service_id != '' || $district_id != '' || $keywords != '') { 

line checking presence of fields between three. in other words logical check give true when $service_id or $district_id or $keywords not empty. suppose, user entered values "keywords" , in page, value of $keywords , $service_id , $district_id empty.

since 1 of them (here $keywords) not empty, if statement return true , program control move inside it.

however , in sql query using , condition , requires valid or non-empty value in service_id & distrito_id columns. since 1 of them might remain empty, query produce no result.

to debug situation, select value 1 of drop-down , use echo statement print query inside if block.


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -