KUPSKIE KUPSKIE - 7 months ago 21
PHP Question

If The Field Is NULL The Number Will Not Appear - USING PHP

I have a blank data in mysql, and when I call it that blank data. The Number will Appear... Example


  1. Sample Data

  2. --Blank--

  3. Sample Data



I want to remove the Number 2. so that it will become 1-2..

$num = 0;


I use $num++ foreach data;

$num = 0;

mysql_connect('localhost','root','');

mysql_select_db('dbase');

$SQL = " SELECT * FROM table ";
$query = mysql_query($SQL);

while($data = mysql_fetch_assoc($query))
{
$num++;

echo $num;

echo $data['Name']

}


OUTPUT :

1. SAMPLE
2.
3. SAMPLE


I want to make this

1. SAMPLE
2. SAMPLE

Answer

You could add a condition in a WHERE clause on the SQL query so that only the rows you want to display are returned, I'd also recommend you add an ORDER BY clause to your query, so the result is more deterministic. And if you only need one column returned (the `Name` column), then specify the column in the SELECT list, instead of returning all columns in the table.

SELECT t.Name
    FROM table t
WHERE t.name <> ''
   ORDER BY t.name