mazman13 Posted September 12, 2006 Share Posted September 12, 2006 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? Quote Link to comment https://forums.phpfreaks.com/topic/20519-need-help-with-writing-php-to-file/ Share on other sites More sharing options...
makeshift_theory Posted September 12, 2006 Share Posted September 12, 2006 What do you want the final product to be that's a better question here.. Quote Link to comment https://forums.phpfreaks.com/topic/20519-need-help-with-writing-php-to-file/#findComment-90503 Share on other sites More sharing options...
mazman13 Posted September 12, 2006 Author Share Posted September 12, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/20519-need-help-with-writing-php-to-file/#findComment-90515 Share on other sites More sharing options...
ober Posted September 12, 2006 Share Posted September 12, 2006 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? Quote Link to comment https://forums.phpfreaks.com/topic/20519-need-help-with-writing-php-to-file/#findComment-90519 Share on other sites More sharing options...
mazman13 Posted September 12, 2006 Author Share Posted September 12, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/20519-need-help-with-writing-php-to-file/#findComment-90520 Share on other sites More sharing options...
makeshift_theory Posted September 13, 2006 Share Posted September 13, 2006 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. =) Quote Link to comment https://forums.phpfreaks.com/topic/20519-need-help-with-writing-php-to-file/#findComment-91180 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.