我有代码,但我不确定它是否正确以及结构是否可行。这是代码:
$host="localhost";
$username="sample1";
$password="1234";
$db_name="sampledb";
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
function example1(array1) {
//is this allowed??
$array1 = array();
$ctr = 0;
$ctr1=1;
$sql="SELECT names FROM tblnamelist";
$result=mysql_query($sql);
$row=mysql_fetch_array($result);
$count=mysql_num_rows($result);
//I also want to populate the array1 with all the values that was retrieved in the query then return it as an array
if($count!=0) {
while($ctr1<=$count) {
$array1[$ctr]=$row[$ctr];
}
}
}
基本上我的问题是如何填充array1
从查询中检索到的值?