473,770 Members | 3,398 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

multidimensiona l associatve array problem

from a MySQL DB i want to get a multidimensiona l 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_arr ay($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 multidimentiona l 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 1666
pauld (pd****@yahoo.c o.uk) decided we needed to hear...
from a MySQL DB i want to get a multidimensiona l 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("sh ow fields from thetable");
$arr = array();
while ($row = mysql_fetch_arr ay($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($fin alResult, substr($item, 1, strlen($item)-2));
}
}
$arr[$row[0]] = $finalResult;
}
print_r($arr);

--
Dave <da**@REMOVEbun dook.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
10920
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 naively assumed that $_SESSION = $myArray ; would work but it doesn't appear to work. Is there a single function
4
3691
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 of the following kind: $people = array(); // maps age and e-mail address to names $people = array(21, "paul@foo.bar"); $people = array(22, "linda@bar.foo"); $people = array(19, "max@foobar.foobar");
5
4505
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 getting in the way. int a; int b; int **present; int **next;
9
6674
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 function (which was translated from Fortran code), among other heinous and numerous declarations, is this bit: static float bbuff; static int bkey; static int buse;
10
2361
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 experiences in c/c++, perl and i thouht in c#, too ), i do not succeed in creating a multidimensional array. I have no experience in creating multidimensional array in c#. The whole process looks so ugly to me,
2
12834
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, comparing the text in Label3 and LblThuTotal and the text in Label4 and LblFriTotal.
14
2895
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 multidimensional array allocation code : typedef struct { int32_t speed;
12
5662
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 myGroups = ,,]; var myProducts = ,,,]; var newGroups = new Array();//Resulting Array function main() { for(i=0; i<myGroups.length; i++){
9
4502
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 function: x = new int;
0
9591
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9425
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10057
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9869
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8883
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6676
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5312
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3970
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2816
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.