我有一个名为tab2的MySQL表。它包含姓名和电话字段
创建了一个名字为 gettabledata():
function gettabledata(){ $data = array(); $query = mysql_query("SELECT * FROM tab2"); $row = mysql_fetch_assoc($query); //Here I am unable to get that how can I pass the fetched data in row // variable to anywhere this function called. // After update: return $row;}if(isset($_POST['action'])){ $gettab = createtable();//calling the function gettabledata //Here I want to get the all data from that table // After doing Update: foreach($gettab as $row){ echo $row['name']; echo $row['phone']; }}执行后,得到如下警告:
`
Warning: Illegal string offset 'name' in E:\xampp\htdocs\practive\csvtest.php on line 29Notice: Uninitialized string offset: 0 in E:\xampp\htdocs\practive\csvtest.php on line 29Warning: Illegal string offset 'phone' in E:\xampp\htdocs\practive\csvtest.php on line 30Notice: Uninitialized string offset: 0 in E:\xampp\htdocs\practive\csvtest.php on line 30Warning: Illegal string offset 'name' in E:\xampp\htdocs\practive\csvtest.php on line 290Warning: Illegal string offset 'phone' in E:\xampp\htdocs\practive\csvtest.php on line 30 `另外在print_r($gettab),我得到了:
Array ( [name] => [phone] => 0 ) 它只是从表中的第一个记录。
相似问题