Wrong parameter count for mysql_result()

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
mhouldridge
Forum Contributor
Posts: 267
Joined: Wed Jan 26, 2005 5:13 am

Wrong parameter count for mysql_result()

Post by mhouldridge »

Help,

I have forgotten how to correc this. my query works, however my result does not.

Code: Select all

$os_query = mysql_query("SELECT value FROM `os` WHERE id = 1");
	$oscost = mysql_result($os_query);
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

mysql_result() -- The manual is your friend.

Do you need mysql_fetch_array() or mysql_fetch_assoc() ? mysql_result() fetches a gievn result value from the array taking a row index, a field index and the result resource.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

mysql_result() has 2 require arguments, and 1 optional. The one you are missing is the row offset, zero in your case.

The manual shows this... :?
User avatar
mhouldridge
Forum Contributor
Posts: 267
Joined: Wed Jan 26, 2005 5:13 am

Post by mhouldridge »

My table has two colums, id and value.

My table name is os in this case.

I simply need the value from the value column depending upon my id value....

I hope this makes sense.
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

Did you read the manual yet...it makes it perfectly clear there what you need to do
User avatar
mhouldridge
Forum Contributor
Posts: 267
Joined: Wed Jan 26, 2005 5:13 am

Post by mhouldridge »

Nope, is there somewhere on the net that I can find this?
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

feyd gave you the direct link to the correct page in the manual
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

mhouldridge wrote:Nope, is there somewhere on the net that I can find this?
Please lord... please send them now, I'm ready... I'm ready to give my life to the little green people
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post by Charles256 »

mysql_result -- Get result data
Description
string mysql_result ( resource result, int row [, mixed field] )

Retrieves the contents of one cell from a MySQL result set.

When working on large result sets, you should consider using one of the functions that fetch an entire row (specified below). As these functions return the contents of multiple cells in one function call, they're MUCH quicker than mysql_result(). Also, note that specifying a numeric offset for the field argument is much quicker than specifying a fieldname or tablename.fieldname argument.
Parameters

result

The result resource that is being evaluated. This result comes from a call to mysql_query().
row

The row number from the result that's being retrieved. Row numbers start at 0.
field

The name or offset of the field being retrieved.

It can be the field's offset, the field's name, or the field's table dot field name (tablename.fieldname). If the column name has been aliased ('select foo as bar from...'), use the alias instead of the column name. If undefined, the first field is retrieved.
User avatar
mhouldridge
Forum Contributor
Posts: 267
Joined: Wed Jan 26, 2005 5:13 am

Post by mhouldridge »

Im a little confused with that. I know I have to define a starting row, ie ($query, 0); however when I do this it doesnt return the correct value....

Urrghm, please help!
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post by Charles256 »

the counting starts at 0, not 1.help any? also..make sure you're pulling the correct info from the database...
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

If you are only returning 1 row, why not use mysql_fetch_row()
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Debug:

Code: Select all

$os_query = mysql_query("SELECT value FROM `os` WHERE id = 1");
    while($row = mysql_fetch_assoc($os_query)) print_r($row);
User avatar
mhouldridge
Forum Contributor
Posts: 267
Joined: Wed Jan 26, 2005 5:13 am

Post by mhouldridge »

I do not want to return both row data, simply one field within value column.
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

what about this

Code: Select all

mysql_result($query, 0, "value");
Last edited by JayBird on Tue Jan 24, 2006 11:11 am, edited 1 time in total.
Post Reply