hi

I'm trying to write a simple MySQL query in a php function so that I can
just call it and pass arguments, but I'm missing something :o(

there are 2 files, index.php and common.php, commom.php contains all the
functions, and is included at the beginning of index.php

the first function called in index.php is db_connect, which calls the
function to create a connect to the MySQL database, this would seem to be
working correctly

the second part (here's where I crap out) is the actual query. the function
is written as follows

function query($strField, $strTable) {
 $sql = "select $strField from strTable";
 $result = mysql_query($sql);
 return $result;
}

I call it with query(my_field, my_table) for example, and I would hope it
would return $result back to the calling page for further us, but the rest
of index.php

   print "<SELECT name=item>";
   while ($line = mysql_fetch_row($result))
   {
      foreach ($line as $value)
       {
         print "<OPTION value='$value'";
      }
print ">$value</OPTION>";
   }
    mysql_close($my_conn);
print "</SELECT>";

simply renders an empty list box :o( if I take the code out of a function
and place it in index.php like this

 $sql = "select my_field from my_table";
 $result = mysql_query($sql);
   print "<SELECT name=item>";
   while ($line = mysql_fetch_row($result))
   {
      foreach ($line as $value)
       {
         print "<OPTION value='$value'";
      }
print ">$value</OPTION>";
   }
    mysql_close($my_conn);
print "</SELECT>";

then it works fine ?? what am I missing here ?

thanks

_scott



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to