Hi everyone :-)
 
I need help, how can I convert the following code into a function so that I can just place it in a global include file and call it using viewdoc($docid); whenever necessary?
 
-------START-------
if ($docid == "") {
          echo "Fatal Error - DocID not supplied";
          exit;
  }
 
  $dbh = mysql_connect("$HOSTNAME","$DB_USER","$DB_PASS");
  mysql_select_db("$DATABASE");
 
  $sth = mysql_query("SELECT docdata FROM documents WHERE docid like
                  '$docid'");
 
  $row = mysql_fetch_array($sth);
 
  if ($row[0] != "") {
          echo "DocID: $docid\n\n";
        echo (wraptext($row[0],72));
 
  } else {
          echo "Fatal Error - Can't fetch docid";
  }
-------END-------
 
I tried to do this:
function viewdoc($docid) {
...PASTE FROM ABOVE...
}
 
But then I get:
 
Warning: Supplied argument is not a valid MySQL result resource in /home/www/websites/gdd/inc/funcs.inc on line 76
Fatal Error - Can't fetch docid  
 
when I call it from a web page using:
 
viewdoc($docid);
 
 
What have I done wrong?
 
 
 
TIA!
Clayton Dukes
-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to