So.....Close.......

Place for questions and answers for all newcomers and new coders. This is a free for all forum, no question is too stupid and to noob.
Post Reply
User avatar
Xaos
Posts: 940
Joined: Wed Jan 11, 2012 4:01 am

So.....Close.......

Post by Xaos »

So, i'm THIS close to being able to breakthrough with my project and be done with it (maybe.......). I just need to know one more thing. But first, I kinda have to talk about the structure of the code. It runs three different functions to affect hte total, in this case we'll say $X. $X is updated on each of the functions. Got that part working down. But now I want to say if $X > 0, give a link to the front page and allow the user to run it again (with a user input on something that will change $X), and I got that part down. Now I just need to know how to declare $X = rand(0,1000); one time, then after that, it updates and keeps course with what it is after the function. SO basically after these functions, I want the user to be able to go to the home page, input a number for the other function that helps change $X, and $X stay the same as it was after the result of the first set of functions. Then I want to be able to display the result of the three functions and $X on the front page. Or maybe I should create a new page, identical to the front page, but have the session variables be called there? I'm a bit confused. Sorry for the long wall of text as well, and I hope it makes sense :D

Also, I can't get it to echo $stock here. Help on that too? :D

Code: Select all

<!DOCTYPE HTML>

<form action = "fish.php" method = post>
Input Harvest Rate<input type="text" name="harvest" id="harvest">
<input type = "submit" value="Submit">
</form>
  <?php
$stock = rand(0,10000);
echo $stock;
?>

</html>
User avatar
Hamilton
Posts: 114
Joined: Tue Sep 11, 2012 7:11 am

Re: So.....Close.......

Post by Hamilton »

I can't say of how to help with most of the items, but I may be able to help with the random situation.
Try mt_rand() instead of rand(). It provides better randomization and performance.

As for displaying it, just try:

Code: Select all

echo mt_rand(0,1000);
And see if you get a result, if you don't then as you will suspect, it has to be something else causing it; such as a layer displaying over it, or something with the form.
Sign off,
Hamilton
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Re: So.....Close.......

Post by Epiales »

Xaos wrote:So, i'm THIS close to being able to breakthrough with my project and be done with it (maybe.......). I just need to know one more thing. But first, I kinda have to talk about the structure of the code. It runs three different functions to affect hte total, in this case we'll say $X. $X is updated on each of the functions. Got that part working down. But now I want to say if $X > 0, give a link to the front page and allow the user to run it again (with a user input on something that will change $X), and I got that part down. Now I just need to know how to declare $X = rand(0,1000); one time, then after that, it updates and keeps course with what it is after the function. SO basically after these functions, I want the user to be able to go to the home page, input a number for the other function that helps change $X, and $X stay the same as it was after the result of the first set of functions. Then I want to be able to display the result of the three functions and $X on the front page. Or maybe I should create a new page, identical to the front page, but have the session variables be called there? I'm a bit confused. Sorry for the long wall of text as well, and I hope it makes sense :D

Also, I can't get it to echo $stock here. Help on that too? :D

Code: Select all

<!DOCTYPE HTML>

<form action = "fish.php" method = post>
Input Harvest Rate<input type="text" name="harvest" id="harvest">
<input type = "submit" value="Submit">
</form>
  <?php
$stock = rand(0,10000);
echo $stock;
?>

</html>
Yeah, not sure why stock's not working. Looks like you have it correct.
Nothing fancy, but a work in progress!

http://gameplaytoday.net
User avatar
Xaos
Posts: 940
Joined: Wed Jan 11, 2012 4:01 am

Re: So.....Close.......

Post by Xaos »

Hamilton wrote:I can't say of how to help with most of the items, but I may be able to help with the random situation.
Try mt_rand() instead of rand(). It provides better randomization and performance.

As for displaying it, just try:

Code: Select all

echo mt_rand(0,1000);
And see if you get a result, if you don't then as you will suspect, it has to be something else causing it; such as a layer displaying over it, or something with the form.
I tried that and still nothing appeared. Also, now it doesn't even generate $stock. Not sure what's happening,.
User avatar
Hamilton
Posts: 114
Joined: Tue Sep 11, 2012 7:11 am

Re: So.....Close.......

Post by Hamilton »

