Page 1 of 1

multiple functions

Posted: Sat May 18, 2002 7:47 pm
by phice
I've got users that store their stock names in a database. Now, I would like to set up a function that would use all of their stock names, to look up the quote, and put it out on a line. Is there a way of doing this as a function? like, stockLookUp($mysqlResults);, and it would do the function, for the query from the database. I've already got the quote look up script customized the way I want it. Anyone got any ideas?

Posted: Sat May 18, 2002 8:08 pm
by jason
Yes, it can be done...but as far as telling you how to do it, I have no idea, considering I dont' know the specs on anything.

Posted: Sat May 18, 2002 8:54 pm
by phice
Alright..

This link is the source of my file. Note: This is only a form-based lookup. This is the working version of the above script.

Now... Lets say that there are multiple querys, coming from one database table. and $query = $row['stockNames'];
I would like to set up a function, that includes that script above, that would use the string included with that function, like: stockScript($query);

Is there a way of doing this? If so -- Could anyone point me in the right direction?

Posted: Sat May 18, 2002 11:56 pm
by jason
I am not sure what you mean by multiple queries coming from one table? Explain?

Posted: Sun May 19, 2002 7:00 am
by volka
didn't get it neither.
maybe:
The user enters one stock name and the script finds all the names used by the one using the entered name? (get N for 1 and free refill ;) )
the working version of your script may be fancy but without a valid name it's just an input box 8O

Posted: Sun May 19, 2002 5:06 pm
by phice
Lets say theres one user. That user adds one stock to the MySQL database, entitled APL. Then, adds another entitled DELL. Then, adds yet another one, entitled AOL. Now... After I call all of the users stored stock names from the Table, I want that script to run for each of those names. Better? :)

Posted: Sun May 19, 2002 6:27 pm
by volka
jepp, better and (hopefully) simple enough for me to answer ;)
i.e.

Code: Select all

$result=mysql_query(....) or die('query failed');
while ($row = mysql_fetch_row($result)
   somethingUseful($row);
mysql_free_result($result);
or if you've already put the data into an array you can perform a forrach-loop

Code: Select all

$allstocks=getAllStocks(..);
foreach($allstocks as $stock)  whatEver($stock);
or misuse the array_map function

Code: Select all

$allstock=getAllStock(..);
$allstocks = array_map("whatEver", $allstocks);
see also:
mysql_query
mysql_fetch_row
mysql_free_result
die
foreach
array_map

(damn, I love this site and even more linking to it ;) )

Posted: Sun May 19, 2002 10:55 pm
by phice
In the first code section, it says "somethingUseful($row)". What Im asking is the made code, for the function: somethingUseful();

Posted: Mon May 20, 2002 11:12 pm
by phice
bump