Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Yeah, sure, that's pretty easy. </p> <p>Here's what I would do:</p> <p>On your first page:</p> <pre><code>&lt;form action="mypage.php?searching=true" method="POST"&gt; &lt;input type="text" name="searchcategory" value=""/&gt; &lt;input type="submit" value="Search"/&gt; &lt;/form&gt; </code></pre> <p>On mypage.php:</p> <pre><code>&lt;table&gt; &lt;?php $sql=$db-&gt;prepare('SELECT * FROM mytable WHERE category=:category'); $sql-&gt;execute(array(':category'=&gt;$_REQUEST[searchcategory])); while ($row=$sql-&gt;fetch()) { //Here is where you will loop through all the results for your search. If //you had for example for each product name, price, and category, //you might do the following echo "&lt;tr&gt;&lt;td&gt;$row[name]&lt;/td&gt;&lt;td&gt;$row[price]&lt;/td&gt;&lt;td&gt;$row[category]&lt;/td&gt;&lt;/tr&gt;"; } ?&gt; &lt;/table&gt; </code></pre> <p>NOTES:</p> <ul> <li><p>I use mySQL...I'm not sure how you would do it with something else, but I would guess you could adapt the code for another sort of database. </p></li> <li><p>I generally use the <a href="http://php.net/manual/en/book.pdo.php" rel="nofollow">PDO</a> (accessing through prepare and execute)...my teacher said it was more secure. You can change that part of the code to however you connect to your DB. The code I use to connect looks something like (goes before the code above on mypage.php):</p> <pre><code>try { $db = new PDO("mysql:host=localhost;dbname=mydatabasename","username","password"); } catch (Exception $e) { echo "PDO connection error: " . $e-&gt;getMessage(); exit(1); } </code></pre></li> <li><p>They don't actually have to be separate pages. If you had both pages php (the first one not straight HTML), you could just change the content based on whether a variable (maybe called searching) was set to true or false. </p></li> </ul> <p>Let me know if any of that is unclear, and I'd be happy to help you out. Good luck! :)</p>
    singulars
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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