RE: [PHP-DB] array awry
| From: | Cal Evans | Date: | Tue, 27 Feb 2001 12:50:12 +0000 |
| Subject: | RE: [PHP-DB] array awry | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-6976@lists.php.net to get a copy of this message | ||
Hi Keith,
1: Don't cross-post. It's rude. Especially since this has nothing to do with
MySQL.
2: You are not building a multi-dimensional array. The code below won't even
build a single dimensional array because you didn't put your keys in quotes
so it's probably blowing chunks. At the very least, if you had put quotes
around your key names, it would have overwritten the data each loop.
Try something like this:
If ($Selection == "3")
{
$lcvA++;
$tabledata[$lcvA] = Array();
$tabledata[$lcvA]['catid'] = $myrow[0];
$tabledata[$lcvA]['category'] = "$myrow[1]";
$tabledata[$lcvA]['under'] = $myrow[2];
$tabledata[$lcvA]['corder'] = $myrow[3];
$tabledata[$lcvA]['active'] = $myrow[4];
}
This is a multidimensional array. The first dimension is a counter, $lcvA.
Make sure you init it at the top of your function. Now, each time you add a
row to the array, it' in a new row IN the array.
To access the data you use:
$myCOrder = $tabledata[$rowToAccess]['corder']
HTH,
Cal
http://www.calevans.com
-----Original Message-----
From: Keith Spiller [mailto:larentium@gilanet.com]
Sent: Monday, February 26, 2001 8:15 PM
To: mysql@lists.mysql.com
Cc: php-db@lists.php.net
Subject: [PHP-DB] array awry
This associative array embedded within a function and declared as a global
at the start of the function, is meant to be a multidimensional array, but
with every loop of the while ($myrow = mysql_fetch_row($result)) statement,
it's previous values are replaced by the new ones. Any ideas on how I can
fix this?
If ($Selection == "3")
{
$tabledata[catid] = $myrow[0];
$tabledata[category] = "$myrow[1]";
$tabledata[under] = $myrow[2];
$tabledata[corder] = $myrow[3];
$tabledata[active] = $myrow[4];
}
Keith
aka Larentium