mysql - PHP - dropdown populates but will not select using 2 tables -
i've been working on @ least month, , can't find question elsewhere. know i'm missing stupid, but...
there 2 tables: biz , bizclass. bizclass.bizclassname holds 250+ classifications populate dropdown box. population bizclass table , update biz table both work, when try select current data biz.bizclass1 , dropdown initial value set null value "select class". please help. it's driving me bonkers. i'm old many more sleepless nights! newbie - familiar php , javascript don't have grip on ajax yet.
echo "class1: <select name ='bizclass1' id='bizclass1'/> "; $sql = 'select bizclassname bizclass order bizclassname'; $query2 = 'select `bizclass1` `biz` `bizid` = "'. $search .'"'; $clist = mysqli_query($connection,$sql); $num=mysqli_num_rows($clist); $olist = mysqli_query($connection, $query2); // select bizclass biz $biztblrecord = mysqli_fetch_assoc($clist); // option values bizclass table populate dropdown $row2 = mysqli_fetch_assoc($olist); // fetched bizclass biz if ($row2['bizclass1'] == $biztblrecord['bizclassname']){ printf ("<option value='%s' selected >%s</option> ", $row2['bizclass1'], $row2['bizclass1']); } else { printf ("<option value=''>select class</option> "); }//end if for($numrows=1; $numrows<= $num; $numrows++) { // associative array $row=mysqli_fetch_assoc($clist); printf ("<option value='%s'>%s</option>",$row['bizclassname'],$row['bizclassname']); } //end echo "</select>"; // free result set mysqli_free_result($clist); mysqli_free_result($olist);
echo "class1: <select name ='bizclass1' id='bizclass1'/> <option value=''>select class</option> "; $sql = 'select bizclassname bizclass order bizclassname'; $clist = mysqli_query($connection,$sql); $num=mysqli_num_rows($clist); $querysearch = 'select `bizclass1` `biz` `bizid` = "'. $search .'"'; $searchlist = mysqli_query($connection, $querysearch); // select bizclass biz $rowsearch= mysqli_fetch_assoc($searchlist); // fetched bizclass biz for($numrows=1; $numrows<= $num; $numrows++) { // associative array $row=mysqli_fetch_assoc($clist); if ($rowsearch['bizclass1'] == $row['bizclassname']){ printf ("<option value='%s' selected >%s</option> ", $rowsearch['bizclass1'], $rowsearch['bizclass1']); } else { printf ("<option value='%s'>%s</option>",$row['bizclassname'],$row['bizclassname']); }//end if } //end echo "</select>"; // free result set mysqli_free_result($clist); mysqli_free_result($searchlist);
if statement have inside loop compare each option search.
test tables:
biz
bizid bizclass1 1 ronaldo 2 shevshenko 3 falcao 4 zidane 5 valderrama
bizclass
bizclassname falcao ozil ronaldo messi shevshenko valderrama hazard totti
Comments
Post a Comment