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
https://forums.phpfreaks.com/topic/20519-need-help-with-writing-php-to-file/
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.

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. =)

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.