-3

I want to display single column from database in php. For eg. table contains users details like users|userid|location and I want all userid to be displayed.

I tried using this query :

select userid from users

But output is only first row.

How to get all rows but value of single column only? Here is the code

<?php
 mysql_connect('localhost','root','******') or die(mysql_error());
 mysql_select_db('data') or die(mysql_error());

 $q1 = mysql_query("Select * from user") or die(mysql_error());
 $no = mysql_num_rows($q1);
 $val=0;
 for( $i=1;$i<=$no;$i++)
 {
     $val=$val+1;
     echo"<br><br>";
 $q1=mysql_query("SELECT userid from user") or die(mysql_error());
 $q2 = mysql_result($q1, 0, 0);
 echo "<input type='submit' name='submit' value='$q2'/>";
 }

?>

harry
  • 9
  • 5

2 Answers2

0

http://php.net/manual/en/pdostatement.fetchall.php

To return an array consisting of all values of a single column from the result set, specify PDO::FETCH_COLUMN. You can specify which column you want with the fetch_argument parameter.

vuryss
  • 1,270
  • 8
  • 16
0

not sure if I got it right. Use

SELECT userid FROM tablename;

Thomas
  • 81
  • 1
  • 4