Get a warning when I use mysqli_fetch_field

johnecollins
johnecollins used Ask the Experts™
on
I have some code in php with a sql statement

$field = mysql_fetch_field($this->cxn, "select  max(my_seqnum) from sequfile")

I get a warning

(!) Warning: mysqli_fetch_field() expects exactly 1 parameter, 2 given in C:\\...\.....\sequfile.class on line 67

max(field name) is an aggragte function so  don't understand how I get this warning, can anybody help?

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
it says mysql_fetch_field expects a single parameter. See the function here: http://php.net/manual/en/function.mysql-fetch-field.php

you should enter the query on mysql_query function and before that you should make a connection by using mysql_connect function and select database with mysql_select_db function. See the example on the link I send to you.

Hope it helps.
Most Valuable Expert 2011
Top Expert 2016
Commented:
Maybe something more like this?  Can't really tell if you've got all the moving parts there.
$sql = "select  max(my_seqnum)as my_max from sequfile";
$res = mysql_query($sql) or die( mysql_error() );
$row = mysql_fetch_assoc($res);
var_dump($row);

Open in new window

Author

Commented:
Hi gplana.

I have made the connection, and selected the database, I'm sorry I should have made all that clear.

So I am still perplexed as to how select max produces more than one output - that is if I'm reading the warning correctly and the warning is not talking about parameters going in.

thank you for responding

John
How to Generate Services Revenue the Easiest Way

This Tuesday! Learn key insights about modern cyber protection services & gain practical strategies to skyrocket business:

- What it takes to build a cloud service portfolio
- How to determine which services will help your unique business grow
- Various use-cases and examples

The point is you should use mysql_query function to execute your select, not mysql_fetch_assoc.
And then you should store the result of mysql_query on a variable and use on mysql_fetch_assoc as a single parameter. Please see the example I said before to see the details.

Regards.
Most Valuable Expert 2011
Top Expert 2016

Commented:
SELECT MAX will return one and only one row (there can only be one MAX) or it will return zero rows if the table is empty.  The php function var_dump() can be used to visualize the row that is returned.  It will contain something like this:

$row["my_max"]  = string(3) "365"

Author

Commented:
gplana,

sorry I had missed that and thank you for sending me your original answer

John

Author

Commented:
gplana,

sorry I had missed that and thank you for sending me your original answer

John

Author

Commented:
Ray,

thanks for that, most useful, this is is a further development following on from the posting about generating random number keys and I would really like to thank you for that most useful.
Most Valuable Expert 2011
Top Expert 2016

Commented:
Thanks for the points, John.  Whenever you see a warning message from PHP it (almost always) contains the name of a function.  Look that up on PHP.net and you will find a pretty good explanation of how to use the function.  Best, ~Ray

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial