I want to select a single column from a table but cannot use "mysql_result" query. is there any other way to output the data of that specific column?

Thanks in advance.

$sql = mysql_query("SELECT any_column FROM yourtable")
while($row=mysql_fetch_array($sql)){
echo $row['any_column'];
}
Member Avatar for rajarajan2017
$query = "SELECT country FROM symbols";

$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); 
if (mysql_num_rows($result) > 0) { 
 echo "column selected";
} else echo "no column selected"
$sql = mysql_query("SELECT any_column FROM yourtable")
while($row=mysql_fetch_array($sql)){
echo $row['any_column'];
}

thanks for reply, but this will display all the fields from any particular column. i just want a single field.

yes we are selecting only a single field which is any_column no other else, FYI the column's are the fields othe table, maybe you mean return a single row? which is the queried recordset

then limit it with a WHERE clause, like

$sql = mysql_query("SELECT any_column FROM yourtable WHERE id=1")
while($row=mysql_fetch_array($sql)){
echo $row['any_column'];
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.