Page 1 of 2

Wrong parameter count for mysql_result()

Posted: Tue Jan 24, 2006 9:29 am
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);

Posted: Tue Jan 24, 2006 9:33 am
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.

Posted: Tue Jan 24, 2006 9:35 am
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... :?

Posted: Tue Jan 24, 2006 10:04 am
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.

Posted: Tue Jan 24, 2006 10:07 am
by JayBird
Did you read the manual yet...it makes it perfectly clear there what you need to do

Posted: Tue Jan 24, 2006 10:21 am
by mhouldridge
Nope, is there somewhere on the net that I can find this?

Posted: Tue Jan 24, 2006 10:31 am
by JayBird
feyd gave you the direct link to the correct page in the manual

Posted: Tue Jan 24, 2006 10:59 am
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

Posted: Tue Jan 24, 2006 11:01 am
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.

Posted: Tue Jan 24, 2006 11:04 am
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!

Posted: Tue Jan 24, 2006 11:06 am
by Charles256
the counting starts at 0, not 1.help any? also..make sure you're pulling the correct info from the database...

Posted: Tue Jan 24, 2006 11:07 am
by JayBird
If you are only returning 1 row, why not use mysql_fetch_row()

Posted: Tue Jan 24, 2006 11:08 am
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);

Posted: Tue Jan 24, 2006 11:08 am
by mhouldridge
I do not want to return both row data, simply one field within value column.

Posted: Tue Jan 24, 2006 11:10 am
by JayBird
what about this

Code: Select all

mysql_result($query, 0, "value");