코드가 있는데 올바른지 구조가 가능한지 확실하지 않습니다.테이블에있는 행의 값으로 배열을 채우는 중
이$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
채울 수있는 방법입니다 : 다음 코드는?
$ array1 = $ 행 부분의 $ array1 []에 ctr ?? like $ array1 [ctr] = $ row [ 'names']; CTRL +? –
아니요,'$ array1 [] = $ row'는 $ row를 배열의 끝에 추가합니다. 그것은 자동적으로 성장할 것입니다 :). –