?
Solved

Insert dynamic data into defined array.

Posted on 2009-05-11
2
Medium Priority
?
227 Views
Last Modified: 2013-12-12
I have a defined array, $array (see example code below). Now, data1a to data2b represent dynamic data, and there are many more data values to be inserted into this array.

For example: data1 ranges from (data1a-data1z), data2 ranges from (data2a-data2z), and so on. there are different data ranges for each set. These are defined within a database. Here is an example table

data1a, data1b, data1c, data1d
data2a, data2b
data3a, data3b, data3c
data4a, data4b, data4c, data4d, data4e
etc.

What I want to do is dynamically insert the values into the defined array without having to manually insert the values.
$array = array('data1a' => array(), 'data1b' => array(), 'data2a' => array(), 'data2b' => array());

Open in new window

0
Comment
Question by:ZeterFan411
1 Comment
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 1000 total points
ID: 24357191
can you please clarify the table schema, resp. how you query the table?
assuming it's a single table/column
$array = array(); 
$sql = "select your_column from yourtable group by your_column";
$rows = mysql_query($sql);
while ($row = mysql_fetch_assoc($rows))
{
  $your_col = $row["your_column"]; 
  $array[$your_col] = array();
}

Open in new window

0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses
Course of the Month16 days, 14 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question