Web Hosting Talk







View Full Version : PHP Loop Programming Question


saj
02-09-2005, 07:31 AM
Hi all

wonder if anyone can help me on a PHP Issue

I have a script on my forum (vbulletin) forum which calls a php script ..which displays random links

the file is called sp_ads.php

Ok thing is when i include the file (on my index.php file) using the following format:

require_once("http://www.mpadc.com/forums/sp_ads.php");

it only shows one instance of the Links
i.e like this

link1

basically i want it to display in this format

link 1 ::: link 2 ::: link3 ::: link4 ::: link5 ::: link6::

with seperators

i know i need a loop to do this but im an PHP idiot!

anyone have ideas?

thanks

Burhan
02-09-2005, 09:48 AM
This would depend on the script and how it works.

require_once means that the script will only be included once. You need to configure the sp_ads.php script to display the ads as you want.

Xenatino
02-09-2005, 10:16 AM
Are the links stored in a MySQL database, text file or what? Try posting your current code and someone can inform you what you need to change to aide your problem.

Omega-Mark
02-09-2005, 07:11 PM
I didn't know you could remotely link php script through http on another server, like a client can't view the code in a php script if they just go to it.

Clients_for_sale
02-10-2005, 11:52 PM
you could modify the code and insert a " while" command

Seems that would be what you are looking for

saj
02-11-2005, 06:28 AM
Thanks guys

i actually got it working using the below code which ii stuck in my archive/index.php page

only problem is its calling the file 6 different times..is there a way to loop it all ?

Basically what the script does it contains a load of Links in the PHP script. Each time the Page is reloaded a random link is displayed on the webpage but only one link, i wanted my code to Display 6 random links from the script




echo "<center><b>Shariah Sponsored Links</b><br></center>" ;

include ("http://www.mpadc.com/forums/sp_ads.php");

echo ":::";

include ("http://www.mpadc.com/forums/sp_ads.php");

echo ":::";
include ("http://www.mpadc.com/forums/sp_ads.php");
echo ":::";
include ("http://www.mpadc.com/forums/sp_ads.php");
echo ":::";
include ("http://www.mpadc.com/forums/sp_ads.php");
echo ":::";
include ("http://www.mpadc.com/forums/sp_ads.php");
echo ":::";

runesolutions
02-11-2005, 07:36 AM
How about:


echo "<center><b>Shariah Sponsored Links</b><br></center>" ;
for ($i = 0; $i < 6; $i++)
{
include ("http://www.mpadc.com/forums/sp_ads.php");
echo ":::";
}

saj
02-11-2005, 08:22 AM
Thanks dude! it worked :)

AaronTHUG
02-12-2005, 11:12 AM
why not just code the sp_ads.php file to output five?

fastduke
02-14-2005, 01:28 AM
I would think that 'sp_ads.php' should be a script with a function in it then just require_once the thing and do something like:

show_links(5); // argument passed returns n links


Just IMHO.