Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I display / filter search results with php / mysql
    primarykey
    data
    text
    <p>I'm very new to working with php / mysql coding, and I've got a slight problem with displaying results that are linked to an sql database.</p> <p>At the moment people search using the below code - which works fine - it's a drop down select box, but you can only select one option. I want it so the items are check boxes and you can select more than one item.</p> <p>I've included below the code that's used for when people input the data to the database - which are check boxes - and I have tried replacing the 'drop down select code' with this but it doesn't work.</p> <p>Does anybody know what code I have to use to replace the 'drop down select code' so that checkboxes are viewable and you can filter more than one item - I have also included the 'results page code', which displays the results and I'm thinking that 'ClientStage' needs adding to the 'check box code' somewhere.</p> <p>Sorry about my lack of knowledge with this and would be grateful for some help?</p> <hr> <p>DROP DOWN SELECT CODE</p> <hr> <pre><code>&lt;select name="ClientStage" id="ClientStage"&gt; &lt;option value=""&gt;&lt;/option&gt; &lt;?php include 'Easyspace.php'; $sql = 'SELECT * FROM `clienttype`;'; $rs = mysql_query($sql, $conn) or die ("error with sql query ".$sql); while ($row = mysql_fetch_array ($rs)){ $ClienttypeID = $row["ClienttypeID"]; $Clienttype = $row["Clienttype"]; echo '&lt;option value="' .$ClienttypeID. '"&gt;' .$Clienttype. '&lt;/option&gt;'; } ?&gt; &lt;/select&gt;&lt;/span&gt; </code></pre> <hr> <p>CHECK BOX CODE</p> <hr> <pre><code>&lt;table width="100%" border="0" cellspacing="1"&gt; &lt;?php $side=1; $sql = 'SELECT * FROM `clienttype`;'; $rs = mysql_query($sql, $conn) or die ("error with sql query ".$sql); while ($row = mysql_fetch_array ($rs)){ $ClienttypeID = $row["ClienttypeID"]; $Clienttype = $row["Clienttype"]; if ($side == 1){ $side = 2; echo '&lt;tr&gt;'; echo '&lt;td&gt;&lt;span class="RPATtext"&gt;&lt;input type="checkbox" name="Clients[]" value="' .$ClienttypeID. '"&gt; ' .$Clienttype. '&lt;/div&gt;&lt;/td&gt;'; } else { $side = 1; echo '&lt;td&gt;&lt;span class="RPATtext"&gt;&lt;input type="checkbox" name="Clients[]" value="' .$ClienttypeID. '"&gt; ' .$Clienttype. '&lt;/div&gt;&lt;/td&gt;'; echo '&lt;option value="' .$ClienttypeID. '"&gt;' .$Clienttype. '&lt;/option&gt;'; } } ?&gt; &lt;/table&gt; </code></pre> <hr> <p>RESULTS PAGE CODE</p> <hr> <pre><code> &lt;?php $Country = $_POST['Country']; $County = $_POST['County']; $ClientStage = $_POST['ClientStage']; $HealthIssues = $_POST['HealthIssues']; include 'Easyspace.php'; $sql = "SELECT * FROM `therapists` WHERE "; if ($Country){ $sql .= "`Country` = '$Country'"; } if ($County){ if ($Country){ $sql .= ' AND '; } $sql .= "`County` = '$County'"; } if ($ClientStage){ if ($Country or $County){ $sql .= ' AND '; } $sql .= "FIND_IN_SET('$ClientStage', Client_typeID)"; } if ($HealthIssues){ if ($Country or $County or $ClientStage){ $sql .= ' AND '; } $sql .= "FIND_IN_SET('$HealthIssues', IssuesID)"; } // echo $sql; $rs = mysql_query($sql, $conn) or die ("error with sql query ".$sql); while ($row = mysql_fetch_array ($rs)){ $TherapistID = $row['TherapistID']; $Title = $row['Title']; $FirstName = $row['First Name']; $LastName = $row['Last Name']; $PostCode = $row['PostCode']; echo '&lt;tr&gt;'; echo '&lt;td valign="middle" bgcolor="#D9E5C3" class="bodycopy"&gt;' .$Title. '&lt;/td&gt;'; echo '&lt;td valign="middle" bgcolor="#D9E5C3" class="bodycopy"&gt;' .$FirstName. '&lt;/td&gt;'; echo '&lt;td valign="middle" bgcolor="#D9E5C3" class="bodycopy"&gt;' .$LastName. '&lt;/td&gt;'; echo '&lt;td valign="middle" bgcolor="#D9E5C3" class="bodycopy"&gt;' .$PostCode. '&lt;/td&gt;'; echo '&lt;td height="34" valign="middle" bgcolor="#D9E5C3"&gt;&lt;p class="bodycopy"&gt;&lt;a href="Therapist.php?ID=' .$TherapistID. '"&gt;View more details&lt;/a&gt;&lt;/p&gt;&lt;/td&gt;'; echo '&lt;/tr&gt;'; } ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
    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