Page 1 of 1

understanding the fetch_assoc

Posted: Thu Jan 08, 2015 7:47 am
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 ?

Re: understanding the fetch_assoc

Posted: Thu Jan 08, 2015 7:51 am
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.