Hi.

I have a db class that accesses and executes querys as well as returns
the result (if you so choose to have it returned).

One method within this class is called query() (how genius!). It's
defined like so:

<?php
function query($sql, $current_line)
{
  $this->Result = mysql_query($sql) or die($this->stop($current_line));

  if(!$this->Result)
  {
    echo mysql_error();
  }

  $this->result_fields = mysql_num_fields($this->Result); // line 127

  $this->result_rows = mysql_num_rows($this->Result); // line 130
}
?>

How is it possible that I'm getting the following errors?

Warning: mysql_num_fields(): supplied argument is not a valid MySQL
result resource in /home/cparker/www/schedulevark/lib/classes/db.php on
line 127

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result
resource in /home/cparker/www/schedulevark/lib/classes/db.php on line
130
success!

I can't figure it out! It sure looks like a valid MySQL result to me! Oh
and I should mention that the query's I'm running are perfect and I can
run these two functions without error in another method (the one that
returns the results). That method is defined like so:

<?php
function get_query_results()
{
  $Result_Arr = array();

////// THESE LINES WORK FINE!!!! BUT I DON'T WANT THEM HERE!
//  // store the number of fields
//  $this->result_fields = mysql_num_fields($this->Result);
//
//  // store the number of rows
//  $this->result_rows = mysql_num_rows($this->Result);

  if($this->result_rows > 0)
  {
    while($line = mysql_fetch_array($this->Result, MYSQL_BOTH))
    {
      $Result_Arr[] = $line;
    }
  }

  mysql_free_result($this->Result);
  return $Result_Arr;
}
?>

The reason I don't want the two mysql counting functions in the second
method is because it forces me to execute the second method within my
page before I can access those values. Sometimes I need to access those
values but don't need to return a result so I'd like to be able to leave
that second step out.

Here is the original way they are used in my page (the way I don't
want):

<?php

$sql = "
        SELECT field1
                , field2
                , field3
        FROM thetable";

$object->query($sql, __LINE__);

$the_result = $object->get_query_results();

$the_result_Rows   = $object->Result_rows;
$the_result_Fields = $object->Result_fields;
?>

Here is the way that I WANT it to work:

<?php

$sql = "
        SELECT field1
                , field2
                , field3
        FROM thetable";

$object->query($sql, __LINE__);

$the_result_Rows   = $object->Result_rows;
$the_result_Fields = $object->Result_fields;
?>



Anyone have any ideas?

If I have not been verbose enough in this email let me know and I will
try to clarify.


Thanks,
Chris.

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

Reply via email to