Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Hot to display ALL banners in one page


quomo

Recommended Posts

Posted

Hi,

I added this code to my specials.php page to get a banner.

 

<?php if ($banner = tep_banner_exists('dynamic', '480x62')) {

?>

<?php echo tep_display_banner('static', $banner); ?>

<?php

}

?>

 

Now, I would like to display all banners available for the category '480x62'.

HOW? :blush:

Posted

I am aware of some contributions that will add the banners to the body of the site, but Im looking for the code to call all banners in a specific page. Thats all.

 

Help.

Posted

Look in includes\functions\banner.php copy the function tep_display_banner to another name then modify the sql query to return those banners matching the 480x62 "group" column. When the function returns with the query loaded use something like:

 

<?php
while($banner = tep_db_fetch_array($banner_returned_query)
{
 echo '<tr><td>' . '<a href="' . tep_href_link(FILENAME_REDIRECT, 'action=banner&goto=' . $banner['banners_id']) . '" target="_blank">' . tep_image(DIR_WS_IMAGES . $banner['banners_image'], $banner['banners_title']) . '</a></td></tr>';

}
?>

Posted

Im not sure I understand you.

 

I have this code in the page now:

<?php if ($banner = tep_banner_exists('dynamic', '480x62')) {

?>

<?php echo tep_display_banner('static', $banner); ?>

<?php

}

?>

 

You want me to copy this code in banner.php:

// Display a banner from the specified group or banner id ($identifier)

function tep_display_banner($action, $identifier) {

if ($action == 'dynamic') {

$banners_query = tep_db_query("select count(*) as count from " . TABLE_BANNERS . " where status = '1' and banners_group = '" . $identifier . "'");

$banners = tep_db_fetch_array($banners_query);

if ($banners['count'] > 0) {

$banner = tep_random_select("select banners_id, banners_title, banners_image, banners_html_text from " . TABLE_BANNERS . " where status = '1' and banners_group = '" . $identifier . "'");

} else {

return '<b>TEP ERROR! (tep_display_banner(' . $action . ', ' . $identifier . ') -> No banners with group \'' . $identifier . '\' found!</b>';

}

} elseif ($action == 'static') {

if (is_array($identifier)) {

$banner = $identifier;

} else {

$banner_query = tep_db_query("select banners_id, banners_title, banners_image, banners_html_text from " . TABLE_BANNERS . " where status = '1' and banners_id = '" . (int)$identifier . "'");

if (tep_db_num_rows($banner_query)) {

$banner = tep_db_fetch_array($banner_query);

} else {

return '<b>TEP ERROR! (tep_display_banner(' . $action . ', ' . $identifier . ') -> Banner with ID \'' . $identifier . '\' not found, or status inactive</b>';

}

}

} else {

return '<b>TEP ERROR! (tep_display_banner(' . $action . ', ' . $identifier . ') -> Unknown $action parameter value - it must be either \'dynamic\' or \'static\'</b>';

}

 

if (tep_not_null($banner['banners_html_text'])) {

$banner_string = $banner['banners_html_text'];

} else {

$banner_string = '<a href="' . tep_href_link(FILENAME_REDIRECT, 'action=banner&goto=' . $banner['banners_id']) . '" target="_blank">' . tep_image(DIR_WS_IMAGES . $banner['banners_image'], $banner['banners_title']) . '</a>';

}

 

tep_update_banner_display_count($banner['banners_id']);

 

return $banner_string;

}

 

and rename it within the same page?

and after add the code you wrote in my special.php page?

Posted

yes thats the function well ok here is a simple way. Just add the code wherever you want to display all banners of this 480x62 group

 

<?php
$identifier = '480x62';
$banners_returned_query = tep_db_query("select count(*) as count from " . TABLE_BANNERS . " where status = '1' and banners_group = '" . $identifier . "'");

 while($banner = tep_db_fetch_array($banners_returned_query))
 {
echo '<tr><td>' . '<a href="' . tep_href_link(FILENAME_REDIRECT, 'action=banner&goto=' . $banner['banners_id']) . '" target="_blank">' . tep_image(DIR_WS_IMAGES . $banner['banners_image'], $banner['banners_title']) . '</a></td></tr>';

 }
?>

Posted

Man, I dont know what do you mean.

 

I tried to add the last bit of code to the page and does not return anything. I just added that last code, nothing else.

 

Can you explain to me a little bit better what to add to specials.php to get all th banners from that group?

Thanks a lot

 

(You know a lot of MySQL and PHP dont you?)

Posted

ok post your specials.php code (or the place inside your specials.php you want this code to be appended) And make sure all your banners you want to display in that page are set with a group called 480x62 in your admin banner manager.

Posted

Here's the specials.php code:

(ON BLUE, THE CODE I USED TO DISPLAY A BANNER, AND THE PLACE WHERE I NEED THEM ALL)

 

 

 

====================================================================

<?php

/*

$Id: specials.php,v 1.49 2003/06/09 22:35:33 hpdl Exp $

 

osCommerce, Open Source E-Commerce Solutions

http://www.oscommerce.com

 

Copyright © 2003 osCommerce

 

Released under the GNU General Public License

*/

 

require('includes/application_top.php');

 

require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_SPECIALS);

 

