mercredi 3 mai 2017

MYSQL Query statements based on PHP radio buttons

I have group of radio buttons:

<div id="navbarval" method="POST">
    <input type="radio" name="selectionval"  onchange="this.form.submit();" value="users" checked> CATEGORY USERS
    <input type="radio" name="selectionval"  onchange="this.form.submit();" value="avgspends"> AVERAGE SPENDS
    <input type="radio" name="selectionval"  onchange="this.form.submit();" value="totalspends" > TOTAL SPENDS
    <input type="radio" name="selectionval"  onchange="this.form.submit();" value="percapita" > PER CAPITA SPENDS
</div>

based on the user selection I am trying to fetch the mysql data. My php codes so far is as follows:

$query = if ($_POST['selectionval'] == "users"){
            "SELECT users,sum(categ) as {$categ} FROM cktable group by users";  
          } 

I am getting the following error:

Parse error: parse error in /Users/dynamo/Sites/newvan/accessories.php on line 210

I want to extend this with else if for all the other radio buttons to alter mysql select query and hence the need for if condition.

i tried passing the select statement directly:

$query = "SELECT users,sum(categ) as {$categ} FROM cktable group by users";  

this runs without any error.

Any thoughts?

Aucun commentaire:

Enregistrer un commentaire