Ok, I think you need to have this code done this way...
I have tested it and it works (and yes, I got the same problems as you did with your older code.

Give this a shot:

Code: Select all

 <?php
	echo '<!DOCTYPE HTML>';

	echo '<form action = "fish.php" method = post>';
	echo 'Input Harvest Rate';
	echo '<input type="text" name="harvest" id="harvest">';
	echo '<input type = "submit" value="Submit">';
	echo '</form>';

	$stock = mt_rand(0,10000);
	echo $stock;

	echo '</html>';
?>
Last edited by Hamilton on Thu Sep 26, 2013 10:33 pm, edited 1 time in total.
Sign off,
Hamilton
User avatar
Hamilton
Posts: 114
Joined: Tue Sep 11, 2012 7:11 am

Re: So.....Close.......

Post by Hamilton »

Forgot, you will have to have the filename with a .php extension.
Sign off,
Hamilton
User avatar
Xaos
Posts: 940
Joined: Wed Jan 11, 2012 4:01 am

Re: So.....Close.......

Post by Xaos »

Thanks a bunch, Hamilton ! Now...anyone got any ideas for my other problem? :D
User avatar
MikuzA
Posts: 394
Joined: Thu Aug 08, 2013 8:57 am

Re: So.....Close.......

Post by MikuzA »

Not sure I understand your issue, let me go through it as I understand it.

You have this $X-variable, that goes through three functions and it is updated on all of these.

Not sure why you use functions but you might have a reason, or are just using word 'function' to mention it as a stage of where the $X is handled?

But according to your explanation of issue you have these,

1. If $X > 0, then >> throw a link for user to be able to declare $X again.
2. Then you have a phase where $X = rand(0,1000)?? What happens to whatever user declares?
3. ??? I lost my thought, I re-read your text and didn't find a third phase :D

I re-read and re-read your explanation but sorry I have some trouble understanding what you want :D

or is this what you want to know::
Then I want to be able to display the result of the three functions and $X on the front page.
As you mentioned also after this sentence, if the results are set by refreshing the page several times, you can use SESSION to store the value between refresh.

Or use some kind of database. In any case, if you you want a result that happens between several refreshes of page in different instances, you need to store the results in between when they meet your acceptance criteria.


When typing explanation, try pressing that enter a few times, it was really hard to read :P
Why so serious?

Business Intelligence, Data Engineering, Data Mining
PHP, HTML, JavaScript, Bash/KornShell, Python, C#, PL/SQL
MySQL, DB2, Oracle, Snowflake
Pentaho, DataStage, Matillion, Unity3D, Blender
User avatar
Xaos
Posts: 940
Joined: Wed Jan 11, 2012 4:01 am

Re: So.....Close.......

Post by Xaos »

MikuzA wrote:Not sure I understand your issue, let me go through it as I understand it.

You have this $X-variable, that goes through three functions and it is updated on all of these.

Not sure why you use functions but you might have a reason, or are just using word 'function' to mention it as a stage of where the $X is handled?

But according to your explanation of issue you have these,

1. If $X > 0, then >> throw a link for user to be able to declare $X again.
2. Then you have a phase where $X = rand(0,1000)?? What happens to whatever user declares?
3. ??? I lost my thought, I re-read your text and didn't find a third phase :D

I re-read and re-read your explanation but sorry I have some trouble understanding what you want :D

or is this what you want to know::
Then I want to be able to display the result of the three functions and $X on the front page.
As you mentioned also after this sentence, if the results are set by refreshing the page several times, you can use SESSION to store the value between refresh.

Or use some kind of database. In any case, if you you want a result that happens between several refreshes of page in different instances, you need to store the results in between when they meet your acceptance criteria.


When typing explanation, try pressing that enter a few times, it was really hard to read :P
Yeah, sorry about the explanation, haha. Basically. X is declared the mt_rand on the first page. Then, the user inputs another variable and runs the sim.

Then, three functions are run. One function adds to X, the other two take away from X. I want to then have a button that takes you back to a page where the user inputs another variable, but also keep the same X value from the previous spin and store this X value over each spin (IE X1, X2, etc.). Then display these X values on the page where the user inputs the other variable again

That make any more sense?
User avatar
MikuzA
Posts: 394
Joined: Thu Aug 08, 2013 8:57 am

Re: So.....Close.......

Post by MikuzA »

Yes, that makes more sense :D

If the storing is for one user only and is not needed 'tomorrow' for example, then use $_SESSION, to store it.
You can have an array in $_SESSION['X'] = Array(), and you just push the results to that.

Otherwise use a database.

Hope I understood what you need :)
Why so serious?

Business Intelligence, Data Engineering, Data Mining
PHP, HTML, JavaScript, Bash/KornShell, Python, C#, PL/SQL
MySQL, DB2, Oracle, Snowflake
Pentaho, DataStage, Matillion, Unity3D, Blender
Post Reply

Return to “Beginner Help and Support”