Jump to content

Archived

This topic is now archived and is closed to further replies.

avo

Get variable from function

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

Share this post


Link to post
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]

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

×

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.