Jump to content


Photo

Get variable from function


  • Please log in to reply
5 replies to this topic

#1 avo

avo
  • Members
  • PipPipPip
  • Advanced Member
  • 148 posts
  • Locationstaffordshire uk

Posted 16 June 2006 - 03:35 PM

Hi all

how do i pull a variable from a function

i wish to see if it is containing any data

my function is

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'];
     }      
}
i wish to get $prt_num_found from the function to check it

thanks in advanve
Im loving it ........

#2 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 16 June 2006 - 03:48 PM

return it:
$prt_num_found =$row['part_number'];
     }
    return $prt_num_found;
}
The you can do this:
if(search_like() == "somthing")
{
    //do something if true;
}
else
{
    //do something else if not true.
}


#3 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 16 June 2006 - 03:49 PM

Use the [a href=\"http://us3.php.net/return\" target=\"_blank\"]return()[/a] statement:
<?php
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'];
     }      
     return($prt_num_found);
}

$pnf = search_like();
echo $pnf;
?>

Ken

#4 avo

avo
  • Members
  • PipPipPip
  • Advanced Member
  • 148 posts
  • Locationstaffordshire uk

Posted 16 June 2006 - 03:52 PM

[!--quoteo(post=384611:date=Jun 16 2006, 04:49 PM:name=kenrbnsn)--][div class=\'quotetop\']QUOTE(kenrbnsn @ Jun 16 2006, 04:49 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Use the [a href=\"http://us3.php.net/return\" target=\"_blank\"]return()[/a] statement:
<?php
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'];
     }      
     return($prt_num_found);
}

$pnf = search_like();
echo $pnf;
?>

Ken
[/quote]

Thank you is return actually returning the value to another scope

thanks in advance

Im loving it ........

#5 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 16 June 2006 - 04:32 PM

yes, it is returning the value to whatever scope it was called from.
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#6 avo

avo
  • Members
  • PipPipPip
  • Advanced Member
  • 148 posts
  • Locationstaffordshire uk

Posted 16 June 2006 - 05:07 PM

[!--quoteo(post=384616:date=Jun 16 2006, 04:52 PM:name=avo)--][div class=\'quotetop\']QUOTE(avo @ Jun 16 2006, 04:52 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Thank you is return actually returning the value to another scope

thanks in advance
[/quote]
Thank you
Im loving it ........




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users