Jump to content

Archived

This topic is now archived and is closed to further replies.

mazman13

Need help with writing PHP to file

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?

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites
So you do a simple COUNT() query on the database and plug the result of that query into the random function.

Does that make sense or do you need help writing the query?

Share this post


Link to post
Share on other sites
Yeah I just thought about that. I don't need to update it with a text file, I just need to have that file count the number of rows in the database, and update that number...

That will work. I'll test it and see how it goes.
Thanks

Share this post


Link to post
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. =)

Share this post


Link to post
Share on other sites

×

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.