Solved

Insert dynamic data into defined array.

Posted on 2009-05-11
2
212 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
2 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 250 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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.

803 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