I have 100 input type text boxes and would like to display the value to each box from a txt file. I couldn't figure it out in PHP and thought it might be easier in JavaScript. But I am not familiar with JavaScript. My text fields are being displayed as:
<input type="text" size="13" name="contacts[]" id="contact0">
<input type="text" size="13" name="contacts[]" id="contact1">
<input type="text" size="13" name="contacts[]" id="contact2">
<input type="text" size="13" name="contacts[]" id="contact3">
So I need to add value the text boxes from contacts.txt
which has peoples names in line by line.
To show as:
<?php include 'includethis.php' ?>
<input type="text" size="13" name="contacts[]" id="contact0" value="David">
<input type="text" size="13" name="contacts[]" id="contact1" value="Erick">
<input type="text" size="13" name="contacts[]" id="contact2" value="John">
<input type="text" size="13" name="contacts[]" id="contact3" value="Frank">
Here is the includethis.php
file that writes all the names to replace the name tag to the index.php
$filename = 'pics.txt';
$handle = fopen($filename, 'r');
$datain = fread($handle, filesize($filename));
$names_array = explode("\n", $datain);
$count = 0;
$counter = 0;
foreach($names_array as $show){
if($count < 4)
{
echo '<img src="images/'.$show.'">';
$count++;
}
else
{
$count = 0;
echo '<br><input type="text" size="13" name="contacts[]" id="contact'.$counter++.'"><input type="text" size="13" name="contacts[]" id="contact'.$counter++.'"><input type="text" size="13" name="contacts[]" id="contact'.$counter++.'">';
echo '<br>'.'<img src="images/'.$show.'">';
$count++;
}
}