0

Hello,

I am trying to work out a PHP page which establishes a sequenced rotation of ADS.

Here is the code so far. There are some elements missing that need help with.

<?php

include("core.php");
session_start();

$type = $_GET['type'];
$category = $_GET['category'];
$User = $_SESSION['MEMEBER_ID'];
$Type = "image_imp";

// Get Initial Large Banner List
if($_SESSION['Category'] == $category ) {

}else{

$query="SELECT id,Ad_Name,URI,URL FROM sm_ADS WHERE id_Maze_Category='$category' and Type='large' and Active='1' ORDER BY RAND()";
$result = $db->query($query) or die($db->error());
$_Session['largeAdsList'] = $result->fetch_array();

}

$ID = $_Session['largeAdsList'][0];

echo "<a href=\"".$_Session['largeAdsList'][3]."\"><img src=\"".$_Session['largeAdsList'][2]."\" border=\"0\" alt=\"".$_Session['largeAdsList'][1]."\" /></a>";

$sql="INSERT INTO sm_History (AD_ID, User_ID, Type) VALUES ('ID','$User','$Type')";
$result = $db->query($sql) or die($db->error());



?>

Basically, I want to test to see if $_SESSION = $category

If it does, then we assume that there is already a AD LIST in the $_Session. ELSE we need to GENERATE the list using the query:

$query="SELECT id,Ad_Name,URI,URL FROM sm_ADS WHERE id_Maze_Category='$category' and Type='large' and Active='1' ORDER BY RAND()";

In both cases, I want to be able to get the first LINE of the $_Session array for my display and history processes.

When I generate form the query everything works fine. When the test is TRUE, I have problems getting the row from the existing session variable.

After I can retrieve the line of the array in both cases, I then want to take that line in my session variable and rotate it to the end of the list so thus causing a rotation.

So if I start having these lines in my $_Session:

2
3
4
5

I grab the 2 line for display and history processes

then the end result will change the $_Session to

3
4
5
2

And so on...

I appreciate any help that can be offered.

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by blocblue
0

Hey, try looking at the array_push and array_shift methods.

Array_shift removes the first element in the array and returns it to you. Array_push adds the pushed element to the end of the array.

Does that do what you require?

R.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.