[PHP-DB] Re: recommending a PHP book?

2005-03-15 Thread Philip Olson



Do.  Not.  Cross.  Post.

Use ONE mailing list at a time.



Please have all further replies to this unfortunate thread
go to php-general and only php-general.

Regards,
Philip

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



[PHP-DB] Re: [PHP] New to PHP Need Help

2002-04-04 Thread Philip Olson

Firstly, cross-posting like this is a huge 
no-no, please don't do that again.

 When the script runs it displays Array.  

Printing arrays directly will do that.  Logically 
speaking, how do you expect PHP to know what 
value to get here?  You are SELECTing many.

 I am running WIN2K and IIS 5

I'm sorry ;)

 echo a href=location.php?location=2Camp Street Cafe/a;

 Here is the script that is called.
 
 ?php
 
 $db = mysql_connect(localhost, , )
  or die (Could not connect to Localhost);
 mysql_select_db (ETM, $db)
  or die (Could not connect to the Database);

If you start running into problems, please 
consider mysql_error()

 $table = locations;
 $location = ($_REQUEST[location]);

No need for the () here.

 $query = Select * from $table where Location_ID = $location;

Notice how you're selecting many columns here, not just one.

 $result= mysql_query($query);
 $Location_Info = mysql_fetch_row($result);

Looking in the manual, the entry for mysql_fetch_row 
tells us:

mysql_fetch_row -- Get a result row as an enumerated array
  array mysql_fetch_row ( resource result)

So it returns an array.  If you prefer the _row format 
then continue to use it, for example using list():

  list($id, $name, $email) = mysql_fetch_row($result);

Or just:

  $row = mysql_fetch_row($result);
  print $row[0]; // This is an enumerated array (numerical)
  print $row[1];

Or use a function like mysql_fetch_assoc instead:

  $row = mysql_fetch_assoc($result);
  print $row['id']; // with id being a column name
// selected via the query
  print $row['name'];

And lastly, if you're not going to use all the data, 
don't SELECT * of it.

Good start, keep it going :)

Regards,
Philip Olson


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




[PHP-DB] Re: [PHP] printing php variable into html print $result; ?

2002-01-03 Thread Philip Olson

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: %sbr, mysql_result($result,0,ircname));
 printf(email: %sbr, mysql_result($result,0,email));
 printf(realname: %sbr, mysql_result($result,0,realname));
 printf(asl: %sbr, mysql_result($result,0,asl));
 printf(info: %sbr, mysql_result($result,0,info));
 
 print brbr;
 
 ?
 
 /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 Database 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-DB] Re: mysql_fetch_array problem

2001-07-09 Thread Philip Olson

What's your code look like, something like this?

$result = mysql_query(SELECT name FROM tablename);
while ($row = mysql_fetch_array($result)) {

print Name : . $row['name'] . br\n;
}

The above is the most standard way at least.  Share your appropriate 
snippet of code, could be a few reasons.

Regards,
Philip

Briansander wrote:

 Greetings,
 
 I'm experiencing the strangest problem and I was wondering if anyone
 else has had the same problem.
 
 I have a fairly simple script setup that queries a mySQL database and
 displays the records in a HTML table. Everything works fine except it
 keeps omitting the first record. Running the query directly on the
 database returns 3 records but only 2 are displayed in the table.
 
 I just upgraded to PHP 4.0.6 and I'm still having the problem. I've also
 tried using mysql_fetch_array and mysql_fetch_object, both produce the
 same results. The first record is left out every time.
 
 Any idea as to what the problem might be?
 
 
 Thanks.



-- 
PHP Database 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]