I would like some guidance on the usage of foreach as I try to parse through a large database and whittle down to a few select stocks. I'm currently doing this with vb, but I'm wanting to get it working in php. I think I'm just struggling with the syntax, but I'm unsure. After a week of trial and error, I've decided it's time to reach out for help.
Currently, I can connect with the db, run a simple query, and return the results to a web page. The db is made up of the past 2 weeks' stock symbols, prices, volumes. I want to go through each symbol and check against 2 conditions. If both conditions are true for that symbol, I want to put it (and the 2 weeks of data) in another db for further parsing later. So in plain english, here's what I'm trying to accomplish:
for each unique symbol,
if condition a is true on every day and
condition b is true on every day, then
write all the data for the past 2 weeks for that symbol to db_x
I'm not sure if it's the most efficient method, but I was thinking I'd loop through the db checking the conditions and meanwhile saving the data to an array, then if the conditions are true when it gets to a different symbol it runs thrrough the array and adds the data to db_x....if it gets a false anywhere along the way for a particular symbol, it clears the array and moves on to the next symbol to check it. I don't want to hard code the 2 week's (ie loop through each stock 10 times, because of holidays, some stocks do not trade every day, etc). I need to check for the symbol changing to know when it's time to make a decision on whether to add or drop the previous symbol.
I've got it loosely structured to use a while loop to cycle through the entire list:
while ($row = mysql_fetch_assoc($result)) {
Then I suppose the foreach would be used, but I'm running into complex commands that I'm needing guidance on. Is ArrayIterator current to PHP5, and if so, is this the direction I should be studying up on? Any recommendations on a good online tutorial for someone who is not well versed in programming, but can get by through dogged determination (and a little help from my friends )?
It should be noted that my array I'm iterating through (the symbols) has several associated elements (volume, closing price, high, low).
As for providing code, I really don't have anything to go by yet. I have not delved too far past "foreach ($arr as $key => $value). I'm using mysql 5 and php 5 and apache2 on an Ubuntu 9.04 machine.
Thank you,
Sorting JTable on more than just the values listed in the columns
I have a collection of objects that store (among other things) two integer values. I only want to display one of these values. The displayed value will dictate the sort order of the JTable.However, I
PHP Captcha Error help - replace the "die" command
Hi All,I am after a bit of help with a Captcha spam protection box.The site gave me instructions, and all is well, apart from if the user give the wrong Captcha information...The highlighted code is
DELETE rows based on content
I have a link in my rows$bit="http://bit.ly/abcd";$query = mysql_query("DELETE FROM *table* WHERE sentence........");//I need to delete all sentence rows which DOES NOT contain my
Keep newlines from textarea?..
I'm creating a simple encoding program, and what I want it to do is retain the newlines, as echoing a textarea for example will strip them out (I think). How do I retain the \n's or whatnot and place
CURL XML Request [From C to PHP]
Hi, I need some help converting this into something that will work with PHP.Code:
Stuck with preg_replace
Hi,I'm trying to use preg_replace to remove part of the IP address submitted using a form on my website. The full IP is entered into my SQL database, but when printing it on the website I want to
How to read CSS message data
Hi,
Character Set Setup
Whats the best character set to use if you want every character to work, and also how do you make your files, mysql stuff, and all that set for the best character type..... got a check list i can
Problem with HTTP Caching...?
Hi there, im trying to implement caching. But it doesn't always work.I post it here because there is no Client-Side HTTP topic...Code: private function setLastModified ($aTimestamp) {
hiCode: <?phpecho "<td width=\"$columnWidth%\" align=\"center\"><a href=\"" . $_SERVER['PHP_SELF'] .