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
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]
Link to comment
Share on other sites

[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]
Link to comment
Share on other sites

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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.