Re: [PHP] Option Value
On 2/23/07, Dan Shirah [EMAIL PROTECTED] wrote: On my form I have several drop down menus. They all work and display the corrent values. However, I would like the initial display of the form to show each dropdown as blank. $q_status = SELECT * FROM status_codes ORDER BY status_description; $r_status = mssql_query($q_status) or die(mssql_error()); while ($rec_status = mssql_fetch_assoc($r_status)) $status[] = $rec_status; foreach ($status as $s) { if ($s['status_code'] == $_POST['status']) echo OPTION value=\{$s['status_code']}\ SELECTED{$s['status_description']}/OPTION\n; else echo OPTION value=\{$s['status_code']}\{$s['status_description']}/OPTION\n; } Any suggestions on how to make my initial display of the field blank without having to add a blank row to my table? Meaning: you want the select box to show as a default value a blank line but have the remaining data items from the db still in the drop-down list? Then you want to use the selected attribute on a blank line. Plenty of examples available. David
Re: [PHP] Option Value
2007. 02. 23, péntek keltezéssel 10.10-kor Dan Shirah ezt írta: On my form I have several drop down menus. They all work and display the corrent values. However, I would like the initial display of the form to show each dropdown as blank. $q_status = SELECT * FROM status_codes ORDER BY status_description; $r_status = mssql_query($q_status) or die(mssql_error()); while ($rec_status = mssql_fetch_assoc($r_status)) $status[] = $rec_status; foreach ($status as $s) { if ($s['status_code'] == $_POST['status']) echo OPTION value=\{$s['status_code']}\ SELECTED{$s['status_description']}/OPTION\n; else echo OPTION value=\{$s['status_code']}\{$s['status_description']}/OPTION\n; } Any suggestions on how to make my initial display of the field blank without having to add a blank row to my table? echo a blank option before the others greets Zoltán Németh -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Option Value
Also, if you want to get into the habit of writing valid xhtml, use lowercase and selected=selected
Re: [PHP] Option Value
Thank you George, that is what I was referring to. I had been placing the echo OPTION value=\\/OPTION\n; inside of my loop..which of course returned a blank after every valid selection. TGIF! Thanks all. On 2/23/07, Dave Goodchild [EMAIL PROTECTED] wrote: Also, if you want to get into the habit of writing valid xhtml, use lowercase and selected=selected
Re: [PHP] Option Value
On Fri, February 23, 2007 9:10 am, Dan Shirah wrote: On my form I have several drop down menus. They all work and display the corrent values. However, I would like the initial display of the form to show each dropdown as blank. [snip] Any suggestions on how to make my initial display of the field blank without having to add a blank row to my table? Just hard-code a blank OPTION in the HTML after the SELECT, but before the PHP to dump out the other options: SELECT NAME=whatever OPTION VALUE=-- Select Choice --/OPTION ?php /* your posted code goes here */ ? /SELECT Presentation Purists will claim this is wrong, I suspect, since it hard-codes the one special value for nothing selected but there it is. I personally have less trouble with this method than the other half-dozen I tried over the years. YMMV IANAL NAIAA -- Some people have a gift link here. Know what I want? I want you to buy a CD from some starving artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] OPTION
Robert Cummings wrote: On Fri, 2006-10-27 at 13:51 +0200, Jochem Maas wrote: range(1, 31) Memory waster ;) any idea as to what the damage is as compared to the classic for loop? Given that a variable probably costs X and that any variable cane be stored as Y in an array, and an array would cost Z where the Z = X * Y _ 1 (Y element + 1 for the array container itself). Then the range format would cost 31 + 1 (the array itself + 31 entries) whereas the for loop would cost 1 + 1 (cost to store i + cost to store endpoint comparison. Thus the damage is about 15*. Given general computer science consideration, this is a constant and thus practically neglible. Cheers Rob (ps. the above may be completely incoherent since I'm completely drunk atm after celebrating two friends birthdays tonight). not a bad explainantion then ;-) it's only the last bit I didn't quite follow :-) *heheh* It makes sense to me, though my head still hurts from last night :) Which part exactly did you not quite follow? this bit: Given general computer science consideration, this is a constant and thus practically neglible. Cheers, Rob. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] OPTION
On Sun, 2006-10-29 at 01:32 +0200, Jochem Maas wrote: Robert Cummings wrote: On Fri, 2006-10-27 at 13:51 +0200, Jochem Maas wrote: range(1, 31) Memory waster ;) any idea as to what the damage is as compared to the classic for loop? Given that a variable probably costs X and that any variable cane be stored as Y in an array, and an array would cost Z where the Z = X * Y _ 1 (Y element + 1 for the array container itself). Then the range format would cost 31 + 1 (the array itself + 31 entries) whereas the for loop would cost 1 + 1 (cost to store i + cost to store endpoint comparison. Thus the damage is about 15*. Given general computer science consideration, this is a constant and thus practically neglible. Cheers Rob (ps. the above may be completely incoherent since I'm completely drunk atm after celebrating two friends birthdays tonight). not a bad explainantion then ;-) it's only the last bit I didn't quite follow :-) *heheh* It makes sense to me, though my head still hurts from last night :) Which part exactly did you not quite follow? this bit: Given general computer science consideration, this is a constant and thus practically neglible. In computer science it's common to profile an algorithm using Big Oh notation. In Big Oh notation you have: O( Cn ) = O( n ) Where C is a constant multiplier. Cheers, Rob. -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] OPTION
On Thu, 2006-10-26 at 22:44 +0200, Jochem Maas wrote: Robert Cummings wrote: On Thu, 2006-10-26 at 15:31 +0200, Jochem Maas wrote: bunch of space wasters ;-) ?php foreach (range(1, 31) as $d) echo 'option value=',$d,'',($d = $selDay?' selected=selected':''),'',$d,'/option'; ? Specifically: range(1, 31) Memory waster ;) any idea as to what the damage is as compared to the classic for loop? Given that a variable probably costs X and that any variable cane be stored as Y in an array, and an array would cost Z where the Z = X * Y _ 1 (Y element + 1 for the array container itself). Then the range format would cost 31 + 1 (the array itself + 31 entries) whereas the for loop would cost 1 + 1 (cost to store i + cost to store endpoint comparison. Thus the damage is about 15*. Given general computer science consideration, this is a constant and thus practically neglible. Cheers Rob (ps. the above may be completely incoherent since I'm completely drunk atm after celebrating two friends birthdays tonight). -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] OPTION
Robert Cummings wrote: On Thu, 2006-10-26 at 22:44 +0200, Jochem Maas wrote: Robert Cummings wrote: On Thu, 2006-10-26 at 15:31 +0200, Jochem Maas wrote: bunch of space wasters ;-) ?php foreach (range(1, 31) as $d) echo 'option value=',$d,'',($d = $selDay?' selected=selected':''),'',$d,'/option'; ? Specifically: range(1, 31) Memory waster ;) any idea as to what the damage is as compared to the classic for loop? Given that a variable probably costs X and that any variable cane be stored as Y in an array, and an array would cost Z where the Z = X * Y _ 1 (Y element + 1 for the array container itself). Then the range format would cost 31 + 1 (the array itself + 31 entries) whereas the for loop would cost 1 + 1 (cost to store i + cost to store endpoint comparison. Thus the damage is about 15*. Given general computer science consideration, this is a constant and thus practically neglible. Cheers Rob (ps. the above may be completely incoherent since I'm completely drunk atm after celebrating two friends birthdays tonight). not a bad explainantion then ;-) it's only the last bit I didn't quite follow :-) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] OPTION
On Fri, 2006-10-27 at 13:51 +0200, Jochem Maas wrote: range(1, 31) Memory waster ;) any idea as to what the damage is as compared to the classic for loop? Given that a variable probably costs X and that any variable cane be stored as Y in an array, and an array would cost Z where the Z = X * Y _ 1 (Y element + 1 for the array container itself). Then the range format would cost 31 + 1 (the array itself + 31 entries) whereas the for loop would cost 1 + 1 (cost to store i + cost to store endpoint comparison. Thus the damage is about 15*. Given general computer science consideration, this is a constant and thus practically neglible. Cheers Rob (ps. the above may be completely incoherent since I'm completely drunk atm after celebrating two friends birthdays tonight). not a bad explainantion then ;-) it's only the last bit I didn't quite follow :-) *heheh* It makes sense to me, though my head still hurts from last night :) Which part exactly did you not quite follow? Cheers, Rob. -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] OPTION
Robert Cummings wrote: On Wed, 2006-10-25 at 17:35 -0700, Paul Novitski wrote: At 10/25/2006 04:09 PM, Stut wrote: Dang that's painful!! Try this... ?php foreach (range(1, 31) as $day) { print 'option value='.$day.''; if ($selected_day_of_month == $day) print ' selected'; print ''.$day.'/option'; } ? Ouch! Gnarly mix of logic and markup. I suggest something more like: foreach (range(1, 31) as $day) { $sSelected = ($selected_day_of_month == $day) ? ' selected=selected' : ''; print hdDay option value=$day$sSelected$day/option hdDay; } Ewww, I'll take Stut's style anyday. Heredoc has its uses, but I wouldn't consider your above usage one of them :/ Now to add my own flavour... ?php for( $day = 1; $day = 31; $day++ ) { $selected = $selected_day_of_month == $day ? ' selected=selected' : ''; echo 'option value='.$day.''.$selected.'' .$day .'/option'; } ? bunch of space wasters ;-) ?php foreach (range(1, 31) as $d) echo 'option value=',$d,'',($d = $selDay?' selected=selected':''),'',$d,'/option'; ? Cheers, Rob. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] OPTION
On Thu, October 26, 2006 8:31 am, Jochem Maas wrote: bunch of space wasters ;-) ?php foreach (range(1, 31) as $d) echo 'option value=',$d,'',($d = $selDay?' selected=selected':''),'',$d,'/option'; ? You messed up. :-) $d == $selDay would be the correct expression in the middle of that. My personal choice is: $last_day = 31; //calculated from date()/mktime() etc for ($day = 1; $day = $last_day; $day++){ $selected = $chosen_day == $ ? 'selected=selected' : ''; echo option $selected$day/option\n; } I don't *think* the w3c requires/recommends a value= in there, if the label *IS* the value, but can live with it either way... echo option value=\$day\ $selected$day/option\n; is fine. I used to be distracted by \ but I've grown so used to it that it no longer bothers me in my reading flow, unless it's excessive and the expression spans multiple lines. Separation of logic and presentation is all very well, but this isn't even business logic. It's presentation logic which, to me, shouldn't be crammed into the complex business portion of my application. I'd much rather have the complex business logic focus on the application needs than the minutae of date formatting. It's all down to personal choice, though. -- Some people have a gift link here. Know what I want? I want you to buy a CD from some starving artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] OPTION
On Thu, 2006-10-26 at 15:31 +0200, Jochem Maas wrote: bunch of space wasters ;-) ?php foreach (range(1, 31) as $d) echo 'option value=',$d,'',($d = $selDay?' selected=selected':''),'',$d,'/option'; ? Specifically: range(1, 31) Memory waster ;) Cheers, Rob. -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] OPTION
On Thu, 2006-10-26 at 11:43 -0500, Richard Lynch wrote: $last_day = 31; //calculated from date()/mktime() etc for ($day = 1; $day = $last_day; $day++){ $selected = $chosen_day == $ ? 'selected=selected' : ''; echo option $selected$day/option\n; } I don't *think* the w3c requires/recommends a value= in there, if the label *IS* the value, but can live with it either way... echo option value=\$day\ $selected$day/option\n; is fine. From the XHTML standard: http://www.w3.org/TR/html/#diffs We read the following: XML does not support attribute minimization. Attribute-value pairs must be written in full. Attribute names such as compact and checked cannot occur in elements without their value being specified. CORRECT: unminimized attributes dl compact=compact INCORRECT: minimized attributes dl compact So even if you aren't using XHTML yet, it's wise to get into the practice. Cheers, Rob. -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] OPTION
for ($i=1;$i=31;$i++) : ? option value=?php echo $i; ? ?php if ($selectedDay == $i) echo selected=\selected\; ??php echo $i; ?/option ?php endfor; ?
Re: [PHP] OPTION
On Thu, October 26, 2006 12:14 pm, Robert Cummings wrote: On Thu, 2006-10-26 at 11:43 -0500, Richard Lynch wrote: $last_day = 31; //calculated from date()/mktime() etc for ($day = 1; $day = $last_day; $day++){ $selected = $chosen_day == $ ? 'selected=selected' : ''; echo option $selected$day/option\n; } I don't *think* the w3c requires/recommends a value= in there, if the label *IS* the value, but can live with it either way... echo option value=\$day\ $selected$day/option\n; is fine. From the XHTML standard: http://www.w3.org/TR/html/#diffs We read the following: XML does not support attribute minimization. Attribute-value pairs must be written in full. Attribute names such as compact and checked cannot occur in elements without their value being specified. CORRECT: unminimized attributes dl compact=compact INCORRECT: minimized attributes dl compact So even if you aren't using XHTML yet, it's wise to get into the practice. A) I see no need, now or ever, to use XHTML. B) What you are referencing has ZERO BEARING on the question of not having ANY value attribute at all, as far as I can see: option5/option This does not have a minimized VALUE attribute. It has *NO* value attribute at all. :-) -- Some people have a gift link here. Know what I want? I want you to buy a CD from some starving artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] OPTION
Wow, pretty aggressive. No reason to EVER use xhtml - hmmm, good attitude, good evolutionary sense. Let's wait and see. I believe the gent was referring to the use of 'selected=selected' and trying to encourage good habits in someone - which I think is commendable. Why so angry?
Re: [PHP] OPTION
On Thu, 2006-10-26 at 13:13 -0500, Richard Lynch wrote: On Thu, October 26, 2006 12:14 pm, Robert Cummings wrote: On Thu, 2006-10-26 at 11:43 -0500, Richard Lynch wrote: $last_day = 31; //calculated from date()/mktime() etc for ($day = 1; $day = $last_day; $day++){ $selected = $chosen_day == $ ? 'selected=selected' : ''; echo option $selected$day/option\n; } I don't *think* the w3c requires/recommends a value= in there, if the label *IS* the value, but can live with it either way... echo option value=\$day\ $selected$day/option\n; is fine. From the XHTML standard: http://www.w3.org/TR/html/#diffs We read the following: XML does not support attribute minimization. Attribute-value pairs must be written in full. Attribute names such as compact and checked cannot occur in elements without their value being specified. CORRECT: unminimized attributes dl compact=compact INCORRECT: minimized attributes dl compact So even if you aren't using XHTML yet, it's wise to get into the practice. A) I see no need, now or ever, to use XHTML. YMMV. B) What you are referencing has ZERO BEARING on the question of not having ANY value attribute at all, as far as I can see: option5/option This does not have a minimized VALUE attribute. It has *NO* value attribute at all. Ahh, I just re-read your email, and well... I need to go drink some coffee :) Cheers, Rob. -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] OPTION
Richard Lynch wrote: On Thu, October 26, 2006 8:31 am, Jochem Maas wrote: bunch of space wasters ;-) ?php foreach (range(1, 31) as $d) echo 'option value=',$d,'',($d = $selDay?' selected=selected':''),'',$d,'/option'; ? You messed up. :-) dang :-P try again: function genDayOptionTags($c = 31, $sv = 0, $eco = 1) { $o = ''; foreach (range(1, $c) as $d) $o .= 'option value=',$d,'', ($d == $sv?' selected=selected':''), '',$d,'/option'; if ($eco) echo $o; return $o; } genMonthSelectTag($m = 1, $sv = 0, $attrs = array(), $eco = 1) { // allowed attribs static $dattr = array('name' = 1, 'id' = 1, 'class' = 1, 'name' = 1,); // speedy literal for looking up number of days static $h = array(1,2,3,4,5,6,7,8,9,10,11,12); // 'normalize' month (13 - 1, 14 - 2, 15 - 3, etc) $m -= ((intval($m) % 12) * 12); // php5.1.0RC1 or higher for array_intersect_key // otherwise STW for a userland variant (PEAR)? $attrs = array_intersect_key($attrs, $dattrs); foreach ($attrs as $k = $v) $attrs[$k] = $v ? {$k}=\{$v}\: ''; $o = 'select name='.join(' ', array_filter($attrs)).''.genDayOptions($h[$m], $sv, 0).'/select'; if ($eco) echo $o; return $o; } the point being that if your going to put things like this into a function then you might as well do it properly and completely generalize the generation of a select tag and it's options. (as opposed to the above banality :-) $d == $selDay would be the correct expression in the middle of that. My personal choice is: $last_day = 31; //calculated from date()/mktime() etc for ($day = 1; $day = $last_day; $day++){ $selected = $chosen_day == $ ? 'selected=selected' : ''; $ ? ;-) echo option $selected$day/option\n; } lately I have been fond of dropping braces around single if/foreach expressions, I like the fact it makes the code compacter. I don't *think* the w3c requires/recommends a value= in there, if the label *IS* the value, but can live with it either way... echo option value=\$day\ $selected$day/option\n; is fine. I used to be distracted by \ but I've grown so used to it that it no longer bothers me in my reading flow, unless it's excessive and the expression spans multiple lines. I know that feeling. :-) Separation of logic and presentation is all very well, but this isn't even business logic. It's presentation logic which, to me, shouldn't be crammed into the complex business portion of my application. here, here. I'd much rather have the complex business logic focus on the application needs than the minutae of date formatting. quite, why would business logic need to deal with anything other than a timestamp (+zone) ? It's all down to personal choice, though. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] OPTION
Robert Cummings wrote: On Thu, 2006-10-26 at 15:31 +0200, Jochem Maas wrote: bunch of space wasters ;-) ?php foreach (range(1, 31) as $d) echo 'option value=',$d,'',($d = $selDay?' selected=selected':''),'',$d,'/option'; ? Specifically: range(1, 31) Memory waster ;) any idea as to what the damage is as compared to the classic for loop? Cheers, Rob. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] OPTION
Ron Piggott (PHP) wrote: I am creating a form right now. I am using the html SELECT tag. SELECT NAME=day_of_month The most number of days in a month is 31 I want the output to be OPTION SELECTED## based on the value of $selected_day_of_month variable. For the days of the month where the number is not selected the output I am desiring is OPTION1 OPTION2 etc. to be generated through PHP code I already have a value the user submitted in a variable named $selected_day_of_month from being stored in a mySQL table Does anyone know how to do this in a few commands? I am wanting to simplify ? if ( $selected_day_of_month == 1 ) } OPTION SELECTED1 } ELSE { OPTION1 } if ( $selected_day_of_month == 2 ) } OPTION SELECTED2 } ELSE { OPTION2 } ? etc. Dang that's painful!! Try this... ?php foreach (range(1, 31) as $day) { print 'option value='.$day.''; if ($selected_day_of_month == $day) print ' selected'; print ''.$day.'/option'; } ? I added a value to the options (you knew that was missing right?). Obviously you need to output the select ... and /select outside this loop. -Stut -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: Re: [PHP] OPTION
...and if you wanted to go an extra step you could try an alternate syntax of the exact same code: ?php foreach (range(1, 31) as $day) print 'option value=' . $day . '' . ($selected_day_of_month == $day ? ' selected' : '') . '' . $day . '/option'; ? Either way, Stut is correct. Don't type this out 31 times unless you really really really like to type. ;-) - Joe On 10/25/06, Stut [EMAIL PROTECTED] wrote: Ron Piggott (PHP) wrote: I am creating a form right now. I am using the html SELECT tag. SELECT NAME=day_of_month The most number of days in a month is 31 I want the output to be OPTION SELECTED## based on the value of $selected_day_of_month variable. For the days of the month where the number is not selected the output I am desiring is OPTION1 OPTION2 etc. to be generated through PHP code I already have a value the user submitted in a variable named $selected_day_of_month from being stored in a mySQL table Does anyone know how to do this in a few commands? I am wanting to simplify ? if ( $selected_day_of_month == 1 ) } OPTION SELECTED1 } ELSE { OPTION1 } if ( $selected_day_of_month == 2 ) } OPTION SELECTED2 } ELSE { OPTION2 } ? etc. Dang that's painful!! Try this... ?php foreach (range(1, 31) as $day) { print 'option value='.$day.''; if ($selected_day_of_month == $day) print ' selected'; print ''.$day.'/option'; } ? I added a value to the options (you knew that was missing right?). Obviously you need to output the select ... and /select outside this loop. -Stut -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] OPTION
At 10/25/2006 04:09 PM, Stut wrote: Dang that's painful!! Try this... ?php foreach (range(1, 31) as $day) { print 'option value='.$day.''; if ($selected_day_of_month == $day) print ' selected'; print ''.$day.'/option'; } ? Ouch! Gnarly mix of logic and markup. I suggest something more like: foreach (range(1, 31) as $day) { $sSelected = ($selected_day_of_month == $day) ? ' selected=selected' : ''; print hdDay option value=$day$sSelected$day/option hdDay; } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] OPTION
On Wed, 2006-10-25 at 17:35 -0700, Paul Novitski wrote: At 10/25/2006 04:09 PM, Stut wrote: Dang that's painful!! Try this... ?php foreach (range(1, 31) as $day) { print 'option value='.$day.''; if ($selected_day_of_month == $day) print ' selected'; print ''.$day.'/option'; } ? Ouch! Gnarly mix of logic and markup. I suggest something more like: foreach (range(1, 31) as $day) { $sSelected = ($selected_day_of_month == $day) ? ' selected=selected' : ''; print hdDay option value=$day$sSelected$day/option hdDay; } Ewww, I'll take Stut's style anyday. Heredoc has its uses, but I wouldn't consider your above usage one of them :/ Now to add my own flavour... ?php for( $day = 1; $day = 31; $day++ ) { $selected = $selected_day_of_month == $day ? ' selected=selected' : ''; echo 'option value='.$day.''.$selected.'' .$day .'/option'; } ? Cheers, Rob. -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Option value
Is it possible to extract the value option which item name selected..for example i am having list of soap brand in the options..is it possible that to tell that the user seleced this brand of soap while in the submittion of the form..can any one please tell me how to do this.. Umm...that's what PHP does, isn't it? form method=GET select name=soap option value=DoveDove/option option value=ZestZest/option /select input type=submit /form When that form is submitted, you'll have a variable $_GET['soap'] that'll be equal to either Zest or Dove, depending on what the user chose. Maybe you are missing the value= in your option tags? ---John Holmes... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] option block
Jeremy: Have you tried echoing your $sql variable to ensure it has in it what you expect? In other words, does $PHP_AUTH_USER have the value you need it to have? hth Happy programming! Chris Mulcahy -Original Message- From: Jeremy Morano [mailto:[EMAIL PROTECTED]] Sent: Tuesday, September 04, 2001 2:57 PM To: [EMAIL PROTECTED] Subject: [PHP] option block Hello everyone, I'm having a problem with my option block... I'm trying to pass the value of uid to the next page. I always get the last uid value in table user. How can I change this so I get to pass the value of the user's choice? $sql = SELECT user.uid, user.first_name, user.last_name FROM user, company Where company.uid = user.companyUid and company.company = '$PHP_AUTH_USER' ORDER BY last_name ; $result = @mysql_query($sql,$connection) or die(Couldn't execute query.); while ($row = mysql_fetch_array($result)) { $uid = $row['uid']; $first_name = $row['first_name']; $last_name = $row['last_name']; $option_block .= option value=\$uid\$last_name, $first_name/option; } $display_block = FORM METHOD=\post\ ACTION=\show_moduser.php\ PstrongUser:/strong select name=\uid\ $option_block /select INPUT TYPE=\SUBMIT\ NAME=\submit\ VALUE=\Select this User\/P /form ; -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] option tags and WHILE
On Mon, 20 Aug 2001 12:23, CGI GUY wrote: What's wrong with this code? I keep getting a parse error at the form/select lines... $array = mysql_fetch_array($mysql_result) or die(no go); print (form); print (select); while ($array[1] = $array[0]) { print (option value=\$array[0]\ $array[1]/option\n); } print (/select); print (/form); ? That's an, er, interesting script. But it's not going ever to do what I think you expect it to. You need to use while to loop through the rows returned by your SQL query, and for each iteration in the while loop, print the values you need. Also, if you use extract, you can directly access variables that have the same names as the rows in your table, so you don't have to refer to array elements. Frinstance, if you are fetching fields named value and label for this exercise, something like: echo 'FORMSELECT'; while ($array = mysql_fetch_array($mysql_result)) { extract($array); echo 'OPTION VALUE=' . $value . '' . $label . '/OPTION'; } echo '/SELECT/FORM'; Of course, you'll need to put some more info in your FORM tag and add submit buttons and so forth. -- David Robley Techno-JoaT, Web Maintainer, Mail List Admin, etc CENTRE FOR INJURY STUDIES Flinders University, SOUTH AUSTRALIA Ensign Expendable, step on that rock! - Kirk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] option tags and WHILE
Also while ($array[1] = $array[0]) { and not while ($array[1] = $array[0]) { Rudolf Visagie [EMAIL PROTECTED] -Original Message- From: David Robley [mailto:[EMAIL PROTECTED]] Sent: 20 August 2001 07:01 To: CGI GUY; [EMAIL PROTECTED] Subject: Re: [PHP] option tags and WHILE On Mon, 20 Aug 2001 12:23, CGI GUY wrote: What's wrong with this code? I keep getting a parse error at the form/select lines... $array = mysql_fetch_array($mysql_result) or die(no go); print (form); print (select); while ($array[1] = $array[0]) { print (option value=\$array[0]\ $array[1]/option\n); } print (/select); print (/form); ? That's an, er, interesting script. But it's not going ever to do what I think you expect it to. You need to use while to loop through the rows returned by your SQL query, and for each iteration in the while loop, print the values you need. Also, if you use extract, you can directly access variables that have the same names as the rows in your table, so you don't have to refer to array elements. Frinstance, if you are fetching fields named value and label for this exercise, something like: echo 'FORMSELECT'; while ($array = mysql_fetch_array($mysql_result)) { extract($array); echo 'OPTION VALUE=' . $value . '' . $label . '/OPTION'; } echo '/SELECT/FORM'; Of course, you'll need to put some more info in your FORM tag and add submit buttons and so forth. -- David Robley Techno-JoaT, Web Maintainer, Mail List Admin, etc CENTRE FOR INJURY STUDIES Flinders University, SOUTH AUSTRALIA Ensign Expendable, step on that rock! - Kirk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] option value
Hi Michael! On Sun, 15 Jul 2001, Michael Thomas wrote: how can i populate an dropdown box useing php postgresql. Thanks in advance if you tell me how you tried by yourself first, I'll help you further ;) it's trivial with Javascript, but if you don't want to use that it's still doable. -- teodor -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]