Jump to content


Photo

Need help with writing PHP to file


  • Please log in to reply
5 replies to this topic

#1 mazman13

mazman13
  • Members
  • PipPipPip
  • Advanced Member
  • 156 posts

Posted 12 September 2006 - 03:47 PM

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

<?php $imgad_num = rand(1, $num); ?>

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?



#2 makeshift_theory

makeshift_theory
  • Members
  • PipPipPip
  • Advanced Member
  • 226 posts

Posted 12 September 2006 - 04:03 PM

What do you want the final product to be that's a better question here..
<b>Emacs</b> it's great for the body.
<br><br>
<b>Trust the TechnoLust</b>

<b><u>Have a question check here:</u></b>
PHP Manual: http://www.php.net

#3 mazman13

mazman13
  • Members
  • PipPipPip
  • Advanced Member
  • 156 posts

Posted 12 September 2006 - 04:11 PM

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.



#4 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 12 September 2006 - 04:13 PM

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?

Info: PHP Manual


#5 mazman13

mazman13
  • Members
  • PipPipPip
  • Advanced Member
  • 156 posts

Posted 12 September 2006 - 04:15 PM

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

#6 makeshift_theory

makeshift_theory
  • Members
  • PipPipPip
  • Advanced Member
  • 226 posts

Posted 13 September 2006 - 04:43 PM

Use the php 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.
<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. =)
<b>Emacs</b> it's great for the body.
<br><br>
<b>Trust the TechnoLust</b>

<b><u>Have a question check here:</u></b>
PHP Manual: http://www.php.net




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users