Using an SQL result in a foreach loop

后端 未结 5 1551
谎友^
谎友^ 2021-01-06 10:36

I feel like I am missing something stupidly obvious here, I am trying to get the results of an SQL query and then using them in a loop. I feel like I am missing something st

5条回答
  •  广开言路
    2021-01-06 10:48

    The return type of the $results = mysql_query($query); is a resource of type object. For example:

    object(mysqli_result)#3 (5) { 
      ["current_field"] => int(0) 
      ["field_count"] => int(3) 
      ["lengths"] => NULL 
      ["num_rows"] => int(2) 
      ["type"] => int(0) 
    }
    

    Since, we are only interested with the table data. We have the pass the resource to mysql_fetch_array(), and other functions for dealing with result tables, to access the returned data according to PHP Docs

    We cannot directly use it.

    However, If you are having problem understanding the inner working of while loop i will give you an example.

    dis())
        {
            echo $fac."
    "; $GLOBALS['s']++; } ?>

提交回复
热议问题