A quick rewrite of your code:

<?php

  $conn = mysql_connect($host, $user, $pass);

  if (!$conn) {
      echo 'Could not connect: '. mysql_error();
      exit;
  }

  mysql_select_db($dbname);

  $sql    = "SELECT * FROM members";
  $result = mysql_query($sql);

  if (!$result) {
      echo 'Could not run Query: '. mysql_error();
      exit;
  }

  while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) {

      extract($row);

      print "$ircname, $email, $realname, $asl, $info <br>";
  }

?>

Your question was how to print the query, in this case you'd just print
$sql.  That was the point of the above but I got a bit carried away :) Oh,
mysql_error() can be very useful for debugging.  Regarding the type
resource, have a look here:

  http://www.php.net/manual/en/language.types.resource.php

Regards,
Philip Olson


On Fri, 4 Jan 2002, louie miranda wrote:

> Hi, is it possible to print the sql query? i mean
> i want to print the output of the command "SELECT * FROM members;"
> and output it into html, i tried
> 
> print $result; -- it gives me different output..
> 
> > Resource id #2
> 
> 
> ty,
> louie...
> 
> # PHP SCRIPT ###############################################
> 
> <html>
> <body>
> 
> <?php
> 
> $db = mysql_connect("my_db_host", "my_db_user", "my_db_pass")
>         or die("Could not connect");
> 
> mysql_select_db("cavite",$db);
> 
> $result = mysql_query("SELECT * FROM members",$db) or
> die("Error:".mysql_error()
> );
> 
> printf("ircname: %s<br>", mysql_result($result,0,"ircname"));
> printf("email: %s<br>", mysql_result($result,0,"email"));
> printf("realname: %s<br>", mysql_result($result,0,"realname"));
> printf("asl: %s<br>", mysql_result($result,0,"asl"));
> printf("info: %s<br>", mysql_result($result,0,"info"));
> 
> print "<br><br>";
> 
> ?>
> 
> </body>
> 
> </html>
> 
> # PHP SCRIPT ###############################################
> 
> 
> -- 
> 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]
> 


-- 
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