Cflax Posted April 24, 2011 Share Posted April 24, 2011 I am trying to make a basic navigation across the top of my pages in my navmenu showing all of the categories in my ob_category table. so if i add a category to the database later, the link in the navmenu is automatically added. this is what i was experimenting with at the moment: <?php $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); $query1 = "SELECT * FROM ob_category"; $data1 = mysqli_query($dbc, $query1); $row1 = mysqli_fetch_array($data1); foreach($row1['name'] as $value){ echo '<a href="viewlistings.php">' . $value . '</a> •'; } ?> not working, I'm not worried about the links working quite yet, its the category names im most concerned about any ideas?? Link to comment https://forums.phpfreaks.com/topic/234573-foreach-or-while-problem/ Share on other sites More sharing options...
ShoeLace1291 Posted April 24, 2011 Share Posted April 24, 2011 An easier way to loop through your data would be this: while($row=mysqli_fetch_array($query)){ echo '<a href="viewlistings.php">' . $row['name'] . '</a> •'; Edit: sorry, it parsed your html symbol code there lol. Link to comment https://forums.phpfreaks.com/topic/234573-foreach-or-while-problem/#findComment-1205489 Share on other sites More sharing options...
Cflax Posted April 24, 2011 Author Share Posted April 24, 2011 ya it did but i got it to work from what you said THANK YOU lol <?php $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); $query1 = "SELECT name FROM ob_category"; $data1 = mysqli_query($dbc, $query1); while($row=mysqli_fetch_array($data1)){ echo '<a href="viewlistings.php">' . $row['name'] . '</a> •'; } ?> now to figure out how to get rid of the bullet separator on the last category Link to comment https://forums.phpfreaks.com/topic/234573-foreach-or-while-problem/#findComment-1205491 Share on other sites More sharing options...
ShoeLace1291 Posted April 24, 2011 Share Posted April 24, 2011 Yeah, that lol. I forgot you only included the SQL in your query variable and not the actual function lol. Anyways, glad I could help. Link to comment https://forums.phpfreaks.com/topic/234573-foreach-or-while-problem/#findComment-1205495 Share on other sites More sharing options...
wildteen88 Posted April 24, 2011 Share Posted April 24, 2011 now to figure out how to get rid of the bullet separator on the last category You could do $links = array(); while($row=mysqli_fetch_array($query)){ $links[] = '<a href="viewlistings.php">' . $row['name'] . '</a>'; echo implode(' •', $links); Link to comment https://forums.phpfreaks.com/topic/234573-foreach-or-while-problem/#findComment-1205506 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.