understanding the fetch_assoc

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
gautamz07
Forum Contributor
Posts: 331
Joined: Wed May 14, 2014 12:18 pm

understanding the fetch_assoc

Post by gautamz07 »

Code: Select all

$this->sql = "SELECT * FROM $this->tableMaster";

try{
$results = $this->hookup->query($this->sql);

while($row = $results->fetch_assoc()){
printf("id is %s and the name is %s " . $row['id'] , $row['name'] , $row['lang'] );
echo "<br>";
}
in the above code hookup holds the connection to the database , just had a few difficulties understanding the code .

is the query run in the following line ??

Code: Select all

$results = $this->hookup->query($this->sql);
or in the following line :

Code: Select all

while($row = $results->fetch_assoc()) ????
also by adding fetch_assoc() in the while loop we are specifying that we would like only one row to be retrived at a time ? am i right ?
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: understanding the fetch_assoc

Post by Weirdan »

gautamz07 wrote:
is the query run in the following line ??

Code: Select all

$results = $this->hookup->query($this->sql);
Yes.
gautamz07 wrote: also by adding fetch_assoc() in the while loop we are specifying that we would like only one row to be retrived at a time ? am i right ?
Yes.
Post Reply