Jump to content

Recommended Posts

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> &#8226;';

}

?>

 

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

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

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);

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.