How to generate columns in MySQL results display?

0

Below is the script that is closest to what I need to generate the MySQL results in 3 columns. That still did not work for me to do the test.

Generating error: Fatal error: Uncaught Error: Call to undefined function mysql_num_rows()

The error refers to this line: $num = ceil( mysql_num_rows( $query ) / $colunas );

Full Code:

<?php
  $query=mysqli_query($con,"select categoria, link from categorias ORDER BY categoria ASC");

  $colunas = 3;
  $num = ceil( mysql_num_rows( $query ) / $colunas );//quantidade de registros por coluna

  $li = '<ul class="coluna">';
  $i = 0;
  while( $dados = mysql_fetch_object( $query ) )
  {
    if( $i==$num )
    {
      $li .= '</ul><ul class="coluna">';
      $i=0;
    }

    $li .= '<li>'.$dados->bairro.'</li>';
    $i++;
  }
  $li .= '</ul>';
  echo $li;
?>
    
asked by anonymous 04.07.2017 / 13:08

1 answer

2

You are piling up your script mysqli_query with mysql_query

mysqli_query

mysql_num_rows

mysql_fetch_object

The correct one is

mysqli_query

mysqli_num_rows

mysqli_fetch_object

Since the relational database management system, MySQL, has been discontinued.

    
04.07.2017 / 13:23