Jump to content

Get variable from function


avo

Recommended Posts

Hi all

how do i pull a variable from a function

i wish to see if it is containing any data

my 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 it

thanks in advanve
Link to comment
Share on other sites

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
Share on other sites

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

Ken
Link to comment
Share on other sites

[!--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]<?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;
?>[/code]

Ken
[/quote]

Thank you is return actually returning the value to another scope

thanks in advance
Link to comment
Share on other sites

[!--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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.