Jump to content

[SOLVED] Multidimensional arrays


wattsup88

Recommended Posts

I need to know how to make a multidimensional array from $_SESSION element but for some reason php thinks it is a string... wonering if anyone has a better way to do this...

[code]$result = mysql_query("SELECT * FROM jobs ORDER BY id");
echo "<table>";
while ($row = mysql_fetch_array($result)) {
    $id = $row['id'];
$_SESSION['id'][] = $id;
echo "<tr><td width=\"200\">$id</td>";
echo "<td width=\"200\"><a href=\"session2.php\">View Job</a></td></tr>";
echo "</table>";
?>[/code]

Thanks
-Jake

Link to comment
https://forums.phpfreaks.com/topic/31294-solved-multidimensional-arrays/
Share on other sites

Is this the right idea? b/c as strange as it sounds it worked the first time but after that it gives me the same message... here's the code:

[code]
$result = mysql_query("SELECT * FROM jobs ORDER BY id");

$_SESSION['id'] = "$id";
$_SESSION['id'] = array();

echo "<table>";

while ($row = mysql_fetch_array($result)) {
    $id = $row['id'];
$_SESSION['id'][] = $id;
    echo "<tr><td width=\"200\">$id</td>";
echo "<td width=\"200\"><a href=\"session2.php\">View Job</a></td></tr>";

}
echo "</table>";
?>
[/code]
[code]Oh to be specific i am using this exact code...


$result = mysql_query("SELECT * FROM jobs ORDER BY id");

echo "<table>";

$_SESSION['id'] = "$id";

$_SESSION['id'] = array();

while ($row = mysql_fetch_array($result)) {
    $id = $row['id'];

$_SESSION['id'][] = "$id";

    echo "<tr><td width=\"200\">$id</td>";
echo "<td width=\"200\"><a href=\"session2.php\">View Job</a></td></tr>";
}
echo "</table>";
?>
[/code]
Take out the first
[code]<?php
$_SESSION['id'] = "$id";
?>[/code]
It is a meaningless statement there, is $id hasn't been set yet. It is also causing your problems because you are first saying that $_SESSION['id'] is a null string and they you're trying to use it as an array.

BTW, you don't need the double quotes around $id in the assignment statement, just use
[code]<?php
$_SESSION['id'] = $id;
?>[/code]

Ken

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.