multiple functions

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

multiple functions

Post 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?
Image Image
jason
Site Admin
Posts: 1767
Joined: Thu Apr 18, 2002 3:14 pm
Location: Montreal, CA
Contact:

Post 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.
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Post 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?
Image Image
jason
Site Admin
Posts: 1767
Joined: Thu Apr 18, 2002 3:14 pm
Location: Montreal, CA
Contact:

Post by jason »

I am not sure what you mean by multiple queries coming from one table? Explain?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Post 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? :)
Image Image
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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 ;) )
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Post by phice »

In the first code section, it says "somethingUseful($row)". What Im asking is the made code, for the function: somethingUseful();
Image Image
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Post by phice »

bump
Image Image
Post Reply