Jump to content

Need help with writing PHP to file


mazman13

Recommended Posts

I'm trying to have it so my PHP script will rewrite a PHP file with the following information:

<?php $imgad_num = rand(1, [b]$num[/b]); ?>

The $num of course will be replaced with a number before it's sent out, so the writing will be:

<?php $imgad_num = rand(1, 8); ?>
Something like that.

Can I put this in a var?
Anyideas?

Link to comment
Share on other sites

Well I'm using this script to pick a random number for banner ads. Everything is already in place and working, I just don't like adding a banner to the database AND updating that file to a new number everytime. I would like to add to the database and have PHP update the number.

It random. 1 - whatever numbers of banners there are in the database. Right now I have 7, so its 1, 7. But if I add another one I want PHP to make it to 8 and so on.

Link to comment
Share on other sites

Use the php code:
[code]
$sql = "SELECT * FROM banners ORDER BY ASC"; // Make sure you change banners to your table name.
$resultofmysql_query = mysql_query($sql);
$count = mysql_num_rows($resultofmysql_query); // the result variable should be the mysql query string that gets all rows from database
$randomnumber = rand(1,$count); // This will generate a random number between 1 and the total number of rows.
[/code]
<br>
I think this should work pretty simple someone correct me if I made a mistake please, want to make sure I'm giving accurate advice. =)
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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