On 2/1/08, Jason Pruim <[EMAIL PROTECTED]> wrote:

>
>  On Feb 1, 2008, at 2:20 PM, David Giragosian wrote:
>
>  On 2/1/08, Jason Pruim <[EMAIL PROTECTED]> wrote:
> >
> > [snip long explanation of problem]
>
>
>  function search($searchvar, $table, $num_rows, $FName, $LName, $Add1,
> $Add2) {
>        $qstring = "SELECT * FROM ".$table." WHERE FName like
> '%$searchvar%'
>                         or LName like '%$searchvar%' or Add1 like
> '%$searchvar%' or Add2 like
>                         '%$searchvar%' or City like '%$searchvar%' or
> State like '%$searchvar%'
>                         or Zip like '%$searchvar%' or XCode like
> '%$searchvar%'";
>
>         $qrow[]= mysql_query($qstring) or die(mysql_error());
>         $qresult = $qrow[0];
>         $num_rows = mysql_num_rows($qresult);
>         while($qrow = mysql_fetch_assoc($qresult)) {
>                $FName = $qrow['FName'];
>                $LName = $qrow['LName'];
>                $Add1 = $qrow['Add1'];
>                $Add2 = $qrow['Add2'];
>
>         }
>
> // what do you want to return...?
>                 return;
>
> }
>
> ?>
>
> $returnedSomething = search($searchvar, $table, $num_rows, $FName, $LName,
> $Add1, $Add2);
>
> Jason,
>
> 1. You're missing a closing brace at the end of the while loop.
> 2. You're not returning anything from the function.
>
> The input parameters are pretty clear but what were you expecting to
> accomplish within the function?
>
> All the data returned from the query only have scope within the function,
> so unless you return something, like an array or a string, use references,
> or write to a global variable, you're not doing anything with the data from
> the db.
>
> David
>
>
> Hi David,
>
>
> Thanks for looking. I'm just starting to learn about functions, and
> obviously making a few mistakes along the road...
>
>
> Basically what I am trying to do is allow my customer the ability to
> search the database, display it on the website, and then export it to excel
> if they wish...
>
>
> the missing closing brace was a bad copy/paste job.
>
>
> I have tried to add $searchReturn = search($searchvar, $table, $num_rows,
> $FName, $LName, $Add1, $Add2);
> and then do a vardump on it and it's not returning any thing.
>
>
> I've also changed the return line to return $searchReturn['FName'];
> but it's still not showing through...
>
>
> I think functions will be the death of me... at least until I understand
> how to use them :)
>
>
> I think I'm off to google some more and see if I can get any more info...
>
>
> Thanks again for your help!
>


Jason,

Untested, but try this...

function search($searchvar, $table, $num_rows, $FName, $LName, $Add1, $Add2)
{
       $qstring = "SELECT * FROM ".$table." WHERE FName like '%$searchvar%'
                        or LName like '%$searchvar%' or Add1 like
'%$searchvar%' or Add2 like
                        '%$searchvar%' or City like '%$searchvar%' or State
like '%$searchvar%'
                        or Zip like '%$searchvar%' or XCode like
'%$searchvar%'";

        $qrow = mysql_query($qstring) or die(mysql_error());
        $qresult = $qrow;
        $num_rows = mysql_num_rows($qresult);

       $outputStr = "<table>";

        while($qrow = mysql_fetch_assoc($qresult)) {
               $FName = $qrow['FName'];
               $LName = $qrow['LName'];
               $Add1 = $qrow['Add1'];
               $Add2 = $qrow['Add2'];

               $outputStr .=
"<tr><td>$FName</td><td>$LName</td><td>$ADD1</td><td>$ADD2</td></tr>\n";

        }

        $outputStr .= "</table>";


                return $outputStr;

}

$searchReturn = search($searchvar, $table, $num_rows, $FName, $LName, $Add1,
$Add2);

echo $searchReturn;

David

Reply via email to