Note that there are some explanatory texts on larger screens.

plurals
  1. POShowing result based on url PDO
    primarykey
    data
    text
    <p>I am fetching results from database using <strong>PDO</strong> with url query string</p> <p><code>url: index.php?bType=doctor&amp;loc=asia|india</code></p> <p><strong>CODE:</strong></p> <pre><code>$bind = array(); $str=explode('|',$_GET[loc]); foreach ($str as $loc) { $bloc[] = $loc; } $loca = implode("','", $bloc); $btype=$_GET['bType']; $sqlsb = "SELECT * FROM t_business WHERE 1=1"; if(isset($_GET['bType'])){ $sqlsb .=" AND type like :btype"; $bind['btype']='%'. $btype .'%';} </code></pre> <p>if(isset($_GET['loc'])){ $sqlsb .=" AND location IN (:loca)"; $bind['loca']="'$loca'";}</p> <pre><code>$qsb = $db-&gt;prepare($sqlsb); $qsb-&gt;execute($bind); </code></pre> <hr/> <p>above code fetches nothing..</p> <p><code>print_r($bind)</code> shows <code>Array ( [btype] =&gt; doctor [loca] =&gt; asia','india )</code></p> <p>If i do it without using prepared it works.</p> <p>I am writing this code for refine search filters.</p> <p>Thanks</p> <p><strong>UPDATE</strong></p> <p>AS <strong>CoursesWeb</strong> anwserd i did changes</p> <pre><code>if(isset($_GET['bType'])){ $sqlsb .=" AND type like :btype"; $bind['btype']='%'. $btype .'%';} if(isset($_GET['loc'])){ $sqlsb .=" AND location IN (:loca)"; $bind['loca']="'$loca'";} </code></pre> <p>it works for <code>:btype</code> but not with <code>:loca</code></p> <p><code>print_r($bind)</code> shows <code>array ( [btype] =&gt; %doctor% [loca] =&gt; 'asia','india' )</code></p> <p>Need to do something better with <code>loc</code> than using implode..think so </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload