-1

I'm trying to obtain a column name EmailId from the table named Users. But it returns only the first string and nothing else?

PHP:

$sql="SELECT EmailId FROM Users;";
$result =mysqli_query($conn,$sql);
$col=mysqli_fetch_array($result);

The database has 3 email-ids but count($col) returns only 1. Why so?

Thanks in advance.

Pascal
  • 1,288
  • 8
  • 13
Rishi
  • 45
  • 9
  • 2
    Because there is only one column in the array returned by `mysqli_fetch_array()`. Read the manual to learn how these functions actually work. – John Conde Apr 12 '14 at 14:35
  • So how can I get the column in an array? – Rishi Apr 12 '14 at 14:37
  • To get the first value: $row = mysql_fetch_row($result); echo $row[0]; – Marcos Aguayo Apr 12 '14 at 14:38
  • I mean all the rows in a column? – Rishi Apr 12 '14 at 14:39
  • You need to do a better job explaining what you're looking for. If you mean all of your results, you need to loop through the results. Once again, read the manual as it shows you how to do this. – John Conde Apr 12 '14 at 14:41
  • possible duplicate of [Get all values in a column using PHP?](http://stackoverflow.com/questions/5229501/get-all-values-in-a-column-using-php) – Uri Agassi Apr 12 '14 at 15:55

1 Answers1

1

The database has 3 email-ids but count($col) returns only 1. Why so?

Because

$col=mysqli_fetch_array($result);

only fetch the first row according to the internal pointer of the dataset, and therefore

count($col) 

returns 1 because $col is an array having 1 item.

davidkonrad
  • 83,997
  • 17
  • 205
  • 265