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 Link to comment https://forums.phpfreaks.com/topic/31294-solved-multidimensional-arrays/ 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? Link to comment https://forums.phpfreaks.com/topic/31294-solved-multidimensional-arrays/#findComment-144811 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? Link to comment https://forums.phpfreaks.com/topic/31294-solved-multidimensional-arrays/#findComment-144813 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] Link to comment https://forums.phpfreaks.com/topic/31294-solved-multidimensional-arrays/#findComment-144820 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] Link to comment https://forums.phpfreaks.com/topic/31294-solved-multidimensional-arrays/#findComment-144846 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. Link to comment https://forums.phpfreaks.com/topic/31294-solved-multidimensional-arrays/#findComment-144871 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 Link to comment https://forums.phpfreaks.com/topic/31294-solved-multidimensional-arrays/#findComment-144878 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] Link to comment https://forums.phpfreaks.com/topic/31294-solved-multidimensional-arrays/#findComment-144885 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 Link to comment https://forums.phpfreaks.com/topic/31294-solved-multidimensional-arrays/#findComment-144901 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.