Paul Williams
01-18-2012, 07:26 PM
overview:
from my javascript,
i call a function in the php block,
that function successfully retrieves a value from the database,
but when i pass that retrieved value back to the calling function....all is lost somehow.
when i test this code by itself, it works fine and gets the correct number.
<?php
mysql_select_db($database_connFtH, $connFtH);
$result = mysql_query("SELECT status_index FROM cpqc_status ORDER BY row_id DESC");
$row_result = mysql_fetch_assoc($result);
$index = $row_result['status_index'];
echo $row_result['status_index'];
echo $index;
echo "the value of index is ".$index;
?>
however, when i set this same code up as a function to be called upon globally, and to return the value of $index, it all just seems to "not work".
<?php
function runStatus() {
mysql_select_db($database_connFtH, $connFtH);
$result = mysql_query("SELECT status_index FROM cpqc_status ORDER BY row_id DESC");
$row_result = mysql_fetch_assoc($result);
$index = $row_result['status_index'];
return ($index);
} //end function runStatus()
?>
the calling function, with an alert box to check if the value of $index was passed down accurately
<script type="text/javascript">
var x = runStatus();
alert(x);
</script>
all i want to do is call a server-script function that deals with the database and gets me a value out of the database, and pass that value back to the calling function. can't figure out what is wrong. the "return($index)" should send back the value of $index. the call to that function should receive back a value and assign it to "x". and the alert(x) should spit it out with no problem. but......something is wrong and it won't work.
any ideas what is wrong?
it is my understanding that a function inside the php determants can be called upon from anywhere and that function can return a value.(?)
argh!! i think i know why Einstein's hair was always so messy!!
thanks,
Paul Williams
weather today in Kalispell, MT:
7 deg this morning, got a little snow last night, only about 6 or 8 inches, not much.
maybe more later.
from my javascript,
i call a function in the php block,
that function successfully retrieves a value from the database,
but when i pass that retrieved value back to the calling function....all is lost somehow.
when i test this code by itself, it works fine and gets the correct number.
<?php
mysql_select_db($database_connFtH, $connFtH);
$result = mysql_query("SELECT status_index FROM cpqc_status ORDER BY row_id DESC");
$row_result = mysql_fetch_assoc($result);
$index = $row_result['status_index'];
echo $row_result['status_index'];
echo $index;
echo "the value of index is ".$index;
?>
however, when i set this same code up as a function to be called upon globally, and to return the value of $index, it all just seems to "not work".
<?php
function runStatus() {
mysql_select_db($database_connFtH, $connFtH);
$result = mysql_query("SELECT status_index FROM cpqc_status ORDER BY row_id DESC");
$row_result = mysql_fetch_assoc($result);
$index = $row_result['status_index'];
return ($index);
} //end function runStatus()
?>
the calling function, with an alert box to check if the value of $index was passed down accurately
<script type="text/javascript">
var x = runStatus();
alert(x);
</script>
all i want to do is call a server-script function that deals with the database and gets me a value out of the database, and pass that value back to the calling function. can't figure out what is wrong. the "return($index)" should send back the value of $index. the call to that function should receive back a value and assign it to "x". and the alert(x) should spit it out with no problem. but......something is wrong and it won't work.
any ideas what is wrong?
it is my understanding that a function inside the php determants can be called upon from anywhere and that function can return a value.(?)
argh!! i think i know why Einstein's hair was always so messy!!
thanks,
Paul Williams
weather today in Kalispell, MT:
7 deg this morning, got a little snow last night, only about 6 or 8 inches, not much.
maybe more later.