473,405 Members | 2,262 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,405 software developers and data experts.

Separating my options

Lazandra
Hi all

I have a field in my database that is one long list. I want to put this list into a drop down but have each item in that list its own option.

This is how its printing at the moment:

Expand|Select|Wrap|Line Numbers
  1. <select name="v_options"><option value="">-- Any --</option><option value='34'>Allerton, Bolton, Bolton Woods,Bowling,Bradford Moor,Buttershaw,Clayton,Dudley Hill,East Bierley</option></select>
Expand|Select|Wrap|Line Numbers
  1. <select name="v_options"><option value="">-- Any --</option>
  2. <option value='34'>Allerton, Bolton</option><option value='34'>Bolton Woods</option><option value='34'>Bowling</option><option value='34'>Bradford Moor</option><option value='34'>Buttershaw</option><option value='34'>Clayton</option>Dudley Hill<option value='34'>East Bierley</option></select>
Does anyone know a function that will separate my options?

Thanks
xx
Feb 1 '08 #1
5 1170
Amzul
130 100+
Hi all

I have a field in my database that is one long list. I want to put this list into a drop down but have each item in that list its own option.

This is how its printing at the moment:

Expand|Select|Wrap|Line Numbers
  1. <select name="v_options"><option value="">-- Any --</option><option value='34'>Allerton, Bolton, Bolton Woods,Bowling,Bradford Moor,Buttershaw,Clayton,Dudley Hill,East Bierley</option></select>
Expand|Select|Wrap|Line Numbers
  1. <select name="v_options"><option value="">-- Any --</option>
  2. <option value='34'>Allerton, Bolton</option><option value='34'>Bolton Woods</option><option value='34'>Bowling</option><option value='34'>Bradford Moor</option><option value='34'>Buttershaw</option><option value='34'>Clayton</option>Dudley Hill<option value='34'>East Bierley</option></select>
Does anyone know a function that will separate my options?

Thanks
xx
you can try explode(), and then make a loop to builed your html code from the array
post a sample of your db filed value
i dont think i understood in 100% what u want to do :(
Feb 1 '08 #2
Markus
6,050 Expert 4TB
Yeh, like he/she said.

Say we have a string (coming from your db), each word is seperated by a space.

[php]
$_string = "list of places in string seperated by spaces";
[/php]
We'd then explode() the string with a space ' ' as a delimiter, to make turn the string into an array
[php]
$_string = explode(" ", $_string);
[/php]
Then we'd use a foreach() loop to traverse through the array:
[php]
foreach( $_string as $_x )
{
echo $_x . "<br />";
}
[/php]

Hope this helps!
Feb 1 '08 #3
Hi,

if the field is in a MySQL DB why not use this to populate your dropdown?

[PHP]<?
mysql_select_db($database, $connect);
$tablename = "event";

$abfrage = "SELECT datum, event FROM $tablename ORDER BY datum ASC";
$ergebnis = mysql_query($abfrage);

echo '<select size="1" name="datum">';

while($row = mysql_fetch_object($ergebnis))

{

$datum = "$row->datum";
$event = "$row->event";

echo '<option value="'.$datum.'">'.$datum. ' : ' .$event.'</option><br>'; // Eleganter
$event = $_POST['event'];
$datum = $_POST['datum'];
}
echo $datum;
echo ' </select>';
?>[/PHP]

In this case, I have populated the dropdown with "Datum : Event"

Hope this helps,

Best regards,

Stefan
Feb 1 '08 #4
Hi guys!

Thats brilliant! I have used the explode () function and it works perfectly.

Thanks again

Laz
xxx
Feb 4 '08 #5
Markus
6,050 Expert 4TB
Hi guys!

Thats brilliant! I have used the explode () function and it works perfectly.

Thanks again

Laz
xxx
Welcome!

Post back again whenever :)
Feb 4 '08 #6

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

Similar topics

9
by: Anon Email | last post by:
Hi people, I'm learning about header files in C++. The following is code from Bartosz Milewski: // Code const int maxStack = 16; class IStack
39
by: Joe Laughlin | last post by:
If I have a character array with "/some/file/directory/file_name", are there any functions / libraries that I could use to separate the directory ("some/file/directory") from the file name...
6
by: Chad Z. Hower aka Kudzu | last post by:
I want to do this. I want my programmers to do all the code. All of it - run at server and run at client. I then want a graphic artist to make the look and the layout of the pages. The...
3
by: mca | last post by:
Hi everyone, I'm new to asp.net and i have a question about separating the html code from the programming code. i have an unknown numbers of entries in my table. I want to make a hyperlink...
13
by: Michelle | last post by:
Hi all... I could use a little TLC here for understanding and not for solving a specific problem... sorry if I've got the wrong group, but I'm using VB so I figured this was the most appropriate...
8
by: Jeff S | last post by:
Please note that this question is NOT about any particular pattern - but about the general objective of separating out presentation logic from everything else. I'm trying to "get a grip" on some...
0
by: Thag | last post by:
Hi! I am currently trying to get an overview about the possibility of separating graphical data from its animations. More specifically speaking, the graphical data is made up from 3D-CAD...
14
by: aaragon | last post by:
Hi everyone, I've been writing some code and so far I have all the code written in the .h files in order to avoid the linker errors. I'm using templates. I wanted to move the implementations to...
14
by: Gilles Ganault | last post by:
Hi One of the ways to raise performance for PHP apps is to separate static contents from dynamic contents, so that the former can be compiled once into cache. Can someone give me a simple...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.