473,506 Members | 14,630 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

multidimensional associatve array problem

from a MySQL DB i want to get a multidimensional array that i can loop
through

either key =field name value = array of ENUM options
or array[x][0] =field name, array[x][1]= ENUM options and increment x
inside loop
$q=mysql_query("SHOW FIELDS FROM table" ) or die ("Query failed");

while ($row = mysql_fetch_array($q))
{
//from http://uk.php.net/mysql_fetch_field

echo 'field is '.$row['Field'] . ' type is ' . $row['Type'];
if (ereg('enum.(.*).', $row['Field'], $match))
{
$opts = explode(',', $match[1]);
foreach ($opts as $item)
{$finalResult[] = substr($item, 1, strlen($item)-2);}
}

$array=array ($row['Field'] =>$finalResult[]);

}
gives Fatal error :Cannot use [] for reading in .......

a similar error message when i try a multidimentional array
array[$x][0]=$row['Field']
array[$x][1]=$finalResult[]
anyone know the answer ( or a better way of doing it )

Jul 17 '05 #1
1 1636
pauld (pd****@yahoo.co.uk) decided we needed to hear...
from a MySQL DB i want to get a multidimensional array that i can loop
through

either key =field name value = array of ENUM options
or array[x][0] =field name, array[x][1]= ENUM options and increment x
inside loop
<snip failing code>

Try the following instead (altered from your code)...

$q = mysql_query("show fields from thetable");
$arr = array();
while ($row = mysql_fetch_array($q)) {
echo 'field is ' . $row[0] . ' type is ' . $row[1] . '<br>';
$finalResult = array();
if (preg_match('/enum\((.*?)\)/', $row[1], $match)) {
$opts = explode(',', $match[1]);
foreach ($opts as $item) {
array_push($finalResult, substr($item, 1, strlen($item)-2));
}
}
$arr[$row[0]] = $finalResult;
}
print_r($arr);

--
Dave <da**@REMOVEbundook.com>
(Remove REMOVE for email address)
Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
10874
by: Rob Tweed | last post by:
Probably a simple question but I can't find the answer anyway. Specifically, is it possible to copy a multidimensional array into the $_SESSION array - ie a deep clone of all keys and data? I...
4
3673
by: Christian Hackl | last post by:
I honestly wasn't able to find an answer for this design question using Google and Google Groups, so I apologize if it is asked too frequently :) Anyway: Let's say I have a multidimensional array...
5
4476
by: TLOlczyk | last post by:
I have a brain cramp and I need some help. I have a chunk of code below which demonstrates a problem I have with multidimensional arrays. I want to keep it simple but something specific is...
9
6653
by: Charles Banas | last post by:
i've got an interesting peice of code i'm maintaining, and i'd like to get some opinions and comments on it, hopefully so i can gain some sort of insight as to why this works. at the top of the...
10
2321
by: Ole | last post by:
Goodday everybody, i want to create an array that represents data, that has to be transferred to a pdf doc ( iTextSharp ). The problem is, that i seem too loose my faith. Namely, ( i have...
2
12809
by: chris | last post by:
Hi there, I created a Multidimensional array of labels Label lblMultiArray = new Label { {Label3, LblThuTotal}, {Label4,LblFriTotal} }; Now I would like to compare the values in the array,...
14
2856
by: Michel Rouzic | last post by:
Hi, I've recently met issues with my program which can only be explained by heap corruption, so I've tried debugging my program with Valgrind, and here's what I get with the following...
12
5619
by: filippo nanni | last post by:
Hello everybody, my question is this: I have two multidimensional arrays and I have to create a third one (for later use) from comparing these two. Here is my example code: //BEGIN CODE var...
9
4473
by: Slain | last post by:
I need to convert a an array to a multidimensional one. Since I need to wrok with existing code, I need to modify a declaration which looks like this In the .h file int *x; in a initialize...
0
7308
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
7479
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5617
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5037
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...
0
4702
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3188
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3178
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
757
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
410
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.