Solved

Insert dynamic data into defined array.

Posted on 2009-05-11
2
211 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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

762 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now