Jump to content

rotaing banner ads... Need help!


wakerider017

Recommended Posts

I am trying to create an advertisement table just like LS1tech.com...


Yet I am having some difficulties...

NOTE: I am using Vbulletin...


This is my database that I have setup:
[a href=\"http://img107.imageshack.us/img107/4594/help6oo.jpg\" target=\"_blank\"]http://img107.imageshack.us/img107/4594/help6oo.jpg[/a]


Since the advertisement table is in th template I can not directly use php...


I need to put the php in another file and then call on it in the template...




Here is what I have so far:

[code]$sql = "SELECT * FROM `table_name` ORDER BY RAND()";
$result = mysql_query($sql) or die(mysql_error());
while ($row = mysql_fetch_object($result))
{
    $ads_HREF = "$row->HREF";
    $ads_SRC = "$row->SRC";
    $ads_ALT = "$row->ALT";
}[/code]



and I call on it with this:

[code]<tr><td>
<a href='$ads_HREF'><img src='$ads_SRC' name='$ads_ALT' border=0></a></td></tr> [/code]



but... there is a problem with this... it shows the same ad 5 times! I want 5 different ads!


I think I may need to use an array... but I am not sure how...


Anyone want to help?
Link to comment
Share on other sites

I think you are running the loop $row times, but each time you overwrite the exsisting the $ads_HREF, $ads_SRC and $ads_ALT, and just show the last one. Add the second part to the first, this way:
[code]<?php
$sql = "SELECT * FROM `table_name` ORDER BY RAND()";
$result = mysql_query($sql) or die(mysql_error());
while ($row = mysql_fetch_object($result))
{
    $ads_HREF = "$row->HREF";
    $ads_SRC = "$row->SRC";
    $ads_ALT = "$row->ALT";
?>
<tr><td>
<a href='<?php echo($ads_HREF); ?>'><img src='<?php echo($ads_SRC); ?>' name='<?php echo($ads_ALT); ?>' border=0></a></td></tr>
<?php
}//close while;
//continue code
?>
[/code]


But if you want you can also use arrays:
[code]<?php
$sql = "SELECT * FROM `table_name` ORDER BY RAND()";
$result = mysql_query($sql) or die(mysql_error());
$i=0;
while ($row = mysql_fetch_object($result))
{
    $ads_HREF[$i] = "$row->HREF";
    $ads_SRC[$i] = "$row->SRC";
    $ads_ALT[$i] = "$row->ALT";
    $i++;
?>
[/code]
And then have a second loop for the ads:
[code]<?php
$i=0;
$number_of_ads= //Enter the number of ads;
while($i<number_of_ads)
{
?>
<tr><td>
<a href='<?php echo($ads_HREF[$i]); ?>'><img src='<?php echo($ads_SRC[$i]); ?>' name='<?php echo($ads_ALT[$i]); ?>' border=0></a></td></tr>
<?php
$i++;
}//close while;
?>
[/code]


Good luck :)

Orio.
Link to comment
Share on other sites

[code] <?php
$i=0;
$number_of_ads= //Enter the number of ads;
while($i<number_of_ads)
{
?>
<tr><td>
<a href='<?php echo($ads_HREF[$i]); ?>'><img src='<?php echo($ads_SRC[$i]); ?>' name='<?php echo($ads_ALT[$i]); ?>' border=0></a></td></tr>
<?php
$i++;
}//close while;
?>[/code]


That looks good.... except this is for my forums... I can not use PHP in the template...


So i need php and then I call on it with HTML...


Thats why I had two seperate codes in the first post!


Thanks a bunch!


Do you think your array code could be altered to do what I am looking for?
Link to comment
Share on other sites

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.