How to generate columns in Mysql results view?

Asked

Viewed 53 times

0

Below is the script closer than I need to generate Mysql results in 3 columns. Even so it didn’t work for me to do the test.

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

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

Complete 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;
?>
  • 1

    Puts i in mysql_num_rows, and mysql_fetch as well

1 answer

2

You’re jamming your script mysqli_query with mysql_query

mysqli_query

mysql_num_rows

mysql_fetch_object

The correct and most suitable is

mysqli_query

mysqli_num_rows

mysqli_fetch_object

as the relational database management system, Mysql, has been discontinued.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.