Hey. I've got a variable which changes depending on the conditions. That's normal, ofc. This variable prints some HTML. Within this HTML is a select-box, with the options (hopefully) pulled from a function - but how do I do that? Currently, I have as follows: $date_paid = "<td class='a_right'> <form> <select class='formlook' name='paid_day'> option_values(31); </select> <select class='formlook' name='paid_month'> option_months(); </select> <input class='formlook' type='text' name='paid_year' size='4' value='' /> </form> </td>"; PHP: What I want is of course for the option_value() and the option_month() functions to be parsed - and I can't seem to get it to work. Anyone have an idea as to how I can do this? (Yes, I know I could echo the if-statement, but that won't work, as it has to be contained inside that $date_paid variable
$date_paid = "<td class='a_right'> <form> <select class='formlook' name='paid_day'>".option_values(31)." </select> <select class='formlook' name='paid_month'>".option_months()." </select> <input class='formlook' type='text' name='paid_year' size='4' value='' /> </form> </td>";
Tried that, does not work. For some reason, I'm not sure why - that was the first thing I tried. It prints the values, all right, but for some reason it leaves the other parts out - ie. if I use your method, it prints the option_values(31) out as <option>1</option><option>2</option> etc. (which of course is what it is supposed to do) but for some reason the rest of the code (the <td><select> etc.) is not displayed. I'm not sure why... I'll add some of the code: if ($members[date_paid] == 00-00-0000) { $date_paid = "<td class='a_right'> <form> <select class='formlook' name='paid_day'>".option_values(31)." </select> <select class='formlook' name='paid_month'>".option_months()." </select> <input class='formlook' type='text' name='paid_year' size='4' value='' /> </form> </td>"; $sum_paid = "<td class='a_right'><form method='post' action='$domain/update_list.php'> <input class='hidden' name='uniqueID' value='$uniqueID' /> <input class='formlook' type='text' name='sum_paid' size='4' maxlength='4' value='$amount' /><input type='submit' value='Oppdater' /></form></td>"; } echo "<tr> $name$address$mail$phone$birthdate$date_paid$sum_paid </tr>"; PHP: The rest of the variables in the echo-statement is defined earlier, and is working as intended
There's no reason NatalicWolf's suggestion shouldn't work. Have you looked at the HTML source that was generated? Maybe your option_values() function is leaving an HTML tag or a quotation mark open.
You might very well be right on that one, yes. The code for the option_values()-function is as follows: function option_values($max) { $options = array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31'); $options_limited = array_slice($options,0,$max); foreach ($options_limited as $value) { echo "<option>$value</option>"; }} PHP:
Score one more for NatalicWolf. Instead of echoing, concatenate the stuff in a variable and then return that variable. $r = ''; foreach (blahblah) $r .= "blahblah"; return $r; Code (markup):