RE: [PHP-DB] Query in a function

From: Date: Tue, 26 Jun 2001 13:49:48 +0000
Subject: RE: [PHP-DB] Query in a function
Groups: php.db 
Request: Send a blank email to php-db+get-9837@lists.php.net to get a copy of this message
take out the db connection and include it seperately in your page then make $connection global in your function. or do a if (!$connection) then ($connection=blah blah blah...) Steve > -----Original Message----- > From: Shahmat Dahlan [mailto:shahmatd@sains.com.my] > Sent: 26 June 2001 07:55 > To: seriousj > Cc: php-db@lists.php.net > Subject: Re: [PHP-DB] Query in a function > > > How about declaring some of the variables as global variables. > > regards > > > seriousj wrote: > > > Hello > > I have a query that I have placed in a function that is in > a file that I > > "include" in the page to be displayed. It doesn't work. I > know that the code > > works because when I place the code in the page to be > displayed directly it > > works fine. > > > > I can't figure it out. Thanks in advance for any help. > > John > > > > Here is the function contained in lib.inc: > > function type_select() > > { > > $connection = mysql_connect($server, $user, $pass); > > echo("<select name=\"type_id\">"); > > $query1 = "SELECT * FROM type"; > > $result1 = mysql_db_query($db, $query1, $connection); > > echo(!isset($type_id)?"<option value=\"\">--Please select a > > Type--</option>":""); > > if(mysql_num_rows($result1) > 0) > > { > > while($row1 = mysql_fetch_array($result1)) > > { > > $result1_type_id = $row1["type_id"]; > > $result1_type_desc = $row1["type_description"]; > > echo("<option "); > > echo(isset($type_id)?($result1_type_id==$type_id ? > "selected " : > > ""):""); > > echo("value=\""); > > echo($result1_type_id); > > echo("\">"); > > echo( $result1_type_desc); > > echo("</option>"); > > } > > } > > else > > { > > echo("<option value=\"error\">Error</option>"); > > } > > echo("</select>"); > > } > > > > And here is the call to that function in the page that is displayed: > > include("lib.inc"); > > ?> > > <form method="post" action="disp_item_test.php"> > > <? > > //TYPE selection > > if(!isset($type_id)) > > { > > type_select(); > > } > > > > And here is the error message: > > Warning: MySQL Connection Failed: Can't connect to local > MySQL server > > through socket '/tmp/mysql.sock' (2) in > > > /web/sites/268/seriousj/www.mccartney.f2s.com/opus/tnzp/lib.in > c on line 21 > > > > -- > > PHP Database Mailing List (http://www.php.net/) > > To unsubscribe, e-mail: php-db-unsubscribe@lists.php.net > > For additional commands, e-mail: php-db-help@lists.php.net > > To contact the list administrators, e-mail: > php-list-admin@lists.php.net > > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-db-unsubscribe@lists.php.net > For additional commands, e-mail: php-db-help@lists.php.net > To contact the list administrators, e-mail: > php-list-admin@lists.php.net >

« previous php.db (#9837) next »