mysql - entering names dynamically using php for loop -


ive got number of textboxes filled in name database.

i create 5 textinputs, using for.. loop

for($i=1; $i<=5; $i++) {   echo '<input type="text" value="">'; }  

my question how enter names each textboxes dynamically.

i tried:

$q = $db->query("select * att id_bs_res='$id_bs_res'");    for($i=1; $i<=5; $i++) {     while($r = $q->fetch_assoc()) {         echo '<input type="text" value="'.$r['att_name'].'">';     } }  

if there 3 names in database, show 3 instead of 5 textboxes? want shows textboxes if rest of textboxes blank.

sample textboxes 1. names 2. names 3. names 4. ------ 5. ------ 

remove inner while loop.

$q = $db->query("select * att id_bs_res='$id_bs_res'");    for($i=1; $i<=5; $i++) {     $r = $q->fetch_assoc();     echo '<input type="text" value="'.isset($r['att_name'])?$r['att_name']:''.'">'; } 

of course, better check count of returned rows, , not call fetch_assoc() after you've displayed 3 rows, output next 2


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -