Display query result in a table

后端 未结 4 1518
谎友^
谎友^ 2021-01-22 20:01

I have a MySQL query with over 50 return results. Now I need to display the results in a table with 3 rows and 3 columns.

Something like this:



        
4条回答
  •  感情败类
    2021-01-22 20:26

    try something like:

     echo "";
     while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) {
     $name   = $row['name'];
     $address = $row['address'];
     $content = $row['content'];
     echo "";
     }
     echo "
    ".$name."".$address."".$content."
    ";

    this example will print in table all the result of the query. if you want to limit only to some results, so limit the sql query. for example:

     $q = "SELECT name, address, content FROM mytable limit 50"; 
    

    to get each content,name, address in TD, and 3 of mycontent(content, name, address) in a TR try this:

    $c= mysql_query("select COUNT(name) from mytable");
    $n=mysql_fetch_array($c);
    $maxname= $n[0];
    $i=0;
    $tr=0;
    echo "";
    while ($tr < $maxname)
    { 
    echo "";
    while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC) and $i<$tr) {
    $name   = $row['name'];
    $address = $row['address'];
    $content = $row['content'];
    echo "";
    $i++;
    }
    echo "";
    $tr= $tr+3;
    }
    echo "
    ".$name." | ".$address." | ".$content."
    ";

提交回复
热议问题