DavidAbineri Posted December 21, 2021 Share Posted December 21, 2021 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> Quote Link to comment https://forums.phpfreaks.com/topic/314338-trying-to-use-php-rand-function-newbie/ Share on other sites More sharing options...
Solution Barand Posted December 21, 2021 Solution Share Posted December 21, 2021 Is the file that the code is in a .PHP file or a .HTML file? If it's not .php, rename it and try again. Quote Link to comment https://forums.phpfreaks.com/topic/314338-trying-to-use-php-rand-function-newbie/#findComment-1592901 Share on other sites More sharing options...
requinix Posted December 21, 2021 Share Posted December 21, 2021 Separately, XHTML has been dead for years. Longer than it was alive, I think. Learn and use HTML 5 instead. 1 Quote Link to comment https://forums.phpfreaks.com/topic/314338-trying-to-use-php-rand-function-newbie/#findComment-1592902 Share on other sites More sharing options...
DavidAbineri Posted December 21, 2021 Author Share Posted December 21, 2021 Thank you, Barand. I know that php can be included in html files but what is the rul for name the file html or .php? Many thanks for these responses. David Abineri Quote Link to comment https://forums.phpfreaks.com/topic/314338-trying-to-use-php-rand-function-newbie/#findComment-1592903 Share on other sites More sharing options...
Barand Posted December 21, 2021 Share Posted December 21, 2021 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!). Quote Link to comment https://forums.phpfreaks.com/topic/314338-trying-to-use-php-rand-function-newbie/#findComment-1592904 Share on other sites More sharing options...
DavidAbineri Posted December 22, 2021 Author Share Posted December 22, 2021 Thank you for that clarification, I was not aware of that but it makes sense. David Abineri Quote Link to comment https://forums.phpfreaks.com/topic/314338-trying-to-use-php-rand-function-newbie/#findComment-1592910 Share on other sites More sharing options...
DavidAbineri Posted December 22, 2021 Author Share Posted December 22, 2021 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 Quote Link to comment https://forums.phpfreaks.com/topic/314338-trying-to-use-php-rand-function-newbie/#findComment-1592911 Share on other sites More sharing options...
benanamen Posted December 22, 2021 Share Posted December 22, 2021 You have the $ sign bass ackwards. It comes first. Quote Link to comment https://forums.phpfreaks.com/topic/314338-trying-to-use-php-rand-function-newbie/#findComment-1592914 Share on other sites More sharing options...
DavidAbineri Posted December 22, 2021 Author Share Posted December 22, 2021 In Visual Basic it is x$, y$ which is what caused this. Please elaborate on what you mean by the xy problem? Thanks, David Abineri Quote Link to comment https://forums.phpfreaks.com/topic/314338-trying-to-use-php-rand-function-newbie/#findComment-1592922 Share on other sites More sharing options...
Phi11W Posted December 22, 2021 Share Posted December 22, 2021 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. Quote Link to comment https://forums.phpfreaks.com/topic/314338-trying-to-use-php-rand-function-newbie/#findComment-1592923 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.