Note that there are some explanatory texts on larger screens.

plurals
  1. POTrouble pulling data out of an sql table
    primarykey
    data
    text
    <p>I have a html form tat my user can use to search through a table in my MYSQL database. By default if you just hit go it will display the entire table, however I would like them to be able select certain fields and my php form to search via the fields that are filled in.</p> <p>I seem to be unable to find a way of doing this without writing a seperate query for all 11 inputs in the different combinations they could be entered in, which comes out at a total of 76 queries.. </p> <p>If anyone has a way to simplify this I would love any advice. </p> <p>I have tried just running a query with the AND operator but that doesnt work as some variables can be left empty and that will return no result, not sure if that is what is upposed to happen, but that is what is happening. </p> <p>my html and php:</p> <p><a href="http://jsbin.com/oquwid/1/edit" rel="nofollow">http://jsbin.com/oquwid/1/edit</a></p> <p>PHP</p> <pre><code>$sql = "SELECT * FROM ".$tbl_name." WHERE fname='".$fname."' and lname='".$lname."' and city='".$city."' and phone='".$pohne."' and interest_inet='".$internet."' and interest_tv='".$television."' and interest_voice='".$voice."' and submission_ip='".$ip."' and inquiry_handled='".$handled."'"; $result = mysql_query($sql); echo "&lt;table border='1'&gt;"; echo "&lt;tr&gt;"; $i = 0; while ($i &lt; mysql_num_fields($result)) { $meta = mysql_fetch_field($result, $i); echo "&lt;th&gt;".$meta-&gt;name."&lt;/th&gt;"; $i++; } while ($row = mysql_fetch_row($result)) { echo '&lt;tr&gt;'; foreach($row as $item) { echo "&lt;td&gt;".$item."&lt;/td&gt;"; } echo '&lt;/tr&gt;'; echo $row; } echo "&lt;/table&gt;"; </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.
 

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