$breadcrumb->add(NAVBAR_TITLE, tep_href_link(FILENAME_SPECIALS));

?>

<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">

<html <?php echo HTML_PARAMS; ?>>

<head>

<?php

// BOF: WebMakers.com Changed: Header Tag Controller v2.5.2

// Replaced by header_tags.php

if ( file_exists(DIR_WS_INCLUDES . 'header_tags.php') ) {

require(DIR_WS_INCLUDES . 'header_tags.php');

} else {

?>

<title><?php echo TITLE; ?></title>

<?php

}

// EOF: WebMakers.com Changed: Header Tag Controller v2.5.2

?><base href="<?php echo (($request_type == 'SSL') ? HTTPS_SERVER : HTTP_SERVER) . DIR_WS_CATALOG; ?>">

<link rel="stylesheet" type="text/css" href="stylesheet.css">

<script language="JavaScript" type="text/JavaScript">

<!--

function MM_swapImgRestore() { //v3.0

var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a)&&x.oSrc;i++) x.src=x.oSrc;

}

 

function MM_preloadImages() { //v3.0

var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();

var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)

if (a.indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a;}}

}

 

function MM_findObj(n, d) { //v4.01

var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {

d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}

if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[n];

for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers.document);

if(!x && d.getElementById) x=d.getElementById(n); return x;

}

 

function MM_swapImage() { //v3.0

var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)

if ((x=MM_findObj(a))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}

}

//-->

</script>

</head>

<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0">

<!-- header //-->

<?php require(DIR_WS_INCLUDES . 'header.php'); ?>

<!-- header_eof //-->

 

<!-- body //--><table border="0" width="760" align="center" cellspacing="3" cellpadding="3">

<tr>

<td width="<?php echo BOX_WIDTH; ?>" valign="top"><table border="0" width="<?php echo BOX_WIDTH; ?>" cellspacing="0" cellpadding="2">

<!-- left_navigation //-->

<?php require(DIR_WS_INCLUDES . 'column_left.php'); ?>

<!-- left_navigation_eof //-->

</table><a href="http://www.facialworksdublin.com/environ-dublin.php"><img src="images/environ_intro.gif" width="125" alt="LEARN MORE ABOUT ENVIRON" height="141" hspace="0" vspace="0" border="0"></a></td>

<!-- body_text //-->

<td width="100%" valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="0">

<tr>

<td><table border="0" width="100%" cellspacing="0" cellpadding="0">

<tr>

<td class="pageHeading"><?php echo HEADING_TITLE; ?></td>

<td class="pageHeading" align="right"> </td>

</tr>

</table><?php if ($banner = tep_banner_exists('dynamic', '480x62')) {

?>

<?php echo tep_display_banner('static', $banner); ?>

<?php

}

?>

</td>

</tr>

<tr>

<td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>

</tr>

<?php

$specials_query_raw = "select p.products_id, pd.products_name, p.products_price, p.products_tax_class_id, p.products_image, s.specials_new_products_price from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_SPECIALS . " s where p.products_status = '1' and s.products_id = p.products_id and p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "' and s.status = '1' order by s.specials_date_added DESC";

$specials_split = new splitPageResults($specials_query_raw, MAX_DISPLAY_SPECIAL_PRODUCTS);

 

if (($specials_split->number_of_rows > 0) && ((PREV_NEXT_BAR_LOCATION == '1') || (PREV_NEXT_BAR_LOCATION == '3'))) {

?>

<tr>

<td><table border="0" width="100%" cellspacing="0" cellpadding="2">

<tr>

<td colspan="2" class="pageHeading">Special Online Exclusives</td>

</tr>

<tr>

<td class="smallText"><?php echo $specials_split->display_count(TEXT_DISPLAY_NUMBER_OF_SPECIALS); ?></td>

<td align="right" class="smallText"><?php echo TEXT_RESULT_PAGE . ' ' . $specials_split->display_links(MAX_DISPLAY_PAGE_LINKS, tep_get_all_get_params(array('page', 'info', 'x', 'y'))); ?></td>

</tr>

</table></td>

</tr>

<tr>

<td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>

</tr>

<?php

}

