Home Backend Development PHP Tutorial php中将指针移动到数据集初始位置的实现代码[mysql_data_seek]_PHP

php中将指针移动到数据集初始位置的实现代码[mysql_data_seek]_PHP

Jun 01, 2016 pm 12:09 PM
pointer data set

复制代码 代码如下:

// Start snipit 1
$sql = "SELECT * from

";
$result = mysql_query($sql);
while ($row = mysql_fetch_assoc($result)) {
// do stuff with $row
}
mysql_data_seek($result, 0); //关键是这儿
while ($row = mysql_fetch_assoc($result)) {
// do other stuff with $row
}
?>


定义和用法

mysql_data_seek() 函数移动内部结果的指针。

语法

mysql_data_seek(data,row)参数 描述
data 必需。返回类型为 resource 的结果集。该结果集从 mysql_query() 的调用中得到。
row 必需。想要设定的新的结果集指针的行数。0 指示第一个记录。

说明

mysql_data_seek() 将 data 参数指定的 MySQL 结果内部的行指针移动到指定的行号。
接着调用 mysql_fetch_row() 将返回那一行。
row 从 0 开始。row 的取值范围应该从 0 到 mysql_num_rows - 1。
但是如果结果集为空(mysql_num_rows() == 0),要将指针移动到 0 会失败并发出 E_WARNING 级的错误,mysql_data_seek() 将返回 false。

返回值

如果成功则返回 true,失败则返回 false。

提示和注释

注释:mysql_data_seek() 只能和 mysql_query() 一起使用,而不能用于 mysql_unbuffered_query()。

例子
复制代码 代码如下:
$con = mysql_connect("localhost", "hello", "321");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db("test_db",$con);
$sql = "SELECT * from Person";
$result = mysql_query($sql,$con);
print_r(mysql_fetch_row($result));
mysql_data_seek($result,3);
print_r(mysql_fetch_row($result));
mysql_close($con);
?>

输出:
复制代码 代码如下:
Array
(
[0] => Adams
[1] => John
[2] => London
)

Array
(
[0] => Carter
[1] => Thomas
[2] => Beijing
)
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How do generic functions handle pointers and reference types in Golang? How do generic functions handle pointers and reference types in Golang? Apr 16, 2024 pm 04:06 PM

When a generic function handles pointer types in Go, it will receive a reference to the original variable, allowing the variable value to be modified. Reference types are copied when passed, making the function unable to modify the original variable value. Practical examples include using generic functions to compare strings or slices of numbers.

To provide a new scientific and complex question answering benchmark and evaluation system for large models, UNSW, Argonne, University of Chicago and other institutions jointly launched the SciQAG framework To provide a new scientific and complex question answering benchmark and evaluation system for large models, UNSW, Argonne, University of Chicago and other institutions jointly launched the SciQAG framework Jul 25, 2024 am 06:42 AM

Editor |ScienceAI Question Answering (QA) data set plays a vital role in promoting natural language processing (NLP) research. High-quality QA data sets can not only be used to fine-tune models, but also effectively evaluate the capabilities of large language models (LLM), especially the ability to understand and reason about scientific knowledge. Although there are currently many scientific QA data sets covering medicine, chemistry, biology and other fields, these data sets still have some shortcomings. First, the data form is relatively simple, most of which are multiple-choice questions. They are easy to evaluate, but limit the model's answer selection range and cannot fully test the model's ability to answer scientific questions. In contrast, open-ended Q&A

How to enable or disable enhanced pointer precision on Windows 11 How to enable or disable enhanced pointer precision on Windows 11 Sep 27, 2023 pm 12:21 PM

Pointer precision is crucial in situations where higher precision and better cursor positioning are required. It is enabled by default in Windows 11, but you may need to reconfigure enhanced pointer precision for better performance. For example, you might not want Windows to automatically re-adjust the pointer speed, but instead cover a fixed distance when making similar mouse movements. What is enhanced pointer precision? Enhanced pointer precision adjusts how far the cursor moves based on how fast the mouse is moving. Therefore, the faster the mouse moves, the greater the distance covered. For those wondering what Windows Enhanced Pointer Precision does, it changes mouse sensitivity. How to turn enhanced pointer precision on or off in Windows 11? 1. Press through Settings

Implementing OpenAI CLIP on custom datasets Implementing OpenAI CLIP on custom datasets Sep 14, 2023 am 11:57 AM

In January 2021, OpenAI announced two new models: DALL-E and CLIP. Both models are multimodal models that connect text and images in some way. The full name of CLIP is Contrastive Language-Image Pre-training (ContrastiveLanguage-ImagePre-training), which is a pre-training method based on contrasting text-image pairs. Why introduce CLIP? Because the currently popular StableDiffusion is not a single model, but consists of multiple models. One of the key components is the text encoder, which is used to encode the user's text input, and this text encoder is the text encoder CL in the CLIP model

How to use C++ reference and pointer parameter passing? How to use C++ reference and pointer parameter passing? Apr 12, 2024 pm 10:21 PM

References and pointers in C++ are both methods of passing function parameters, but there are differences. A reference is an alias for a variable. Modifying the reference will modify the original variable, while the pointer stores the address of the variable. Modifying the pointer value will not modify the original variable. When choosing to use a reference or a pointer, you need to consider factors such as whether the original variable needs to be modified, whether a null value needs to be passed, and performance considerations.

What are pointers in Python? Do pointers exist in Python? What are pointers in Python? Do pointers exist in Python? Aug 19, 2023 am 11:09 AM

Low-level programming languages, such as C or C++, often use pointers to directly manipulate memory. They enable efficient memory management and low-level data operations. Thelow-levelcomplexitiesofmemoryadministrationareabstractedawayinPython,ahigh-levellanguage.Becauseofthis,PythonlacksexpresspointersinanequalmannerthatCorC++.Asanalternative,Pythonmakesuseofanideacompa

Advanced Golang pointer type methods to improve programming skills Advanced Golang pointer type methods to improve programming skills Apr 07, 2024 pm 06:42 PM

The pointer type approach is available in Go language, which allows you to define a function of pointer type in order to modify the value pointed to without explicitly passing the pointer in the method signature. This provides code simplicity and efficiency since copy-by-value passes do not need to be copied. The syntax of pointer type method is: typeTypeName*Type\nfunc(t*TypeName)MethodName(). To use pointer type methods, you create a pointer to an instance of the type and then use that pointer to call the method. The benefits of pointer type methods include code simplicity, efficiency, and modifiability. It should be noted that the pointer type method can only be used for pointer types, and you need to be careful when using it, because the structure value pointed to may be accidentally

Deep understanding of const in C language Deep understanding of const in C language Feb 18, 2024 pm 12:56 PM

Detailed explanation and code examples of const in C In C language, the const keyword is used to define constants, which means that the value of the variable cannot be modified during program execution. The const keyword can be used to modify variables, function parameters, and function return values. This article will provide a detailed analysis of the use of the const keyword in C language and provide specific code examples. const modified variable When const is used to modify a variable, it means that the variable is a read-only variable and cannot be modified once it is assigned a value. For example: constint

See all articles