★ wanayoo — archive 1999 http://www.php.net/manual/ja/function.mysql-result.phpNouvelle recherche | Portail wanayoo

PHP Home Page

Manual Table of Contents
Up to MySQL
Quick Reference
English version of this pageGerman version of this pageItalian version of this pageFrench version of this pageHungarian version of this page
MySQL
* mysql_affected_rows
* mysql_change_user
* mysql_close
* mysql_connect
* mysql_create_db
* mysql_data_seek
* mysql_db_query
* mysql_drop_db
* mysql_errno
* mysql_error
* mysql_fetch_array
* mysql_fetch_field
* mysql_fetch_lengths
* mysql_fetch_object
* mysql_fetch_row
* mysql_field_name
* mysql_field_seek
* mysql_field_table
* mysql_field_type
* mysql_field_flags
* mysql_field_len
* mysql_free_result
* mysql_insert_id
* mysql_list_fields
* mysql_list_dbs
* mysql_list_tables
* mysql_num_fields
* mysql_num_rows
* mysql_pconnect
* mysql_query
* mysql_result
* mysql_select_db
* mysql_tablename
Manual: mysql_result
View the source code for this pageSearch the site



Previous page
 mysql_query
 Updated
Mon, 14 Aug 2000
mysql_select_db 
Next page


mysql_result

(PHP3 , PHP4 )

mysql_result -- 結果データを得る

説明

int mysql_result (int result, int row [, mixed field])

mysql_result() は、MySQL 結果セットから一つの セルの内容を返します。 引数fieldには、フィールドのオフセットまたはフィールド名または フィールド名.テーブル名を指定可能です。 カラム名のエイリアスが定義されている場合 ('select foo as bar from...')、そのカラム名の代わりにエイリアスを 使用して下さい。

大量の結果セットで作業を行う際、(以下で示す) 行全体を取り込む関氣n一つを使用することを検討するべきです。 これらの関数は一回の関数コールで複数のセルの内容を返すので、 mysql_result()よりもかなり高速です。 また、フィールド引数としてオフセット数値を指定する方が フィールド名やテーブル名.フィールド名のように指定するよりも かなり高速です。

mysql_result() は、 結果セットを処理するほかの関数と混用することはできません。

推奨される高性能な代替案は、mysql_fetch_row()mysql_fetch_array()mysql_fetch_object()です。


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>

&nbsp;&nbsp;
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>

&nbsp;&nbsp;
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.



 About Notes


Previous page
 mysql_query
 Updated
Mon, 14 Aug 2000
mysql_select_db 
Next page





Who's responsible for this?
Top of this page

Site
Hosting:



Located in
United States
Elements of this website are subject to copyright.
Questions about installing or using PHP should be directed to one of the mailing lists.
Only questions about the website should be directed to webmaster@php.net.