User Contributed Notes: mysql_result
rsarno@msn.com
17-Jul-1999 03:12
print "<table border=\"1\" cellspacing=\"2\">";
print "<tr>";
for($i=0; $i<$n_columns; $i++) {
$field_names = mysql_field_name($result,$i);
print "<td><b>" . $field_names . "</b></td>";
}
print "</tr>";
for ($j=0; $j<$n_records; $j++) {
print "<tr>";
for($i=0; $i<$n_columns; $i++) {
$rows = mysql_result($result, $j, $i);
print "<td>" . $rows . "</td>";
}
print "</tr>";
}
print "</table>";
messi@iname.com
21-Jan-2000 05:29
If it returns the content of one cell, how can the return value be an int?
Please clarify
jeff@cepheid.org
23-Jan-2000 05:31
It passes the result by reference
to the "mixed" variable in the function
call. the int return is used for loops
to indicate when there is data remaining
to be returned
martin-at-koistinen-dot-com
14-Feb-2000 07:39
The above comment seems erroneous, so does the function prototype in this documentation. The function returns the value of the requested cell from the results set. The last argument is declared ablve as mixed because it can be either an integer or a string. The function will clearly return a string if that is contained in the requested cell.
<pre>
[mixed] = mysql_result([int db result handle],[int row],[string or int-offset column]);
</pre>
soferstam@netzero.net
17-Feb-2000 12:22
I am new in php.
What is exactly the syntax for mysql_result() if i whant to get data from mysql_query("select ID from.....")?
brw12@columbia.edu
28-Mar-2000 07:24
you can say:
<b>$result=mysql_query("SELECT * FROM tablename;",$db);</b>
with $db being a database already connected with mysql_connect and that you selected with mysql_select_db
then:
<b>
printf("First Name: %s", mysql_result($result,1,"fname"));</b>
here, the dataspace (column) 'fname' is selected for row number 1 of the output you grabbed in $result.
So in short, mysql_result takes your result from your query as its first parameter.
learn more at <b>www.devshed.com</b>
or at <b>www.webmonkey.com</b>.
-Ben Wheeler
ywei1997@hotmail.com
04-Apr-2000 04:02
How can I get the result num of this SQLQuery: "select count(*) from mytable"
Thanks
martemas@email.com
04-Apr-2000 08:42
you can either user mysql_num_rows function or if you really need to use mysql_result to get the result of your "SELECT count(*) from table", do the following :
$dbresult = mysql_query("SELECT count(*) from table",$handler);
$Result = mysql_result($dbresult,0);
The result of your query should be in $Result
eduany@aol.com
04-Apr-2000 09:00
hello to all just a lil' note
when adding code use the <pre> HTML TAG st the beginig of your code and </pre> at the end so that your code is easier to understand, EX:
<pre>
mysql_fetch_array
mysql_fetch_array
</pre>
instead of:
mysql_fetch_array
mysql_fetch_array
ed
eduany@aol.com
04-Apr-2000 09:02
sorry i meant
<pre>
the "<PRE>" HTML TAG at begining
and "</PRE>" at end of your code
</pre>
ed
eduany@aol.com
04-Apr-2000 09:06
LMAO (laughin my ass off)
you guys know what i meant......
this tag PRE and /PRE
just like the <html> and </html> tags
Marcel
30-Jun-2000 06:58
How do I distinguish between an empty result, a bad row/column offset or a bad result handle?
None of the above produce MySQL errors, just warnings, and all of them return an empty string.
gdesjardins@anomalie.com
23-Jul-2000 09:43
I have the following code:
$sql = "SELECT student_id, name FROM students WHERE name LIKE '$Name'";
$overwrite = mysql_query($sql,$db);
echo "overwrite is $overwrite ";
if (!$overwrite) {
$status=1;
break;
}
$id_exists = mysql_result($overwrite,0,"student_id");
$name_exists = mysql_result($overwrite,0,"name");
If $name_exists is not null, I want to UPDATE instead of INSERTing stuff in the db. It works fine, however i keep getting the warning
"Warning: Unable to jump to row 0 on MySQL result index 2 in..." when the query doesn't return anything.
How can i get rid of the warnings? it seems that mysql_result doesn't return an empty row when there aren't any results, but an undefined object...however $overwrite=2 not 0 ....
Any help would be appreciated.
pcsmit@bart.nl
01-Aug-2000 09:13
Is it possible to get the data from a mysql query directly to an emailadress.
For expample i want to create a button on a web page wich reads the database and send the result from it to an email adres. Thanx, Paul.
pdrew1979
07-Aug-2000 05:02
Have a look at mail()
Quite simple. Do your query. Get the result. Use mail() to send the result.
Andrew
skysign@dreamwiz.com
13-Aug-2000 02:23
mysql_result() is have a one bug.....
$loop = mysql_affected_rows();
for($i=0 ; $loop>= ; ++$i)
{
$row = mysql_result($result,$i);
$row = mysql_fetch_object($row);
// echo something....
// like that $row->name $row->date...
}
everyone think that $row is object. but, above code NOT RUN....
mysql_result() is not return a row.