Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Try using this code,</p> <ul> <li>Changes what I have done are, created anchor's of your field name as table header</li> <li>by default the headers are in ASC order, if we click it, it changes to DESC order</li> <li>the sql query then uses the field name in GET to order the records</li> <li>the search term is also then saved in the GET request so that we can persist it ahead</li> <li>as search term is sometimes received in GET and sometimes in POST, have used REQUEST here, to get data</li> </ul> <p> <pre><code> if (!empty($search_name)){ if (strlen($search_name)&gt;=3) { if(empty($_REQUEST['searchTrm'])) $_REQUEST['searchTrm'] = 'price'; if(empty($_REQUEST['order'])) $_REQUEST['order'] = 'ASC'; $query = "SELECT * FROM `shoes` WHERE `brand/model` LIKE '".mysql_real_escape_string($search_name)."%' ORDER BY ".$_REQUEST['searchTrm']." ".$_REQUEST['order']; $query_run = mysql_query($query); $query_num_rows = mysql_num_rows($query_run); if ($query_num_rows&gt;=1) { echo $query_num_rows.' Results found:&lt;br&gt;'; ?&gt; &lt;table border=1&gt; &lt;tr&gt; &lt;td&gt; &lt;?php //use your sql field name as searchTrm value if($_REQUEST['searchTrm'] == 'brand/model' &amp;&amp; $_REQUEST['order'] == 'DESC') { ?&gt; &lt;a href='?searchTrm=brand/model&amp;order=ASC&amp;search_name=&lt;?php echo $_REQUEST['search_name']?&gt;' title = 'ASC'&gt;Brand Name&lt;/a&gt; &lt;?php } else { ?&gt; &lt;a href='?searchTrm=brand/model&amp;order=DESC&amp;search_name=&lt;?php echo $_REQUEST['search_name']?&gt;' title = 'DESC'&gt;Brand Name&lt;/a&gt; &lt;?php } ?&gt; &lt;/td&gt; &lt;td&gt; &lt;?php if($_REQUEST['searchTrm'] == 'price' &amp;&amp; $_REQUEST['order'] == 'DESC') { ?&gt; &lt;a href='?searchTrm=price&amp;order=ASC&amp;search_name=&lt;?php echo $_REQUEST['search_name']?&gt;' title = 'ASC'&gt;Price&lt;/a&gt; &lt;?php } else { ?&gt; &lt;a href='?searchTrm=price&amp;order=DESC&amp;search_name=&lt;?php echo $_REQUEST['search_name']?&gt;' title = 'DESC'&gt;Price&lt;/a&gt; &lt;?php } ?&gt; &lt;/td&gt; &lt;td&gt;Image&lt;/td&gt; &lt;/tr&gt; &lt;?php while ($query_row = mysql_fetch_array($query_run)) { $picture = $query_row['picture']; ?&gt; &lt;tr&gt; &lt;td&gt;&lt;?php echo $query_row['brand/model'];?&gt;&lt;/td&gt; &lt;td&gt;&lt;?php echo $query_row['price'];?&gt;&lt;/td&gt; &lt;td&gt;&lt;img src='image.php?id=&lt;?php echo $query_row['id'];?&gt;' width='300' height='200' /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;?php } ?&gt; &lt;/table&gt; &lt;?php } else { echo 'No Results Found.'; } } else { echo 'Text field must be more than 3 characters.'; } } else { echo 'Text Field Cannot be Empty!'; } } </code></pre>
    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.
 

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