BenGoldberg
Members-
Posts
15 -
Joined
-
Last visited
Never
Profile Information
-
Gender
Not Telling
BenGoldberg's Achievements
Newbie (1/5)
0
Reputation
-
Still have figured this out, and I only have one more day. Anyone?
-
Eval seems to be the right function for my application, but for the life of me I can not get it to work. Here's the basic code I'm working with. <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <table> <tr> <td>Enter function y prime:</td> <td><input type="text" size="50" maxlength="" name="yprime" value="<?php echo (isset($_POST['yprime']) ? $_POST['yprime'] : '')?>" /></td> </tr> </table> </br> <input type="submit" name="rk" value="Submit" /> </form> <?php $yprime = strval( $_POST['yprime'] ); //saving the function as a string function dydx($x,$y){ eval("\$equation = \"$yprime\";"); return $equation; } echo dydx(3,2); //equals 0 when it should equal 9 (yprime being 3*$x) ?> (The example input i use for yprime is 3*$x) I've done hours of googling and researching how eval works, but no matter what I try, the function dydx() always returns 0. The code above is what I believe to be my best attempt at getting it to evaluate $yprime properly, but it doesn't work. Argh!
-
WOW I'm not sure why I forgot to try this. You would think it would work, and it does keep the values in the forms, which I wanted to do anyways. But I just tested it and as soon as I hit that second submit button it still wipes out all my old data. Now I really don't know why, but I guess I don't fully understand how the SELF POST method works. Any other ideas? And thank you btw for helping me with this, it's actually part of a school project that's due Thursday so it really is a big help.
-
One more question. So I have a function with two parameters, $x and $y. Here it is. function dydx($x,$y){ $equation = 2 * $x; return $equation; } Now here's the problem. I want $equation to be user defined. Easy enough, I use a post command and I get $equation to equal whatever the user inputs. The problem is that if I get input from the user, I'm not sure how to take that input and then have the function parameters work on it. Like if the user inputs "3*$x + 2*$y", i want to be able to let the parameters for the function dydx act on it. How could I go about doing this?
-
Ok so here's what I have now... <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <table> <tr> <td>Enter function y prime:</td> <td><input type="text" size="50" maxlength="" name="yprime" value="" /></td> </tr> <tr> <td>Enter number of partitions:</td> <td><input type="text" size="7" maxlength="7" name="partitions" value="" /></td> </tr> <tr> <td>Enter initial x value, x(0):</td> <td><input type="text" size="3" maxlength="3" name="initialx" value="" /></td> </tr> <tr> <td>Enter the ending x value:</td> <td><input type="text" size="3" maxlength="3" name="endingx" value="" /></td> </tr> <tr> <td>Enter initial y value, y(0):</td> <td><input type="text" size="3" maxlength="3" name="initialy" value="" /></td> </tr> </table> </br> <input type="submit" name="runge kutta name" value="Run Program" /> </form> <?php if ($_SERVER['REQUEST_METHOD'] == 'POST' ) { // make sure that the form is posted $yprime = $_POST['yprime']; $partitions = $_POST['partitions']; $initialx = $_POST['initialx']; $endingx = $_POST['endingx']; $initialy = $_POST['initialy']; function dydx($x,$y){ $equation = 2 * $x; return $equation; } if ($_POST['partitions'] != 0) { $h = ($endingx - $initialx)/$partitions; } $a[1] = $initialx; $b[1] = $initialy; for ($i = 1; $i <= $partitions; $i++) { $k1 = dydx($a[$i], $b[$i]); $k2 = dydx($a[$i] + (1/2)*$h, $b[$i] + (1/2)*$h*$k1); $k3 = dydx($a[$i] + (1/2)*$h, $b[$i] + (1/2)*$h*$k2); $k4 = dydx($a[$i] + $h, $b[$i] + $h*$k3); $a[$i + 1] = $a[$i] + $h; $b[$i + 1] = $b[$i] + (1/6)*$h*($k1 + 2*$k2 + 2*$k3 + $k4); } for ($i = 1; $i <= $partitions + 1; $i++) { $xyarray["$a[$i]"] = $b[$i]; } $_SESSION['graph'] = $xyarray; } // if ($_SERVER['REQUEST_METHOD'] == 'POST' ) ends ?> </br></br> Choose a partition of X: <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <select name="output"> <?php for ($i = 1; $i <= $partitions + 1; $i++) { echo "<option value=\"$b[$i]\">$a[$i]</option>\n"; } ?> </select> <input type="submit" name="runge kutta name" value="See Y" /> </form> <?php echo $_POST['output']; I put in my second post command to display the y value for the corresponding x value, and it almost works. It successfully displays the value I expect it to but it wipes out all the data from the $a and $b arrays at the same time. I would like to preserve that data until new data is inputted for partitions, initial x, ending x, and initial y. This is where I'm having problems.
-
Alright, here's the important stuff. Don't get too caught up in the math, the important thing to know is my $a array are my x values and my $b array are my y values. I created the drop down menu of the x values at the end but there is no attempt on there of trying to display the y values. But basically if they choose $a[37] I would like $b[37] to be displayed. <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <?php function dydx($x,$y){ $equation = 3 * pow($x, 2); return $equation; } ?> <table> <tr> <td>Enter number of partitions:</td> <td><input type="text" size="7" maxlength="7" name="partitions" value="" /></td> </tr> <tr> <td>Enter initial x value, x(0):</td> <td><input type="text" size="3" maxlength="3" name="initialx" value="" /></td> </tr> <tr> <td>Enter the ending x value:</td> <td><input type="text" size="3" maxlength="3" name="endingx" value="" /></td> </tr> <tr> <td>Enter initial y value, y(0):</td> <td><input type="text" size="3" maxlength="3" name="initialy" value="" /></td> </tr> </table> </br> <input type="submit" name="runge kutta name" value="Run Program" /> </form> <?php $partitions = $_POST['partitions']; $initialx = $_POST['initialx']; $endingx = $_POST['endingx']; $initialy = $_POST['initialy']; if ($_POST['partitions'] != 0) { $h = ($endingx - $initialx)/$partitions; } $a[1] = $initialx; $b[1] = $initialy; for ($i = 1; $i <= $partitions; $i++) { $k1 = dydx($a[$i], $b[$i]); $k2 = dydx($a[$i] + (1/2)*$h, $b[$i] + (1/2)*$h*$k1); $k3 = dydx($a[$i] + (1/2)*$h, $b[$i] + (1/2)*$h*$k2); $k4 = dydx($a[$i] + $h, $b[$i] + $h*$k3); $a[$i + 1] = $a[$i] + $h; $b[$i + 1] = $b[$i] + (1/6)*$h*($k1 + 2*$k2 + 2*$k3 + $k4); } for ($i = 1; $i <= $partitions + 1; $i++) { $xyarray["$a[$i]"] = $b[$i]; } $_SESSION['graph'] = $xyarray; ?> </br></br> Choose a partition of X: <select name="output"> <?php for ($i = 1; $i <= $partitions + 1; $i++) { echo "<option value=\"$a[$i]\">$a[$i]</option>\n"; } ?>
-
So basically I'm using PHP to solve a math problem for me. The user puts in a few parameters and the program runs those numbers through the algorithm and spits out a bunch of xy coordinates. I'm using the PHP SELF method to retrieve the user input. This all works fine, but it's afterwords that I run into problems. I create a drop down menu of all the x values and I want the user to be able to choose any x value they wish and to have the corresponding y value be displayed. The problem is that I have to use another POST command for this and when I do, it wipes out all the computed data. Of course the y-value is never displayed, and there lies the problem. I'm sure there are many ways to get around this, but I could not find one out myself. Anyone have any ideas?
-
[SOLVED] Using regex to get data between two quotation marks
BenGoldberg replied to BenGoldberg's topic in Regex Help
Ah yes, perfect. Thanks everyone! -
[SOLVED] Using regex to get data between two quotation marks
BenGoldberg replied to BenGoldberg's topic in Regex Help
Thanks you guys, it works just how I expect it to! The only thing is, is it possible to not copy the quotation marks? I just want the data inside them. -
[SOLVED] Using regex to get data between two quotation marks
BenGoldberg replied to BenGoldberg's topic in Regex Help
I entered in a valid string with quotation marks, but I'm just getting an empty array for $matches. I guess it's not matching anything. ??? -
I'm really horrible with regex but I need to use it for a site that I'm building, so that's why I'm here. Basically, I need to extract data between two quotation marks and store the value in a variable. An example of a string that I need to work on is... deg_F = "---.-" But I need to do this for quite a few lines. The cool thing is for every one, the data is inside the quotation marks. Another example... percent = "--" So the quotation marks don't always start at the same point since the strings are different, but the data I need is always inside the quotation marks. Any help would be greatly appreciated!
-
[SOLVED] Getting undefined offset error, but don't see why...
BenGoldberg replied to BenGoldberg's topic in PHP Coding Help
Ah yes, I see now. Duh. Well I knew it was something silly like that. -
[SOLVED] Getting undefined offset error, but don't see why...
BenGoldberg replied to BenGoldberg's topic in PHP Coding Help
Holy moly! Thank you so much, works perfectly now. Can I ask why this fixes the problem though? Why does $records[0] not count the values correctly? It seems like count($records) and count($records[0]) would output the same number no matter what. In any case, I can move on with my website now, so thanks again! -
[SOLVED] Getting undefined offset error, but don't see why...
BenGoldberg replied to BenGoldberg's topic in PHP Coding Help
Well it's displaying a lot, but here's the first two arrays it displays... array(3) { [0]=> array(3) { [0]=> string(3) "106" [1]=> string(11) "08 15, 2008" [2]=> string(1) "1" } [1]=> array(3) { [0]=> string(3) "106" [1]=> string(11) "08 14, 2008" [2]=> string(1) "2" } [2]=> array(3) { [0]=> string(3) "108" [1]=> string(11) "08 14, 2008" [2]=> string(1) "3" } } array(1) { [0]=> array(3) { [0]=> string(3) "107" [1]=> string(11) "08 15, 2008" [2]=> string(1) "1" } } It then has 6 undefined offsets and then more arrays and errors... The values that var_dump are displaying are the ones I expected. Does this help? -
Hi, I have a script that compares integers and ranks them from lowest to highest, and then submits those rankings to a mysql table. If two or more integers are the same, I have it so they're ranked the same and the next integer is ranked where it would appear if there was no tie, example... $a = 1 $b = 1 $c = 2 $a and $b would be ranked 1st because they're tied for the lowest value while $c would be ranked third, not second. Anyways, I created a relatively simple function to do this and in testing, it's outputting the values I expected it to. The only thing is that it's giving me undefined offset errors, but I don' see why. Here's the function... <?php /* FUNCTION TO ENTER RANKINGS INTO DATABASE */ function post_rankings() { $result = mysql_query("SELECT * FROM auf_records") or die(mysql_error()); $u = 17; $x = 18; $y = 19; while ($u < mysql_num_fields($result)) { /* RETRIEVE DATA FROM TABLE "AUF_RECORDS" */ $level = mysql_field_name($result, $u); $date = mysql_field_name($result, $x); $recrank = mysql_field_name($result, $y); $result2 = mysql_query("SELECT $level, $date, id FROM auf_records") or die(mysql_error()); while ($row = mysql_fetch_row($result2)) { if ($row[0] > 0) { $records[] = $row; } } if (isset($records)) { sort($records); $i = 0; $numrec = count($records[0]); while ($i < $numrec) { $uid = $records[$i][2]; // FIRST UNDEFINED OFFSET if ($i == 0) { $rank = $i + 1; mysql_query("UPDATE auf_records SET $recrank = '$rank' WHERE id = '$uid' ") or die(mysql_error()); } else { $a = $i - 1; if ($records[$i][0] == $records[$a][0]) { // SECONDS UNDEFINED OFFSET $prevuid = $records[$a][2]; // THIRD UNDEFINED OFFSET $result3 = mysql_query("SELECT $recrank FROM auf_records WHERE id = '$prevuid' ") or die(mysql_error()); $row2 = mysql_fetch_row($result3); $rank = $row2[0]; mysql_query("UPDATE auf_records SET $recrank = '$rank' WHERE id = '$uid' ") or die(mysql_error()); } else { $rank = $i + 1; mysql_query("UPDATE auf_records SET $recrank = '$rank' WHERE id = '$uid' ") or die(mysql_error()); } } $i++; } } $u = $u + 3; $x = $x + 3; $y = $y + 3; unset($records); } } ?> I'm getting Undefined offset: 1 for all three undefined offsets but only Undefined offset: 2 for the first two undefined offsets. If $records isn't set if (isset($records)) should take care of that, so why am I getting this error. I'm sure it's something simple, but I can't find it by myself. Any help would be greatly appreciated!