I display results from the table users
:
<div class='box-for-info'>
<span>Name:</span>
<div class='box-data-content'>
<span class='text-al-center'>
<?php if(!$row['name']==NULL){echo $row['name'];}else{echo '-';}?>
</span>
<input type='text' class='data-inputs' maxlength="30" name='name' value='<?php echo $row['name'];?>'/>
</div>
</div>
<div class='box-for-info'>
<span>Gender:</span>
<div class='box-data-content'>
<span class='text-al-center'>
<?php if(!$row['gender']==NULL){echo $row['gender'];}else{echo '-';}?>
</span>
<input type='text' class='data-inputs' maxlength="30" name='gender' value='<?php echo $row['gender'];?>'/>
</div>
</div>
<div class='box-for-info'>
<span>Age:</span>
<div class='box-data-content'>
<span class='text-al-center'>
<?php if(!$row['age']==NULL){ echo $row['age'];}else{echo '-';}?>
</span>
<input type='number' class='data-inputs' maxlength="30" name='age' value='<?php if(isset($age)){echo $age;}?>'/>
</div>
</div>
<div class='box-for-info'>
<span>Country:</span>
<div class='box-data-content'>
<span class='text-al-center'>
<?php if(!$row['country']==NULL){ echo $row['country'];}else{echo '-';}?>
</span>
<input type='text' class='data-inputs' maxlength="30" name='country' value='<?php echo $row['country'];?>'/>
</div>
</div>
<div class='box-for-info'>
<span>City/Town:</span>
<div class='box-data-content'>
<span class='text-al-center'>
<?php if(!$row['city']==NULL){echo $row['city']; }else{echo '-';}?>
</span>
<input type='text' class='data-inputs' maxlength="30" name='city' value='<?php echo $row['city'];?>'/>
</div>
</div>
<div class='box-for-info'>
<span>Native languages:</span>
<div class='box-data-content'>
<span class='text-al-center'>
<?php if(!$row['native_lang']==NULL){echo $row['native_lang'];}else{echo '-';}?>
</span>
<input type='text' class='data-inputs' maxlength="30" name='native_lang' value='<?php echo $row['native_lang'];?>'/>
</div>
</div>
<div class='box-for-info'>
<span>Learned languages:</span>
<div class='box-data-content'>
<span class='text-al-center'>
<?php if(!$row['learned_lang']==NULL){echo $row['learned_lang'];}else{echo '-';}?>
</span>
<input type='text' class='data-inputs' maxlength="30" name='learned_lang' value='<?php echo $row['learned_lang'];?>'/>
</div>
</div>
<div class='box-for-info'>
<span>Learning leanguages:</span>
<div class='box-data-content'>
<span class='text-al-center'>
<?php if(!$row['learning_lang']==NULL){echo $row['learning_lang'];}else{echo '-';}?>
</span>
<input type='text' class='data-inputs' maxlength="30" name='learning_lang' value='<?php echo $row['learning_lang'];?>'/>
</div>
</div>
<div class='box-for-info'>
<span>Most favourite language:</span>
<div class='box-data-content'>
<span class='text-al-center'>
<?php if(!$row['most_fav_lang']==NULL){echo $row['most_fav_lang'];}else{echo '-';}?>
</span>
<input type='text' class='data-inputs' maxlength="30" name='most_fav_lang' value='<?php echo $row['most_fav_lang'];?>'/>
</div>
</div>
<div class='box-for-info'>
<span>Best method to learn a language:</span>
<div class='box-data-content'>
<span class='text-al-center'>
<?php if(!$row['best_method_to_learn']==NULL){ echo $row['best_method_to_learn'];}else{echo '-';}?>
</span>
<textarea class='textar' maxlength="2000" name='best_method_to_learn'><?php echo $row['best_method_to_learn'];?></textarea>
</div>
</div>
<div class='box-for-info'>
<span>Why do you learn languages:</span>
<div class='box-data-content'>
<span class='text-al-center'>
<?php if(!$row['why_do_you_learn'] == NULL){ echo $row['why_do_you_learn'];}else{echo '-';}?>
</span>
<textarea class='textar' maxlength="2000" name='why_do_you_learn'><?php echo $row['why_do_you_learn'];?>
</textarea>
</div>
</div>
<div class='box-for-info'>
<span>Your most favourite way to practice a language:</span>
<div class='box-data-content'>
<span class='text-al-center'>
<?php if(!$row['your_most_fav_way'] == NULL){echo $row['your_most_fav_way'];}else{echo '-';}?>
</span>
<textarea class='textar' maxlength="2000" name='your_most_fav_way'><?php echo $row['your_most_fav_way']; ?>
</textarea>
</div>
</div>
<div class='box-for-info'>
<span>If the world would speak one language, it would be:</span>
<div class='box-data-content'>
<span class='text-al-center'>
<?php if(!$row['one_lang_in_the_world']==NULL){ echo $row['one_lang_in_the_world'];}else{echo '-';}?>
</span>
<textarea class='textar' maxlength="2000" name='one_lang_in_the_world'><?php echo $row['one_lang_in_the_world']; ?>
</textarea>
</div>
</div>
And as you can see - the code is repeating itself but the row changes. I thought I could save whole lot of code and memory if I would use a loop that would be something like:
$row = mysqli_num_rows($result);
while($rows){?>
<div class='box-for-info'>
<span>Name:</span>
<div class='box-data-content'>
<span class='text-al-center'>
<?php if(!$row[$rows]==NULL){echo $row['name'];}else{echo '-';}?>
</span>
<input type='text' class='data-inputs' maxlength="30" name='name' value='<?php echo $row[$rows];?>'/>
</div>
</div>
The issue is that I don't really know how to identify rows so I can iterate through them here:
$row[$rows]
and also here:
name='gender'
I need with each loop to change the name of a row like: $row['name']
, $row['gender']
etc.
How can I transfer my code into a nice little loop? Any help?