php - Object of class mysqli_result could not be converted to string (search criteria) -


im new in php , trying make criteria search based on tutorial in youtube used mysql , im try in mysqli.. right got error object of class mysqli_result not converted string . error in line $result .= "and tblpartner.companystate = '{$location}' ";. proper way write codes? below codes..

<?php  $result = $mysqli->query("select tbljob.jobid, tbljob.title, tbljob.position1, tbljob.position2, tbljob.position3, tbljob.description1, tbljob.requirement1, tbljob.mincgpa1, tbljob.alowance1, tbljob.status, tbljob.pdate, tbljob.companyid, tblpartner.companyname, tblpartner.companyaddress, tblpartner.companycity, tblpartner.companystate tbljob inner join tblpartner on tbljob.companyid = tblpartner.companyusername tbljob.status = 'active' order tbljob.pdate desc");  if (isset($_post['submit'])) {    $location = mysqli_real_escape_string($mysqli, $_post['location']);    $result .= "and tblpartner.companystate = '{$location}' ";  }  if ($result->num_rows != 0) {     while($row = mysqli_fetch_array($result)) {  ?>   <div class="sub">position: <?php echo $row['position1']; ?></div>           <div class="sub">position 2 :<?php echo $row['position2']; ?></div>  <div class="sub">position 3 :<?php echo $row['position3']; ?><br>&nbsp;</br></div>  //other output **trying reduce code <?php } } ?> 

this search box

<form name = "searchform"  method="post" action="t.html">                     <p><select id="location" name="location" class="form-control placeholder1">                             <option value="" selected>all location</option>                             <option value="sabah">sabah</option>                             <option value="perak">perak</option>                             <option value="pahang">pahang</option>                         </select></p>                      <p><input type="submit" value="search" id="btnsubmit" name="submit" class="btn btn-success" /></p>  </form> 

you're running query before if condition gets considered. why $result mysqli object. need let if condition gets considered before query gets run.

if (isset($_post['submit'])) {    $location = mysqli_real_escape_string($mysqli, $_post['location']);    $where_sql = " , tblpartner.companystate = '{$location}' ";  } else {   $where_sql = ""; }  $result = $mysqli->query("select tbljob.jobid, tbljob.title, tbljob.position1, tbljob.position2, tbljob.position3, tbljob.description1, tbljob.requirement1, tbljob.mincgpa1, tbljob.alowance1, tbljob.status, tbljob.pdate, tbljob.companyid, tblpartner.companyname, tblpartner.companyaddress, tblpartner.companycity, tblpartner.companystate tbljob inner join tblpartner on tbljob.companyid = tblpartner.companyusername tbljob.status = 'active'".$where_sql." order tbljob.pdate desc"); 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -