downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

mssql_execute> <mssql_connect
Last updated: Fri, 13 Nov 2009

view this page in

mssql_data_seek

(PHP 4, PHP 5, PECL odbtp >= 1.1.1)

mssql_data_seek内部行ポインタを移動する

説明

bool mssql_data_seek ( resource $result_identifier , int $row_number )

mssql_data_seek() は、指定した結果 ID が指す MS SQL 結果に関する内部行ポインタを指定した行番号に移動します。 最初の行は行番号 0 となります。 この後、mssql_fetch_row() をコールした場合、 その行を返します。

パラメータ

result_identifier

処理対象となる結果リソース。

row_number

新しい結果ポインタの行番号。

返り値

成功した場合に TRUE を、失敗した場合に FALSE を返します。

例1 mssql_data_seek() の例

<?php
// MSSQL に接続します
$link mssql_connect('MANGO\SQLEXPRESS''sa''phpfi');
mssql_select_db('php'$link);

// すべての人を選択します
$result mssql_query('SELECT [name], [age] FROM [persons] WHERE [age] >= 13');

if(!
$result)
{
    die(
'Query failed.');
}

// 結果の中から 4 人おきに学生を選択します
for($i mssql_num_rows($result) - 1$i 4$i++)
{
    if(!
mssql_data_seek($result$i))
    {
        continue;
    }
    
    
// 行を取得します ...
}

// 結果を開放します
mssql_free_result($result);
?>



add a note add a note User Contributed Notes
mssql_data_seek
phpcomments at hltools dot com
20-Jul-2005 11:33
mssql_data_seek will return false AND trigger a warning ('Bad row offset') if you specify a row outside the result set.
You'll need to check beforehand if the row you are trying to seek to exists. Or you can supress the error and look for the false result, depending on your needs.

To check beforehand (where $result is the result fo your query and $seek is the row number you want to seek to):
<?php
$rowcount
= mssql_num_rows($result);
if (
$seek >= $rowcount)
{
    print (
"Trying to seek outside result set!");
}
else
{
    if (!
mssql_data_seek($result, $seek))
    {
        print (
"Seek failed");
    }
    else
    {
        print (
"Seek complete");
    }
}
?>

To have a 'simpler' way of handling errors by supressing the warning:
<?php
if (!@mssql_data_seek($result, $seek))
{
    print (
"Seek failed");
}
else
{
    print (
"Seek complete");
}
?>

mssql_execute> <mssql_connect
Last updated: Fri, 13 Nov 2009
 
 
show source | credits | sitemap | contact | advertising | mirror sites