Check for data in column

Asked

Viewed 452 times

5

Have a check to see if there is data inside a column in a table?

I want to do a check and if there is data in the column it displays a div.

I know the mysql_num_rows to add the data that was searched, but wanted to know if there is a way to check data inside a column.

  • 1

    <?php if (!empty($exibe_painel_usuarios_um [ "twitter" ])) just deny

  • 2

    Solved, echo "<div class="equipe_redes_twitter">". $exibe_painel_usuarios_um [ "twitter" ]."</div>";

  • Thanks for the help.

  • 1

    De boa veiow. o

1 answer

-1

If it is to check only one column, make one SELECT counting the results, using as attribute, if the column is not empty (IS NOT NULL), in the clause WHERE. Then you’ll know if there are any results. In the following example how to validate if there are records for the column, to make your select you must put all items that are necessary for the query you were doing, to get the correct result.

SELECT count(COLUNA) as TOTAL FROM TABLEA WHERE COLUNA IS NOT NULL;

In this case you will get the result of select with the alias "TOTAL" and if it is different from 0, then display the results from another SELECT preeminently.

Making the way this above will reduce consumption of MYSQL, since otherwise will return a row from the entire table, for at the end of the empty column ignore it. Although using the IS NOT NULL and put the column even in mysql also will not give error, but in this case it will be necessary to use the mysql_num_rows and that would consume more resources than making a count in a field.

  • Is not null does not work if it is an empty field case ' '.

Browser other questions tagged

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