Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fetching one row only with MySQLi

Tags:

php

mysqli

How can I only fetch one INDEXED row with MySQLi? I'm currently doing this:

$row = $result->fetch(MYSQLI_ASSOC); $row = $row[0]; 

Is there another way?

I'm aware of mysqli_fetch_row but it doesn't return an associative array.

like image 478
oaziz Avatar asked Jan 17 '12 11:01

oaziz


People also ask

How can you retrieve a particular row of data from a set of MySQLi results?

The fetch_row() / mysqli_fetch_row() function fetches one row from a result-set and returns it as an enumerated array.

How can I get single record in PHP?

First you connect to your database. Then you build the query string. Then you launch the query and store the result, and finally you fetch what rows you want from the result by using one of the fetch methods. Show activity on this post.

What is mysqli_query () used for?

The query() / mysqli_query() function performs a query against a database.


1 Answers

Use $row = $result->fetch_assoc(); - it's the same as fetch_row() but returns an associative array.

like image 74
You Qi Avatar answered Sep 21 '22 12:09

You Qi