I am trying to create a plan for users based on their top 3 choices. I want to display results all together on a results page. I have database populated and form (check boxes) created. I cannot seem to put the two together. I want them to choose 3 choices and upon submission return results based on those choices. please advise. (please note this is not to populate data in a database but to retrieve data from based on user section)

Recommended Answers

All 7 Replies

Which part are you having trouble with? Are you getting the checkbox values? Do you need help with the SQL? Note that you only need one query. Something like:

select * from table where column = value1 or column = value2 or column = value3

i need help with the display of results. I have the above sql statment in my form. when testing, it only displays the first checkbox checked.

Post some code and we can help you fillin the gaps

It's probably how you are building your query that's the problem.

You have to start with a basic query, then for each checkbox that is checked, add the appropriate bit to the end of the query, then finally pass that to your database.

so, something like this perhaps

$sql ='select your fields from yourtable where 1=1'

then a select case type section or set of ifs which for each true case adds the next bit this way
if (checkboxA)
$sql = $sql.'and fieldA=somevalue';
if (checkboxB)
$sql=$sql.'and fieldB=othervalue';

and so on. I've written this in a hurry, it's not correct but it gives you the sort of ideas to use.

In the SQL statement above, the three items are there, but it is set up to only return ONE item. If you change the OR to AND, or just use commas, since you want all three, you should get the info you need.

Tom

here is the code

$dbhandle = mysql_connect($hostname, $username, $password)
  or die("Unable to connect to MySQL");
echo "Connected to MySQL<br>";
?>
<?php
$selected = mysql_select_db("telcom",$dbhandle)
  or die("Could not select");


$result = mysql_query("SELECT code, name, hours FROM courses WHERE silver = 'y'")
or die(mysql_error());  

$row = mysql_fetch_array( $result );

?>


<form action="results.php" method="post">
<p>Choose Proficieny Level</p>
<table width="750" border="0" cellspacing="0" cellpadding="3">
  <tr>
<td>
 <input type="checkbox" name="Silver" />Silver (64 Credit Hours)</td>
<td><input type="checkbox" name="gold"  />   Gold (96 Credit Hours)</td>
<td><input type="checkbox" name="Platinum" />   Platinum (128 Credit Hours)</td>
<td><input type="checkbox" name="Master"  />   Master (168 Credit Hours)</td>
  </tr>
</table>
<p>Choose Top 3 Primary Functions</p>
<table width="750" border="0" cellspacing="0" cellpadding="5">
  <tr>
<td><input type="checkbox" name="TEM Sourcing" />TEM Sourcing</td>
<td><input type="checkbox" name="TEM Invoice Processing/Auditing"/>TEM Invoice Processing/Auditing</td>
<td><input type="checkbox" name="TEM Service Ordering" />TEM Service Ordering</td>
</tr>
  <tr>
<td><input type="checkbox" name="TEM Inventory Validation" />TEM Inventory Validation</td>
<td><input type="checkbox" name="TEM Reporting & Analysis"  /> TEM Reporting &amp; Analysis</td>
<td><input type="checkbox" name="WMM eProcurement" />WMM eProcurement </td>
</tr>
  <tr>
<td><input type="checkbox" name="WMM Asset/Inventory Management"  />WMM Asset/Inventory Management</td>
<td><input type="checkbox" name="WMM Expense Management"  /> WMM Expense Management</td>
<td><input type="checkbox" name="WMM Help Desk Management" />WMM Help Desk Management</td>
    </tr>
  <tr>
<td><input type="checkbox" name="WMM Mobile Device Management"/>WMM Mobile Device Management</td>
<td><input type="checkbox" name="WMM Reporting & Analysis" /> WMM Reporting &amp; Analysis</td>
<td><input type="checkbox" name="Executive"  /> Executive</td>
    </tr>
  <tr>
<td><input type="checkbox" name="other" /> Other
</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    </tr>
</table>
<input type=submit>
</form>

i havn't used php for quite some time, however i think the following might be helpful;

$val[] = $_POST['checkbox'];

$sql = "SELECT * FROM telcom WHERE ";
for($i = 0; $i < $val.length; $i++){
     $sql = $sql + "colA = ".$val[$i];

    if($i != ($val.length)-1 ){
        $sql = $sql + " OR ";
    }
}

Sorry if my syntax is a little off, i've not used php in quite some time

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.