PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP RelatedPHP Coding

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old August 21st, 2002, 04:32 PM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
option value

hello,

if am using an arrays in my code, i modify my form fields(text box, check box) like this,

$cnt = count($HTTP_POST_VARS['id']);

for($cntr=0;$cntr<$cnt;$cntr++) {

<input type="text" name="ac[<?=$counter?>]" value="<?=$ac?>">

if (!$HTTP_POST_VARS['attach'][$cntr]) $attach=0; else $attach=1;

<input type="checkbox" name="is_enrolled[<?=$counter?>]" value="1"<? if ($isenrolled==1)echo "checked";?>>


BUT, how is with option box.

If it is like this for example,

<SELECT
size=1 name=brand>
<OPTION value ="0"<?php
if($brand==0){
echo 'selected';
}?>>NIKE</OPTION>
<OPTION value ="1"<?php
if($brand==1){
echo 'selected';
}?>>ADDIDAS</OPTION></SELECT>

Now, my question is , how can i modify the above option code with respect to an array.

could some body pls make the changes and present it to me.

many thanks

Reply With Quote
  #2  
Old August 21st, 2002, 05:38 PM
notepad notepad is offline
Codewalkers Loyal (3000 - 3499 posts)
 
Join Date: Apr 2007
Location: Central, IL USA
Posts: 3,214 notepad User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Send a message via AIM to notepad
RE: option value

i don't even really get how your first array is working.. either way you could use the same code to determin your values but an option box can only have one item at a time selected.

Reply With Quote
  #3  
Old August 21st, 2002, 05:58 PM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
RE: option value

OK, let me try to explain in detail:

<?
Database connection
if ($HTTP_POST_VARS){
$cnt = count($HTTP_POST_VARS['id']);
for($cntr=0;$cntr<$cnt;$cntr++) {
if (!$HTTP_POST_VARS['attach'][$cntr]) $attach=0; else $attach=1;

UPDATE Statement;
}
}

SELECT STATEMENT
?>

Field headings
<?php

$counter=0;
$old_values=null;
while statement to get the fields
?>
//here comes my form fields

<td width="154" height="23">
<input type="text" name="tei[<?=$counter?>]" value="<?=$tei?>">
</td>
<td width="69" height="23">
<input type="checkbox" name="attach[<?=$counter?>]" value="1"<? if ($attach==1)echo "checked";?>>

<?php

$old_values.=' <input type="hidden" name="id['.$counter.']" value="'.$row->HS_ID.'">
';

$counter++;

}
?>
</table>
<?=$old_values?>

hmm..thatz it.this works fine so far with all my text boxes and check boxes.

My problem is only with OPTION VALUE.

If i have a code like this for my selectable field,

<SELECT
size=1 name=type>
<OPTION value ="0"<?php
if($type==0){
echo 'selected';
}?>>Addidas</OPTION>
<OPTION value ="1"<?php
if($type==1){
echo 'selected';
}?>>GAP</OPTION></SELECT>

How should i make the changes with respect to my array?

Hope somebody would be there to help me.

thanks once again.






Reply With Quote
  #4  
Old August 22nd, 2002, 01:52 AM
Gipz Gipz is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Stockholm, Sweden
Posts: 98 Gipz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via ICQ to Gipz
RE: option value

Do you want to geneder the options from an array??

Then, try this:
php Code:
Original - php Code
  1.  
  2. <?php
  3.    
  4. $optionArray = array (
  5.     'name1' => 'value1',
  6.     'name2' => 'value2',
  7.     'name3' => 'value3'
  8. );
  9.  
  10. $ret = '<SELECT size=1 name=brand>';
  11. foreach($optionArray as $name => $value)
  12. {
  13.     $ret .= '<OPTION value ="'.$value.'">'.$name.'</OPTION>';
  14. }
  15. $ret .= '</SELECT>';
  16. ?>

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Coding > option value


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway