Hi folks,
Sorry to be such a pest only days after my last glitch (hard to believe I’ve been writing code for 10 years, must be old age catching up on me at last) was resolved so masterfully on thus forum.
I have a simple form that queries a MySQL db…
…to allow a user search by county for a musician who plays a particular instrument to join their band.
Thanks to some very helpful folks here a few days ago, I managed to get a query working that will return a result if the user selects one of the ‘real’ options.
My problem now is what to do if the user selects ‘All’ as an option. In other words they want to see all the musicians in all the counties or all the guitarists in all the counties and so on.
My PHP on the existing qresults.php page that works is:
So, how do I expand this to allow for NULL values?
It should be noted here that in the above example I’m using 2 fields (county and instrument), when I eventually get this working I’ll be using around 5 more fields (e.g. style, songwriter, etc) but for the purposes of keeping it uncluttered here I chopped it down to 2. From my old VB days I tried getting this to work with If, Then, Else statements but realised that by the time I had the remaining fields included I’d have a heap of unwieldy code to deal with.
Again, I truly appreciate the time people take with the brain dead like me.
Many thanks!!
Michael.
Sorry to be such a pest only days after my last glitch (hard to believe I’ve been writing code for 10 years, must be old age catching up on me at last) was resolved so masterfully on thus forum.
I have a simple form that queries a MySQL db…
Code:
<form name="form1" method="POST" action="qresults.php">
<p>Instrument:
<input name="instrument" type="text" id="instrument">
<p>
<select name="county" id="county">
<option value="" selected>All
<option value="county1">county1
<option value="county2">county2
</select>
<p>Instrument:
<select name="instrument" id="instrument">
<option value="" selected>All</option>
<option value="Guitar">Guitar</option>
<option value="Bass">Bass</option>
<option value="Drums">Drums</option>
</select>
</p>
Rest of form here….
Thanks to some very helpful folks here a few days ago, I managed to get a query working that will return a result if the user selects one of the ‘real’ options.
My problem now is what to do if the user selects ‘All’ as an option. In other words they want to see all the musicians in all the counties or all the guitarists in all the counties and so on.
My PHP on the existing qresults.php page that works is:
Code:
$sql =
"SELECT *
FROM $table_name WHERE county='" . $_POST['county'] . "' AND instrument='" . $_POST['instrument'] . "'";
So, how do I expand this to allow for NULL values?
It should be noted here that in the above example I’m using 2 fields (county and instrument), when I eventually get this working I’ll be using around 5 more fields (e.g. style, songwriter, etc) but for the purposes of keeping it uncluttered here I chopped it down to 2. From my old VB days I tried getting this to work with If, Then, Else statements but realised that by the time I had the remaining fields included I’d have a heap of unwieldy code to deal with.
Again, I truly appreciate the time people take with the brain dead like me.
Many thanks!!
Michael.