Link to home
Start Free TrialLog in
Avatar of johnecollins
johnecollinsFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Get a warning when I use mysqli_fetch_field

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?

Avatar of gplana
gplana
Flag of Spain image

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.
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of johnecollins

ASKER

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
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.
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"
gplana,

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

John
gplana,

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

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