Jump to content

Help With A Loop


Recommended Posts

I am making an advertisement script that can be used for multiple adverts on a single page. It uses variables to determine what image show up and where.I need it to check if an image is available and if not, then it has to re-generate a number to show one.If you need me too, I could probably try to explain it more.

<?phpdo {$rndNum = mt_rand(1,2);switch($rndNum){case 1:if ($adStyle = 'vert'){  $advertImg = "_private/advert_available.png";  } else {  $advertImg = '';  }  $advertLink = "index.php?action=advertise";  break;case 2:if ($adStyle = 'vert'){  $advertImg = "_private/advert_available1.png";  } else {  $advertImg = '';  }  $advertLink = "index.php?action=advertise";  break;}}while ($advertImg = '');?>

I am so used to coding visual basic 6.0 this stuff is just too different for me.Is there maybe a do until function that i could say do this until $advertImg is NOT blank?

Edited by dzhax
Link to comment
Share on other sites

Once you have the filename, you can use the file_exists function to check if it exists.http://www.php.net/manual/en/function.file-exists.phpThis line needs 2 equal signs instead of 1:while ($advertImg = '');All of the if statements need 2 also:if ($adStyle == 'vert'){In most languages besides VB, 1 equal sign assigns a value, 2 equal signs check if something is equal. You don't want to assign a value, you want to check the value.

Edited by justsomeguy
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...