
|
View Full Version : PHP Passing Variables
devanium 03-12-2005, 10:20 PM Hello,
I have a question. How would I go about passing a variable by appending it to a URL (ie. page.php?action=variable), through a form on an HTML page? Finally, I need the page to pop-up too.
So, the user puts the variable's info into a text form field, presses the button, then a new smaller window pops up with the info. Do I need to use a session for this? Or is there an easier way?
Any help would be greatly appreciated.
Thanks!
devanium 03-12-2005, 10:47 PM I tried this:
<input type="submit" value="Get Quote" onClick="window.open('quote.php?<?php echo $tickersymbol;?>')">
And nothing in the form. This doesn't echo it, and if I include it in the form action, then it redirects the user from the page, not just a popup window... any ideas?
WO-Jacob 03-13-2005, 12:12 AM Originally posted by devanium
Hello,
I have a question. How would I go about passing a variable by appending it to a URL (ie. page.php?action=variable), through a form on an HTML page? Finally, I need the page to pop-up too.
So, the user puts the variable's info into a text form field, presses the button, then a new smaller window pops up with the info. Do I need to use a session for this? Or is there an easier way?
Any help would be greatly appreciated.
Thanks!
Try...
<form name="test">
<input type="text" name="symbol" />
<input type="button" onclick="window.open('http://www.yoursite.com/page.php?symbol='+document.test.symbol); " />
</form>
hope this turns out in the page :)
devanium 03-13-2005, 12:26 AM Works great, thanks!
One other question...
I'm trying to parse a CSV document. I can load the CSV document into an array using fread (to $read); but my question is, how do I read more than one line? For the first row, I use $read[column1], $read[column2], etc., but how would I go about checking a different row?
Again, thanks for any help!
WO-Jacob 03-13-2005, 12:39 AM $file = file('file.csv');
foreach ($file as $line) {
$read = split(',', $line);
blah
}
devanium 03-13-2005, 12:43 AM Ok, how would I pull data from a cell then? $read[row,column]? Sorry, I'm new to parsing CSV files in PHP...
Thank again!
artofmobile 03-13-2005, 01:07 AM I sure there are 1001 ways, but see this one works for you:
<?
$my_array = file("call.csv");
foreach($my_array as $line){
$row = explode(",",$line);
foreach($row as $col) {
echo "$col ";
}
echo "\n";
}
?>
devanium 03-13-2005, 02:00 AM Thanks for replying - I tried that, but I can't seem to get it to work right (probably a mistake I am making)...
Basically, what I'm trying to do is perform calculations based on certain fields within the CSV. So, for example, add the data in row5/column2 to row6/column2.
When I do the calculation on one row, I can just use $read[2] and add it to $read[3], for example. Is there a way I can pin-point locations like this using the same basic command - for example, $read[column,row]? I think that's what artofmobile was getting at, but I can't seem to get it to work - can someone give me an example that will add two fields from two seperate rows?
Again, thanks for the help!
artofmobile 03-13-2005, 02:53 AM I think this is what you want:
<?
$my_array = file("call.csv");
$values=array();
foreach($my_array as $line){
$row = explode(",",$line);
$one=array();
foreach($row as $col) {
echo "$col | ";
array_push($one,$col);
}
array_push($values,$one);
echo "\n";
}
$find=$values[1];
echo "$find[2]\n";
$find=$values[1][2];
echo "$find\n";
devanium 03-13-2005, 03:11 AM Thanks for the reply. I tried just putting in what you had, and replacing the CSV with the CSV I am using, and adding in my variables:
<?
$monthStart = date("M") - 1;
$dayStart = date("D");
$yearStart = date("Y");
$monthEnd = date("M");
$dayEnd = date("D");
$yearEnd = date("Y");
$my_array = file("http://ichart.finance.yahoo.com/table.csv?s=$tickersymbol&a=$monthStart&b=dayStart&c=$yearStart&d=$monthEnd&e=$dayEnd&f=$yearEnd&g=d&ignore=.csv");
$values=array();
foreach($my_array as $line){
$row = explode(",",$line);
$one=array();
foreach($row as $col) {
echo "$col | ";
array_push($one,$col);
}
array_push($values,$one);
echo "\n";
}
$find=$values[1];
echo "$find[2]\n";
$find=$values[1][2];
echo "$find\n";
?>
Here's the result of that code: http://www.chartsetups.com/beta/swing.php?tickersymbol=drl.
Can you show me an example of how I could add, for example, two fields? Let's say from these two rows,
| 11-Mar-05 | 39.27 | 39.43 | 38.51 | 38.60 | 935000 | 38.60 |
| 10-Mar-05 | 38.00 | 39.50 | 37.85 | 39.27 | 2084600 | 39.27 |
I want to add the 39.27 and 38.00 and print the result... how would I go about doing this?
Again, sorry if I'm a little slow at this - my first time working with CSV.
Thank you so much for the help so far!!
artofmobile 03-13-2005, 03:25 AM If it is always the second column, then it will be:
<?
$my_array = file("call.csv");
$final=0;
foreach($my_array as $line){
$row = explode(",",$line);
$final+=$row[1];
}
echo "$final\n";
?>
devanium 03-13-2005, 03:41 AM Ok, I think I got it now. Thanks for your help!
artofmobile 03-13-2005, 05:12 AM Originally posted by devanium
Ok, I think I got it now. Thanks for your help!
No worry,.. hope that's help,...
|