wattsup88 Posted December 19, 2006 Share Posted December 19, 2006 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 Quote Link to comment Share on other sites More sharing options...
trq Posted December 19, 2006 Share Posted December 19, 2006 What do you meen by php thinks its a string? Quote Link to comment Share on other sites More sharing options...
esukf Posted December 19, 2006 Share Posted December 19, 2006 Where's the closing bracket for your while loop? Quote Link to comment Share on other sites More sharing options...
alpine Posted December 19, 2006 Share Posted December 19, 2006 set $_SESSION['id'] as array after it is set,example:[code]<?phpsession_start();$_SESSION['id'] = "whatever";$_SESSION['id'] = array();while(whatever){ $_SESSION['id'][] = "whatever";}?>[/code] Quote Link to comment Share on other sites More sharing options...
wattsup88 Posted December 20, 2006 Author Share Posted December 20, 2006 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] Quote Link to comment Share on other sites More sharing options...
esukf Posted December 20, 2006 Share Posted December 20, 2006 It helps if you copy and paste the actual errors you are getting. Quote Link to comment Share on other sites More sharing options...
wattsup88 Posted December 20, 2006 Author Share Posted December 20, 2006 Fatal error: [] operator not supported for strings in /home/content/d/i/a/dianabarton/html/tests/session1.php on line 38 Quote Link to comment Share on other sites More sharing options...
wattsup88 Posted December 20, 2006 Author Share Posted December 20, 2006 [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] Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted December 20, 2006 Share Posted December 20, 2006 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.