Forum Moderators: coopster

Message Too Old, No Replies

Array help

array help

         

BlackRaven

12:47 pm on Jun 18, 2005 (gmt 0)

10+ Year Member



hi, ok i recently added ebay editors kit on my site, but instead of manually inserting the links i thought i could do it dynamically. All i am trying to do is pass the values of $category, $minprice, $query below to the ad script ("<script>...yata yata..".$category."</script>")

So like how do i randomly select an ad given that its a arrary.

//for example

$ad1[0]=6789;
$ad1[1]=20;
$ad1[2]=mint;

$ad2[0]=6769;
$ad2[1]=70;
$ad2[2]=mint;

$ad3[0]=6790;
$ad3[1]=55;
$ad3[2]=mint;

// so i am guess i just use the shuffle rite?
$adfinal=shuffle(ad1,ad2,ad3);

$category=$adfinal[0];
$minprice=$adfinal[1];
$query=$adfinal[2];

dreamcatcher

4:52 pm on Jun 18, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can do it like this:


$ad[0]['cat']=6789;
$ad[0]['min']=20;
$ad[0]['query']=mint;

$ad[1]['cat']=6769;
$ad[1]['min']=70;
$ad[1]['query']=mint;

$ad[2]['cat']=6790;
$ad[2]['min']=55;
$ad[2]['query']=mint;

Then:

shuffle($ad);
$random = array_rand($ad, 1);

echo $ad[$random]['cat'];
echo $ad[$random]['min'];
echo $ad[$random]['query'];

Hope that helps.

dc

BlackRaven

9:04 pm on Jun 18, 2005 (gmt 0)

10+ Year Member



thanks works now