avo Posted June 16, 2006 Share Posted June 16, 2006 Hi allhow do i pull a variable from a functioni wish to see if it is containing any datamy function is[code]function search_like(){ include ('includes/dbconfig.php'); mysql_connect ($dbhost, $dbuser, $dbpass); mysql_select_db ($dbname) or die ( mysql_error ()); $query = "SELECT part_number FROM parts_db WHERE part_number RLIKE '".$_POST['txt_search']."'ORDER BY part_number ASC"; $result = mysql_query ($query) or die ( mysql_error () ); while($row=mysql_fetch_array($result)) { echo "<option value='{$row["part_number"]}'>{$row["part_number"]}</option>"; $prt_num_found =$row['part_number']; } }[/code]i wish to get $prt_num_found from the function to check itthanks in advanve Link to comment https://forums.phpfreaks.com/topic/12163-get-variable-from-function/ Share on other sites More sharing options...
wildteen88 Posted June 16, 2006 Share Posted June 16, 2006 return it:[code]$prt_num_found =$row['part_number']; } return $prt_num_found;}[/code]The you can do this:[code]if(search_like() == "somthing"){ //do something if true;}else{ //do something else if not true.}[/code] Link to comment https://forums.phpfreaks.com/topic/12163-get-variable-from-function/#findComment-46312 Share on other sites More sharing options...
kenrbnsn Posted June 16, 2006 Share Posted June 16, 2006 Use the [a href=\"http://us3.php.net/return\" target=\"_blank\"]return()[/a] statement:[code]<?phpfunction search_like(){ include ('includes/dbconfig.php'); mysql_connect ($dbhost, $dbuser, $dbpass); mysql_select_db ($dbname) or die ( mysql_error ()); $query = "SELECT part_number FROM parts_db WHERE part_number RLIKE '".$_POST['txt_search']."'ORDER BY part_number ASC"; $result = mysql_query ($query) or die ( mysql_error () ); while($row=mysql_fetch_array($result)) { echo "<option value='{$row["part_number"]}'>{$row["part_number"]}</option>"; $prt_num_found =$row['part_number']; } return($prt_num_found);}$pnf = search_like();echo $pnf;?>[/code]Ken Link to comment https://forums.phpfreaks.com/topic/12163-get-variable-from-function/#findComment-46313 Share on other sites More sharing options...
avo Posted June 16, 2006 Author Share Posted June 16, 2006 [!--quoteo(post=384611:date=Jun 16 2006, 04:49 PM:name=kenrbnsn)--][div class=\'quotetop\']QUOTE(kenrbnsn @ Jun 16 2006, 04:49 PM) [snapback]384611[/snapback][/div][div class=\'quotemain\'][!--quotec--]Use the [a href=\"http://us3.php.net/return\" target=\"_blank\"]return()[/a] statement:[code]<?phpfunction search_like(){ include ('includes/dbconfig.php'); mysql_connect ($dbhost, $dbuser, $dbpass); mysql_select_db ($dbname) or die ( mysql_error ()); $query = "SELECT part_number FROM parts_db WHERE part_number RLIKE '".$_POST['txt_search']."'ORDER BY part_number ASC"; $result = mysql_query ($query) or die ( mysql_error () ); while($row=mysql_fetch_array($result)) { echo "<option value='{$row["part_number"]}'>{$row["part_number"]}</option>"; $prt_num_found =$row['part_number']; } return($prt_num_found);}$pnf = search_like();echo $pnf;?>[/code]Ken[/quote]Thank you is return actually returning the value to another scope thanks in advance Link to comment https://forums.phpfreaks.com/topic/12163-get-variable-from-function/#findComment-46318 Share on other sites More sharing options...
.josh Posted June 16, 2006 Share Posted June 16, 2006 yes, it is returning the value to whatever scope it was called from. Link to comment https://forums.phpfreaks.com/topic/12163-get-variable-from-function/#findComment-46341 Share on other sites More sharing options...
avo Posted June 16, 2006 Author Share Posted June 16, 2006 [!--quoteo(post=384616:date=Jun 16 2006, 04:52 PM:name=avo)--][div class=\'quotetop\']QUOTE(avo @ Jun 16 2006, 04:52 PM) [snapback]384616[/snapback][/div][div class=\'quotemain\'][!--quotec--]Thank you is return actually returning the value to another scope thanks in advance[/quote]Thank you Link to comment https://forums.phpfreaks.com/topic/12163-get-variable-from-function/#findComment-46357 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.