这只是解决方法,您可以按照 chrisR 所说的那样更改表格的结构
但是,如果您愿意,可以在这里查看,如果它对您有帮助。
$con = mysql_connect("localhost","root","admin");
if (!$con)
{
die('Could not connect ya rafik : ' . mysql_error());
}
mysql_select_db("mydatabase", $con);
$query = mysql_query("SELECT * FROM mytable2 ORDER BY name ");
// please use PDO or mysqli instead.
然后你像这样通过php管理结果
while ($column_data = mysql_fetch_assoc ($query)) {
echo $column_data['name']." does : ";
if ($column_data['sports_1'] == 1 ){echo " Sport1 ";} else {}
if ($column_data['sports_2'] == 1 ){echo " Sport2 ";} else {}
if ($column_data['sports_3'] == 1 ){echo " Sport3 " ;} else {}
echo "<br />" ;
}
数据库是这样的
id name sports_1 sports_2 sports_3
1 Mark 1 0 1
2 John 0 1 1
结果将是这样的:
John does : Sport2 Sport3
Mark does : Sport1 Sport3