Some code seemes to have distroy the script

Discuss Programming
Post Reply
User avatar
Basher52
guru
guru
Posts: 930
Joined: Wed Oct 22, 2003 5:57 am
Location: .SE

Some code seemes to have distroy the script

Post by Basher52 »

In this place: http://boxerville.se/forum/ I've been asked to help out with some php coding and stuff.
In the forum there's a banner centered with links to places that can help people with getting their VW's fixed that I added which uses a small mysql DB table and some smaller script to read that data in create the html output.
It has worked before as I added more sponsor after sponsor for that website but now long after I added the last I found that the "click function" to create a new tab in the browser and open the site is not working.
I've been trying to figure out what it is but I can't find it and now a sponsor has seen it and want it fixed fast or he will pull his sponsorship back.

The following scripts are from a test site I put up but I have the same problem at this place.
I found these and has modified them not to create an array of four images per row, so it's not totally fresh code.

"banner.class.php" - Creates the html data from the database

Code: Select all

<?php

class Banner{

        private $data = array();

        public function __construct($row){
                $this->data = $row;
        }

        public function html(){

                /* This method returns the banner's HTML code */

                $d = &$this->data;
                $d['company'] = htmlspecialchars($d['company']);

                return '<div class="banner"
                                <a href="'.$d['url'].'" target="_blank">
                                        <img src="img/banners/'.$d['image'].'" alt="'.$d['company'].'"
                                        width="728" height="90" margin: 0 auto;
                                        />
                                </a>
                        </div>';
        }

}



/*
                return '<div class="banner"


                return '<div class="banner1"
                                <a href="'.$d['url'].'" target="_blank">
                                        <img src="img/banners/'.$d['image'].'" alt="'.$d['company'].'"
                                        width="728" height="90" margin: 0 auto;
                                        />
                                </a>
                        </div>';


*/

?>

"banner.php" - Reads the DB table

Code: Select all

<?php
/**
 * Displays a list of the categories/forums that the current user can see, along with some statistics.
 *
 * @copyright (C) 2008-2009 PunBB, partially based on code (C) 2008-2009 FluxBB.org
 * @license http://www.gnu.org/licenses/gpl.html GPL version 2 or higher
 * @package PunBB
 */


if (!defined('FORUM_ROOT'))
        define('FORUM_ROOT', './');

require "connect.php";
require "banner.class.php";

// Error reporting:
error_reporting(E_ALL^E_NOTICE);

$bannerResult = mysql_query("SELECT * FROM banners");
mysql_close();

$banners = array();
while($row=mysql_fetch_assoc($bannerResult))
{
        $banners[] = new Banner($row);
}

// Randomizing the $banners array:
shuffle($banners);

// Splitting the banners array into smaller arrays with 4 banners each:
$bannerGroups = array_chunk($banners,1);
?> 

   <!-- Line of banners -->

   <div class="bannerHolder">
        <?php   

                // Looping through the first group:
                foreach($bannerGroups[0] as $ban)
                {
                        echo $ban->html();
                }
        ?>
    </div>
"connect.php" - data to connect to the database

Code: Select all

<?php

/* Database config */

$db_host                = 'xxx';
$db_user                = 'xxxxxx';
$db_pass                = 'xxxxxxxxxx;
$db_database            = 'xx';

/* End config */


$link = @mysql_connect($db_host,$db_user,$db_pass) or die('Unable to establish a DB connection');

mysql_set_charset('utf8');
mysql_select_db($db_database,$link);

?>

and last the css file (at least some part of it)

Code: Select all

/* Banners
-------------------------------------------------------------------*/

.brd .banner{
        /* The banner divs */
        position:relative;
        overflow:hidden;
        background-position: center;
        text-align:center; /* centers in old versions of IE*/
        margin-bottom: 10px;
}



.brd .banner p{
        /* The "Visit Company" text */

        display:none;  /* hidden by default */

        left:0;
        top:57px;
        width:100%;
        z-index:200;
        position:relative;

        font-family:Tahoma, Arial, Helvetica, sans-serif;
        color:white;
        font-size:11px;
        text-align:center;

        cursor:pointer;
}

/* Banners
-------------------------------------------------------------------*/

All this seems OK to me but it's not working... at least not any more.
If I remove the 'div' in banner.class.php

Code: Select all

<div class="banner"
and it's end

Code: Select all

</div>
the link will work but it won't get centered.

All I can think of is that some other code somewhere trashes this but that will take forever to find :cry:
I also know that you might need all the code to find the error but I hope you can give me some hints where to look.

I'm starting to get nervous for not finding this error and they might lose a sponsor :(

please help and fast too... if you can


//TIA B52

User avatar
Void Main
Site Admin
Site Admin
Posts: 5716
Joined: Wed Jan 08, 2003 5:24 am
Location: Tuxville, USA
Contact:

Re: Some code seemes to have distroy the script

Post by Void Main »

I didn't really look at it in detail but shouldn't your "<div *" statement have a ">" at the end of it?

User avatar
Basher52
guru
guru
Posts: 930
Joined: Wed Oct 22, 2003 5:57 am
Location: .SE

Re: Some code seemes to have distroy the script

Post by Basher52 »

:evil: :evil: :evil:

How can I not see so obvious things :( added that and it works :D
Once again you have saved my life :P


btw... if the html created is broken, how come the page can be shown at all?

Post Reply