spires Posted June 5, 2007 Share Posted June 5, 2007 Hi I'm rubbish with arrays, can anyone help? i'm trying put information from my database into an array. then pull them out one by one. I'm trying to only get the 1st and the 5th entry. example: $array['0'] $array['5'] $sql3 = "SELECT * FROM pages WHERE page_cat='bread_crumb'"; $select_query3 = mysql_query($sql3) or die ('error1'); $count3 = mysql_num_rows($select_query3); $row3 = mysql_fetch_array($select_query3); $page_name = $row3['page_name']; $page_status = $row3['page_status']; $page_url = $row3['page_url']; $page_cat = $row3['page_cat']; $page_order = $row3['page_order']; $array = array($page_name); echo $array['0']; echo $array['5']; Thanks for any help Quote Link to comment Share on other sites More sharing options...
paul2463 Posted June 5, 2007 Share Posted June 5, 2007 I dont quite understand what you mean, how many rows are likely to be returned from each of the queries? if there are more than one then you probably will need a while loop to fill the array if it is only one then the array $row3 can be used which information are you after? Quote Link to comment Share on other sites More sharing options...
spires Posted June 5, 2007 Author Share Posted June 5, 2007 I have 7 rows in the database. home lounge_bar club_music whats_on menues corporate_rooms contacts I want to echo out two at a time, depending on which page the user is currently on. the names are going to make up a bread crumbing effect. FOR EXAMPLE: home > menues So, i'm trying to put the values into an array, where i can then select which values i want. FOR EXAMPLE: echo $array['0'].' > '.$array['5']; My knowledge on arrays is very limited as i don't tend to use them. But i thought this would be a simple exercise to get me started. Thanks for your help. Quote Link to comment Share on other sites More sharing options...
paul2463 Posted June 5, 2007 Share Posted June 5, 2007 $sql3 = "SELECT * FROM pages WHERE page_cat='bread_crumb'"; $select_query3 = mysql_query($sql3) or die ('error1'); $count3 = mysql_num_rows($select_query3); while($row3 = mysql_fetch_assoc($select_query3)) { $array[] = $row3['page_name']; // this will fill $array with all the page names } print_r($array); // prints out Array([0]=>Home, [1]=>lounge_bar, [2]=>club_music, [3]=>whats_on, [4]=>menues, [5]=>corporate_rooms, [6]=>contact) echo $array['0'].' > '.$array['5']; //echoes out Home>corporate_rooms hope that helps Quote Link to comment Share on other sites More sharing options...
spires Posted June 5, 2007 Author Share Posted June 5, 2007 Thanks. Thats great. 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.