I think this is probably really simple to do, but I must be overlooking something.
Basically, I have If/Else php statements, that check if a condition is true. Within each of these if statements, is a WHILE loop that echos all the appropriate rows from my database.
The while loops need to print some table cells, and fields from the row. At the moment, each WHILE loop has the code manually typed out, meaning if I want to change the layout or something else, I need to change it within each while loop.
What I want to do, is to define a variable, that I can echo, so that I only need to change the code in one place for it to affect all WHILE loops. However, the nature of the content within the WHILE loops mean that this wont work, and here is why:
//If the date is a monday
if($daycheck == "Monday") {
//Start a row and create cell with date in
echo "<tr><td height='100px' valign='top'>".$datedisplay."<br />";
//For each event found for this day
while($dayrow = mysql_fetch_assoc($dayresult)) {
//Show the event info
echo $dayrow['Event Time']."<br />".$dayrow['Event Name']."<br />";
}
//End the cell for the day
echo "</td>";
}
This is one IF statement, but imagine there are several more underneath. You can see in the middle is my WHILE loop, showing the fields from each row in the database.
The problem is, that if I stick:
$dayrow['Event Time']."<br />".$dayrow['Event Name']."<br />";
into a variable before the while loop, when I echo it out, it will be the same every time as the $dayrow parts don’t get updated.
Is there any way that I can put the above into a variable so that it gets update each time the WHILE loop runs?
Perhaps if the $dayrow[”] parts were stored as text rather than variables somehow?
Thanks for any assistance you can offer.
Eds
As DaveRandom suggested you can use
sprintf()or (more fancy and more possibilities) a template system usingeval().