Re: [PHP] Non-Object errors

2009-04-28 Thread Jan G.B.
2009/4/28 Miller, Terion tmil...@springfi.gannett.com:
 Can someone help with how to make this work, trying to get the number of
 rows but am getting the trying to get property of non-object

 Code-

 $query = select blah, blah, blah from table where .$type. like
 '%.$name.%';

 $result = mysql_query($query);

 $num_results = $result-num_rows; ---this is the line with
 error

Hi Terion,

you're mixing normal mysql_* with mysqli. Mysqli is object oriented
and the mormalö mysql_ functions aren't - thei're procedural.

So you can do it either like

$result = mysql_query(SELECT 1);
$num = mysql_num_rows($result);

Or in OOP

$res = $mysqlObj-query(SELECT 1); // $mysqlObj should be
initialized first ;) hint: new mysqli()
$num = $res-num_rows();



Check ot this URL: http://php.net/mysqli



byebye

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



Re: [PHP] Non-Object errors

2009-04-28 Thread Miller, Terion



On 4/28/09 11:23 AM, Jan G.B. ro0ot.w...@googlemail.com wrote:

2009/4/28 Miller, Terion tmil...@springfi.gannett.com:
 Can someone help with how to make this work, trying to get the number of
 rows but am getting the trying to get property of non-object

 Code-

 $query = select blah, blah, blah from table where .$type. like
 '%.$name.%';

 $result = mysql_query($query);

 $num_results = $result-num_rows; ---this is the line with
 error

Hi Terion,

you're mixing normal mysql_* with mysqli. Mysqli is object oriented
and the mormalö mysql_ functions aren't - thei're procedural.

So you can do it either like

$result = mysql_query(SELECT 1);
$num = mysql_num_rows($result);

Or in OOP

$res = $mysqlObj-query(SELECT 1); // $mysqlObj should be
initialized first ;) hint: new mysqli()
$num = $res-num_rows();



Check ot this URL: http://php.net/mysqli



byebye


Hmm, well I did some looking at other codes etc and some tweaking but still get 
two problems:
Changed my code to try and use an array because that has worked before when I 
have run into the object error, but I still get this error:

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result 
resource

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result 
resource

Here is my code now:
   $query = select name, age, warrant, bond, wnumber, crime FROM warrants 
where .$warranttype. = .$warranttype. OR .$searchname. = .$searchname. 
;$result = mysql_query($query);$row = mysql_fetch_assoc($result);
$num_results = mysql_num_rows ($result);
Should this post of gone on the Db list maybe?

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



Re: [PHP] Non-Object errors

2009-04-28 Thread Lex Braun
Terion,

On Tue, Apr 28, 2009 at 1:14 PM, Miller, Terion 
tmil...@springfi.gannett.com wrote:

 Here is my code now:
   $query = select name, age, warrant, bond, wnumber, crime FROM warrants
 where .$warranttype. = .$warranttype. OR .$searchname. =
 .$searchname. ;$result = mysql_query($query);$row =
 mysql_fetch_assoc($result);$num_results = mysql_num_rows ($result);
 Should this post of gone on the Db list maybe?


One thing I noticed about your code above has to do with your WHERE clause.
Say,
$warranttype = 'warrant'
$searchname = 'Terion'

Your $query will become:
SELECT name, age, warrant, bond, wnumber, crime
FROM warrants
WHERE warrant = warrant OR Terion = Terion

The first time you use $warranttype and $searchname should be the column
names rather than the value you would like that column to be equal to.

-- Lex


Re: [PHP] Non-Object errors

2009-04-28 Thread Miller, Terion



On 4/28/09 12:27 PM, Lex Braun lex.br...@gmail.com wrote:

Terion,

On Tue, Apr 28, 2009 at 1:14 PM, Miller, Terion tmil...@springfi.gannett.com 
wrote:
Here is my code now:
   $query = select name, age, warrant, bond, wnumber, crime FROM warrants 
where .$warranttype. = .$warranttype. OR .$searchname. = .$searchname. 
;$result = mysql_query($query);$row = mysql_fetch_assoc($result);
$num_results = mysql_num_rows ($result);
Should this post of gone on the Db list maybe?

One thing I noticed about your code above has to do with your WHERE clause. Say,
$warranttype = 'warrant'
$searchname = 'Terion'

Your $query will become:
SELECT name, age, warrant, bond, wnumber, crime
FROM warrants
WHERE warrant = warrant OR Terion = Terion

The first time you use $warranttype and $searchname should be the column names 
rather than the value you would like that column to be equal to.

-- Lex

OH Ah ha bet that's it!! I hope!!



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



Re: [PHP] Non-Object errors (RESOLVED)

2009-04-28 Thread Miller, Terion
Thanks folks!!


On 4/28/09 12:30 PM, Miller, Terion tmil...@springfi.gannett.com wrote:




On 4/28/09 12:27 PM, Lex Braun lex.br...@gmail.com wrote:

Terion,

On Tue, Apr 28, 2009 at 1:14 PM, Miller, Terion tmil...@springfi.gannett.com 
wrote:
Here is my code now:
   $query = select name, age, warrant, bond, wnumber, crime FROM warrants 
where .$warranttype. = .$warranttype. OR .$searchname. = .$searchname. 
;$result = mysql_query($query);$row = mysql_fetch_assoc($result);
$num_results = mysql_num_rows ($result);
Should this post of gone on the Db list maybe?

One thing I noticed about your code above has to do with your WHERE clause. Say,
$warranttype = 'warrant'
$searchname = 'Terion'

Your $query will become:
SELECT name, age, warrant, bond, wnumber, crime
FROM warrants
WHERE warrant = warrant OR Terion = Terion

The first time you use $warranttype and $searchname should be the column names 
rather than the value you would like that column to be equal to.

-- Lex

OH Ah ha bet that's it!! I hope!!





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