Hi Everyone
I hope someone can help me, I'm trying to display database results in an array, but I keep getting the following error message:
'Cannot use string offset as an array'
I'm using WAMP version2 as a testing server on my windows computer (using Vista Business OS)
Here is the php code:
require_once ('../mysql_connect.php'); // Connect to the db.
// Make the query:
$q = "SELECT ret_name,ret_add1,ret_add2,ret_town,ret_county,ret_pcode,ret_phone,ret_email,ret_web FROM retailers ORDER BY ret_name ASC";
$result = mysql_query ($q); // Run the query.Define the $result variable and display or send error message
while ($rows = mysql_fetch_array($result)) {
$records[] = array(1 => $rows['ret_name'],
2 => $rows['ret_add1'],
3 => $rows['ret_add2'],
4 => $rows['ret_town'],
5 => $rows['ret_county'],
6 => $rows['ret_pcode'],
7 => $rows['ret_phone'],
8 => $rows['ret_email'],
9 => $rows['ret_web']
);
}
$total = count($records);
$nocol = 3;
$norows = $total / $nocol;
for ($i=1; $i <= $norows; $i++) {
$cell = 0;
echo "<tr>";
for($col=1; $col <= $nocol; $col++) {
echo "<td>";
if ($col == 1) {
$cell += $i;
echo $records[$cell - 1][1][2][3][4][5][6][7][8][9];
} else {
$cell += $norows;
echo $records[$cell - 1][1][2][3][4][5][6][7][8][9];
}
echo"<td>";
}
echo"</tr>";
}
[code=php]
I haven't included the html table or coding in this post as that seems to be working fine, it's just the php code that seems to be wrong, any help would be greatly appreciated.