Jump to content

array missing bits


c_shelswell

Recommended Posts

Hi i'm trying to make an array to spit out a load of different countrys to populate a select box i've got:

[code]
$bizArray = array(
'<option value="AI">Anguilla </option>',
'<option value="AR">Argentina </option>',
'<option value="AU">Australia </option>',
'<option value="AT">Austria </option>',
'<option value="BE">Belgium </option>',
[/code]
problem is it's only returning the country names and knocking off the <option value> bits.

Anyway to stop this?

Cheers
Link to comment
https://forums.phpfreaks.com/topic/35655-array-missing-bits/
Share on other sites

seek and ye shall find sorry might have been a bit quick to post up here.

[code]
$bizArray = array(htmlspecialchars("<option value='AI'>Anguilla </option>"),htmlspecialchars('<option value="AR">Argentina </option>'));
[/code

seems to work. Will take a while to type it all out mind you. Is there better way?[/code]
Link to comment
https://forums.phpfreaks.com/topic/35655-array-missing-bits/#findComment-168895
Share on other sites

How are you using this array? Please post the code that uses it.

This code works fine:
[code]<?php
$bizArray = array(
'<option value="AI">Anguilla </option>',
'<option value="AR">Argentina </option>',
'<option value="AU">Australia </option>',
'<option value="AT">Austria </option>',
'<option value="BE">Belgium </option>');

echo '<form>';
echo 'Country: <select name="country">';
echo '<option value=""></option>';
for ($i=0;$i<count($bizArray);$i++)
echo $bizArray[$i];
echo '</select>';
echo '</form>';
?>[/code]

Ken
Link to comment
https://forums.phpfreaks.com/topic/35655-array-missing-bits/#findComment-168896
Share on other sites

basically i'm storing a customers details in the database but when they come to purchase they get a chance to amend their details. I want my option box to default to their country so i was going to do this:

[code]

foreach ($bundles as $key => $value)
{
$id = $value['media_id'];
$title = $value['title'];
echo "\t<option value='$id'"; if ($media_id == $id){echo "selected";} echo "/>".$title."</option>\n";
}
[/code]
this is a bit of code i used elsewhere in my project and as i was putting it here i just realised my array won't work with the <option> tags already in there going to have to change it.
Link to comment
https://forums.phpfreaks.com/topic/35655-array-missing-bits/#findComment-168898
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.