Jump to content

Trying to use php rand() function (newbie)


Go to solution Solved by Barand,

Recommended Posts

I am just trying to get a single random number to show on the page using this code which shows nothing for me. Any assistance will be appreciated.

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<body>

<?php
echo rand(1,100);
?>

</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/314338-trying-to-use-php-rand-function-newbie/
Share on other sites

18 minutes ago, DavidAbineri said:

but what is the rul for name the file html or .php?

If the php code didn't work when it was a .html file but did work when changed to a .php file, then that should be a clue.

The default configuration on most servers is that php code must be in a .php file to be processed.

A .php file may contain html (in fact it doesn't need to contain any php!).

It looks like I have a secondary problem along these lines too.

I am trying to assign two variable each a random number but this does not work.  Can you advise on how to accomplish this

<?php
x$=rand(1,100);
y$=rand(1,100);

echo x$." ".y$;

?>

Thank you for your time again.

 

David Abineri

 

1 hour ago, DavidAbineri said:

Please elaborate on what you mean by the xy problem?

Did you try following the link under "The XY Problem"??

It's asking a very [very] specific question about a solution you're trying to get working when the "correct" answer involves taking a different path altogether, for example:

"X" Question: "How can I stop llamas from chewing the cushions on my sofa." (requesting a solution to a very specific, small-scale issue.)
"Y" Question: "How do I stop llamas getting into my house." (asking a far broader question, the solving of which would completely eliminate the need for the original solution). 

Regards, 
   Phill  W.

 

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.