order of operations
Posted: Sun Apr 30, 2006 12:46 am
feyd | Please use
When calling this function in a situation where it will print to screen, it works great.
However, if you would like to use it in one of the following examples, it doesn't return the same information.
.. or ...
Being rather new to PHP, any education on this matter would be most enlightening.
Thanks.
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Is there a place were we can view the 'order of operations' for different php commands?
Here's an example of a problem that I have noticed recently.
Let's say you have a function that pulls a store ID from a database, like below.
NOTE: Please overlook the ineffeciency of the code and accept the concept I'm presenting.Code: Select all
// Gets Store ID
///////////////////////////////////////////////////////////////////////////
function get_store_id($my_store_name) {
$query = "SELECT * FROM mystores WHERE my_store_name = '".$my_store_name."'";
$result = mysql_query($query);
if (mysql_num_rows($result) > 0 ) {
while ($record = mysql_fetch_assoc($result)) {
while (list($fieldname,$fieldvalue) = each ($record)) {
$$fieldname = $fieldvalue;
}
}
echo $my_store_id;
}
}Code: Select all
echo "My Store ID: ";
get_store_id($my_store_name);
echo "<br>";Code: Select all
$query = "INSERT INTO my_main_category (my_main_cat,my_store_id) VALUES ('".$my_main_category."','".get_store_id($my_store_name)."')";Code: Select all
$my_store_id = get_store_id($my_store_name);Thanks.
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]