Converting code to a function

From: Date: Wed, 28 Feb 2001 02:51:50 +0000
Subject: Converting code to a function
Groups: php.general 
Request: Send a blank email to php-general+get-41946@lists.php.net to get a copy of this message
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

« previous php.general (#41946) next »