php - Using a dropdown menu in a form for a SELECT statement with SQL -


thank reading question.

i building form let users search db cards used in collectible card game. want include dropdown menu let users narrow search down specific card expansion.

here dropdown menu:

<select name="expsn" onchange="this.submit()">      <option>all expansions</option>      <option value="core">core</option>      <option value="som">shadows of mirkwood</option> 

and here select statement:

$sql = "select * carddb  expsn ='" . $_post['expsn'] . "' , type='hero' "; 

this works when selecting either core or mor, if dropbox left blank "all expansions" passed $_post['expsn']. (i use echo $sql; output select statement). how can set default return card expansions.

i have spent last few weeks learning php , sql online, possible whole approach here wrong , not scalable, 'big picture' appreciated. thank you.

if expsn comes set, add condition sql, like:

$expsn = (strlen($_post['expsn']) > 0) ? "expsn = '" . $_post['expsn'] . "' , " : ''; $sql = "select * carddb $expsn type='hero'"; 

Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -