I have an array with the names of medication which the user is currently taking. On the webpage, I want to display radio buttons with the name of each of the medications, which are currently being taken, next to them. The code I have for the array is;
//Current Entries Section
$CurrentMedsQuery = "SELECT Name FROM `".$username."medication` WHERE Status='Current';";
$RunMedsQuery = mysql_query($CurrentMedsQuery) or trigger_error(mysql_error().$CurrentMedsQuery);
$Count = mysql_num_rows($RunMedsQuery);
$CurrentMedsArray = array();
while ($CurrentMedEntries = mysql_fetch_array($RunMedsQuery)) {
array_push($CurrentMedsArray,$CurrentMedEntries['Name']);
}
$session =& JFactory::getSession();
$session->set('CurrentMedsArray', $CurrentMedsArray);
while ($Count < 0) {
}
$FirstMedEntry = ($CurrentMedsArray["0"]);
Then on my HTML form, I have the following code which successfully displays the name of the first element in the array as I want it to;
<form method="post" name="currentmeds" action="">
<input type="radio" name="med1" value="med1"><?php echo $FirstMedEntry;?><br>
</form>
But my question is, I will not know how many current medication entries the user has, therefore I cannot continuously use echo $FirstMedEntry, echo $SecondMedEntry and so on..I figure I need some sort of loop, and help would be greatly appreciated!
Thanks in advance!
Changed to the following as suggested;
//Current Entries Section
echo '<form method="post" name="currentmeds" action="">';
$CurrentMedsQuery = "SELECT Name FROM `".$username."medication` WHERE Status='Current';";
$RunMedsQuery = mysql_query($CurrentMedsQuery) or trigger_error(mysql_error().$CurrentMedsQuery);
$Count = mysql_num_rows($RunMedsQuery);
$count = 1;
while ($CurrentMedEntries = mysql_fetch_row($RunMedsQuery)) {
echo '<input type="radio" name="med' . $count . '" value="med' . $count . '">' . $CurrentMedEntries . '<br>';
$count++;
}
echo '</form>';
But now receiving this error; Notice: Array to string conversion in C:\xampp\htdocs\Joomla-Lifestyle\components\com_jumi\files\medication.php on line 238
Line 238:
echo '<input type="radio" name="med' . $count . '" value="med' . $count . '">' . $CurrentMedEntries . '<br>';