[英]using php, how would I convert all rows of a char field such as “11/19/10” to a date field?
[英]How would I get all the values of a field in mysql using php?
我有3行和3個字段,其中一行是數字,如何獲得所有這些數字? 在那個領域? 在for循環中不能像mysql_fetch_rows()一樣工作?
<?php
$result = mysql_query("SELECT id,email FROM people WHERE id = '42'");
if (!$result) {
echo 'Could not run query: ' . mysql_error();
exit;
}
$row = mysql_fetch_row($result);
echo $row[0]; // 42
echo $row[1]; // the email value
?>
在此代碼中,從表“ people”中選擇了一個id = 42
的“ person”。 結果只需要一行,因此,所需的只是$row = mysql_fetch_row($result);
。
$row
將是這樣的: array(0 => 42, 1 => 'person@people.xx');
。
要打印電子郵件,請通過回顯$row[1]
訪問$row
的第二個位置。
這正是有關mysql_fetch_row()
php文檔的內容
另一方面,如果您希望從查詢中返回幾行,例如: SELECT id, email FROM people WHERE email LIKE '%@people%'
from SELECT id, email FROM people WHERE email LIKE '%@people%'
類似SELECT id, email FROM people WHERE email LIKE '%@people%'
,則應使用帶有while
循環的mysql_fetch_array()
。 您可以在mysql_fetch_array()
文檔中查看示例
如果您要問如何從一個結果中的三個不同行中獲取所有三個數值,則應查看MySQL的GROUP_CONCAT()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.