我在我的MySQL數據庫中有一個名爲Sponsors
的表。
此表有兩個字段。 event
和names
。字段names
充滿了不同的詞。例如Pieter, Sam, Thomas
。我想要統計names
中的姓名的數量。統計一個數據庫字段中的項目數
我該如何使用PHP和SQL請求來做到這一點。不過,我覺得這樣的事情...
$query = mysql_result(mysql_query("SELECT names FROM Sponsors WHERE id = '55'"));
$result = str_replace(',',' ', $query);
$total = count($result);
但這並沒有解決這個問題......
編輯
if(!empty($activiteiten))
{
foreach($activiteiten as $k => $v)
{
$query = mysql_result(mysql_query('SELECT aanwezig FROM tblLeidingAgenda WHERE id = "'.$v["id"].'"),0');
$result = str_replace(", ", " ", $query);
$total = str_word_count($result);
echo '<div class="lof-main-item">';
echo '<img src="images/791902news3.jpg" title="Newsflash 2" height="300" width="900">
<div class="lof-main-item-desc">
<h3><a target="_parent" title="Newsflash 2" href="#">'.$v["uur"].'</a></h3>
<p>'.$v["titel"].'</p>
ID: '.$v["id"].'
<form method="post" action="#">
<input type="submit" name="aanwezig" value="Ik ben aanwezig"/><br />
<input type="submit" name="afwezig" value="Ik ben afwezig"/><br />
<input type="submit" name="herinnering" value="Stuur herinnering"/><br />
<input type="text" name="id" value="'.$v["id"].'" />
Ik ben aanwezig ('.$total.'): '.$v["aanwezig"].'<br />
Ik ben afwezig: '.$v["afwezig"].'</form></div></div> ';
}
}
正常化您的數據庫。一個表格用於事件,一個用於贊助商名稱,另一個用於將兩者連接在一起(事件 - 贊助商,每行一組,每個事件多行)。 – Arjan