Updating an older NAVBAR module to show manufacturers

Open to all! Ask other shopowners for help.
Post Reply
14Steve14
Senior Contributor
Posts: 923
Joined: Fri Oct 25, 2019 7:01 pm
Phoenix Version: v1.0.9.1
Has thanked: 17 times
Been thanked: 103 times

Updating an older NAVBAR module to show manufacturers

Post by 14Steve14 »

I am trying to update an older NAVBAR module that shows a dropdown list of the stores manufacturers. I have the module installed and it works, but it throws a few errors. The first error is thrown I believe because of
tep_db_query
on line 6 and the second is caused by
tep_db_fetch_array
on line 11.

I have added the full code below.

Code: Select all

<li class="nav-item dropdown nb-manufacturers">
	<a class="nav-link dropdown-toggle" href="#" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><?= MODULE_NAVBAR_MANUFACTURERS_TEXT;?></a>

<?php 
$manufacturers_list = '';
$manufacturers_query = tep_db_query("select manufacturers_id, manufacturers_name from manufacturers order by manufacturers_name");

// Display a list
$manufacturers_list = '<div class="dropdown-menu">';

while ($manufacturers = tep_db_fetch_array($manufacturers_query)) {

	$manufacturers_name = $manufacturers['manufacturers_name'];

	if (isset($_GET['manufacturers_id']) && ($_GET['manufacturers_id'] == $manufacturers['manufacturers_id'])) {
		$manufacturers_name = '<strong>' . $manufacturers_name .'</strong>';
	}

	$manufacturers_list .= '<a class="dropdown-item" href="' . $GLOBALS['Linker']->build('index.php', 'manufacturers_id=' . $manufacturers['manufacturers_id']) . '">' . $manufacturers_name . '</a>';

}

$manufacturers_list .= '</div>';

echo $manufacturers_list; 
?>

</li>
There may be more errors in there, but those are the two that I can see in the error logs for the site.

Is there anyone that can give me a bit of help, or at least a pointer, on how to cure the errors please. I have look in other modules for similar code but seem to be confusing myself.


Join The Code Co-op to get access to your library in the Code Co-op Forum
User avatar
burt
Core Team
Posts: 4561
Joined: Tue Oct 29, 2019 9:37 am
Phoenix Version: v1.1.0.8
Has thanked: 252 times
Been thanked: 422 times

Re: Updating an older NAVBAR module to show manufacturers

Post by burt »

The straightforwardest (usually) option is to find a piece of code in Core Phoenix that is closest to what you're trying and "copy" it, changing just enough to suit your new modules needs. In this case, /includes/modules/boxes/bm_manufacturers.php (and corresponding tpl file) seem to fit the bill;

Code: Select all

$manufacturers_query = $GLOBALS['db']->query("SELECT manufacturers_id AS id, manufacturers_name AS text FROM manufacturers ORDER BY manufacturers_name");
and

Code: Select all

<div class="dropdown-menu">
  <?php
  while ($manufacturer = $manufacturers_query->fetch_assoc()) {
    echo '<a class="dropdown-item" href="', $GLOBALS['Linker']->build('index.php', ['manufacturers_id' => $manufacturer['id']]), '">', $manufacturers_name, '</a>';
  }
  ?>
</div>
I am not here to build for you.
I am here to build with you. Let's help each other.
14Steve14
Senior Contributor
Posts: 923
Joined: Fri Oct 25, 2019 7:01 pm
Phoenix Version: v1.0.9.1
Has thanked: 17 times
Been thanked: 103 times

Re: Updating an older NAVBAR module to show manufacturers

Post by 14Steve14 »

Thanks Gary @burt for the pointers I eventually got the NAVBAR dropdown working.

I also managed to update the code on another page that shows all the manufacturers and their logos.

Onwards to the next task in the update process.


Join The Code Co-op to get access to your library in the Code Co-op Forum
Post Reply