473,322 Members | 1,421 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

string in array

I am new to PHP so sorry if this has been covered before - couldn't find anything through a search.

I want to set up an array that I can use to fill a selection box in a form. My array looks like

$AdTypeArray = array(1=> 'Not known', 'Newspaper text only', 'Newspaper Column Colour', 'Newspaper Column BW', 'Web directory', 'Directory Column Colour',
'Search Engine', 'Website', 'Car', 'Recommendation', 'Shop');

and my form code is:

<td id='input'><select name='AdType'>";

for ($n=1;$n<=sizeof($AdTypeArray);$n++)
{
echo "<option value=$AdTypeArray[$n]";
if ($_POST['AdType'] == $AdTypeArray[$n])
{
echo " selected";
}
echo "> $AdTypeArray[$n]";
}

echo "</select></td>

On the form I get the full text from the array value but when the form is submitted $_POST[AdType] only holds the characters up to the first space. I have tried double quotes single quotes and combinations. Put double and single quotes around each value gives me the output I want from the form but the display on the form shows the value surrounded by the single quotes.

Any ideas please?

Robert
Mar 13 '07 #1
3 1476
ronverdonk
4,258 Expert 4TB
Welcome to TSDN!

Read the Posting Guidelines (top of this forum), especially the part about enclosing any shown code within php or code tags!!

When you post code, post all relevant code, and not just part of it. Where e.g. is the <form> statement, the 'submit' button, etc.?

Your problem: your box values have blanks in them, so when you show these entries in a value field, you must enclose them within quotes, otherwise only the first word will show.

Here is the code as it works [php]
if (isset($_POST['submit'])) {
print_r($_POST);
exit;
}
echo '<form action="a.php" method="POST">';
echo "<td id='input'><select name='AdType'>";

for ($n=1;$n<=sizeof($AdTypeArray);$n++) {
echo "<option value='$AdTypeArray[$n]'";
if ($_POST['AdType'] == $AdTypeArray[$n]) {
echo " selected='selected'";
}
echo "> $AdTypeArray[$n]</option>";
}
echo '</select></td>';
echo '<input type="submit" value="submit" name="submit">';
echo '</form>';
[/php]

Ronald :cool:
Mar 13 '07 #2
Very many thanks, I knew it would be something simple.

Sorry about the poorly displayed code, I will read all of the guidance before next posting and promise to behave in future!

Rob
Mar 13 '07 #3
ronverdonk
4,258 Expert 4TB
You are welcome and will see you next time.

Ronald :cool:
Mar 13 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

16
by: Don Starr | last post by:
When applied to a string literal, is the sizeof operator supposed to return the size of the string (including nul), or the size of a pointer? For example, assuming a char is 1 byte and a char *...
7
by: al | last post by:
char s = "This string literal"; or char *s= "This string literal"; Both define a string literal. Both suppose to be read-only and not to be modified according to Standard. And both have...
4
by: songkv | last post by:
Hi, I am trying to reassign an array of char to a string literal by calling a function. In the function I use pointer-to-pointer since I want to reassign the "string array pointer" to the string...
22
by: spike | last post by:
How do i reset a string? I just want to empty it som that it does not contain any characters Say it contains "hello world" at the time... I want it to contain "". Nothing that is.. Thanx
4
by: Simon Schaap | last post by:
Hello, I have encountered a strange problem and I hope you can help me to understand it. What I want to do is to pass an array of chars to a function that will split it up (on every location where...
14
by: Bob | last post by:
I have a function that takes in a list of IDs (hundreds) as input parameter and needs to pass the data to another step as a comma delimited string. The source can easily create this list of IDs in...
8
by: Jeff Johnson | last post by:
Hi, I've begun converting an ASP site over to .NET and I'm a novice at both the new platform as well as C#. I have a COM+ object that returns a string array when it is called. The size of...
17
by: Chad Myers | last post by:
I've been perf testing an application of mine and I've noticed that there are a lot (and I mean A LOT -- megabytes and megabytes of 'em) System.String instances being created. I've done some...
11
by: Zordiac | last post by:
How do I dynamically populate a string array? I hope there is something obvious that I'm missing here Option Strict On dim s() as string dim sTmp as string = "test" dim i as integer ...
14
by: Shhnwz.a | last post by:
Hi, I am in confusion regarding jargons. When it is technically correct to say.. String or Character Array.in c. just give me your perspectives in this issue. Thanx in Advance.
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.