Jump to content

Loop query inside an array


Julian

Recommended Posts

Hello guys..

 

I found this useful script that helps me rotate my banners, but I don't know how to change the array for a query from my database.  Here's the example:

 

mysql_select_db($database_xxx, $xxx);
$query_banner = sprintf("SELECT * FROM banners");
$banner = mysql_query($query_banner, $xxx) or die(mysql_error());
$totalRows_banner = mysql_num_rows($banner);

$banners = array(
"http://www.website.com,image.png",
"http://www.example.com,images/banner.jpg"
);

//I want to change what's on the array $banners for my sql results in a loop
//tried replacing for: 

$banners = array();
while (list($link, $banner1) = mysql_fetch_row($banners)) {	 
	$banners[$banner]=array('http://www.mysite.com/click.php?id='.$link.',/images/banners/'.$banner1);
}
//no luck so far.

$randnum = rand(0, count($banners) - 1); // Choose a random banner
$exploded = explode(",", $banners[$randnum]); // Separate chosen banner by ,

$url = $exploded[0]; // Grab the URL for the banner
$img = $exploded[1]; // Grab the image for the banner

// Display the banner
echo "<a href=\"$url\">";
echo "<img src=\"$img\" border=\"0\" />";
echo "</a>";

 

Any help will be highly appreciated.

Link to comment
https://forums.phpfreaks.com/topic/141862-loop-query-inside-an-array/
Share on other sites

Archived

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

×
×
  • 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.