?>

<tr>

<td><table border="0" width="100%" cellspacing="0" cellpadding="2">

<tr>

<?php

$row = 0;

$specials_query = tep_db_query($specials_split->sql_query);

while ($specials = tep_db_fetch_array($specials_query)) {

$row++;

 

echo ' <td align="center" width="33%" class="smallText"><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $specials['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $specials['products_image'], $specials['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a><br><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $specials['products_id']) . '">' . $specials['products_name'] . '</a><br><s>' . $currencies->display_price($specials['products_price'], tep_get_tax_rate($specials['products_tax_class_id'])) . '</s><br><span class="productSpecialPrice">' . $currencies->display_price($specials['specials_new_products_price'], tep_get_tax_rate($specials['products_tax_class_id'])) . '</span></td>' . "\n";

 

if ((($row / 3) == floor($row / 3))) {

?>

</tr>

<tr>

<td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>

</tr>

<tr>

<?php

}

}

?>

</tr>

</table></td>

</tr>

<?php

if (($specials_split->number_of_rows > 0) && ((PREV_NEXT_BAR_LOCATION == '2') || (PREV_NEXT_BAR_LOCATION == '3'))) {

?>

<tr>

<td><br><table border="0" width="100%" cellspacing="0" cellpadding="2">

<tr>

<td class="smallText"><?php echo $specials_split->display_count(TEXT_DISPLAY_NUMBER_OF_SPECIALS); ?></td>

<td align="right" class="smallText"><?php echo TEXT_RESULT_PAGE . ' ' . $specials_split->display_links(MAX_DISPLAY_PAGE_LINKS, tep_get_all_get_params(array('page', 'info', 'x', 'y'))); ?></td>

</tr>

</table></td>

</tr>

<?php

}

?>

</table></td>

<!-- body_text_eof //-->

<td width="<?php echo BOX_WIDTH; ?>" valign="top"><table border="0" width="<?php echo BOX_WIDTH; ?>" cellspacing="0" cellpadding="2">

<!-- right_navigation //-->

<?php require(DIR_WS_INCLUDES . 'column_right.php'); ?>

<!-- right_navigation_eof //-->

</table></td>

</tr>

</table>

<!-- body_eof //-->

 

<!-- footer //-->

<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>

<!-- footer_eof //-->

<br>

</body>

</html>

<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>

===========================================================

 

This is the end.

Posted

ok, backup first, then change this:

 

</table><?php if ($banner = tep_banner_exists('dynamic', '480x62')) {
?>
<?php echo tep_display_banner('static', $banner); ?>
<?php
}
?>

 

to this:

</table>
<?php 
$identifier = '480x62';
$banners_returned_query = tep_db_query("select count(*) as count from " . TABLE_BANNERS . " where status = '1' and banners_group = '" . $identifier . "'");

while($banner = tep_db_fetch_array($banners_returned_query))
{
echo '<tr><td>' . '<a href="' . tep_href_link(FILENAME_REDIRECT, 'action=banner&goto=' . $banner['banners_id']) . '" target="_blank">' . tep_image(DIR_WS_IMAGES . $banner['banners_image'], $banner['banners_title']) . '</a></td></tr>';

}
?>

Posted

In the meantime, I left the code as you can read above in the specials.php, cause I need to show at least one banner. But I will be most grateful if you could help me with this, and try to display all banners from a group in that page. Cheers!

Posted

yes somehow I placed the code to only get the banners count. Try this instead:

 

</table>
<?php 
$identifier = '480x62';
$banners_returned_query = tep_db_query("select banners_id, banners_image, banners_title from " . TABLE_BANNERS . " where status = '1' and banners_group = '" . $identifier . "'");

while($banner = tep_db_fetch_array($banners_returned_query))
{
echo '<tr><td>' . '<a href="' . tep_href_link(FILENAME_REDIRECT, 'action=banner&goto=' . $banner['banners_id']) . '" target="_blank">' . tep_image(DIR_WS_IMAGES . $banner['banners_image'], $banner['banners_title']) . '</a></td></tr>';

}
?>

 

Same place as before to replace the code.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...