Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am wanting to search through AdvInfo table and store the primary keys if Unit = Child.

 $result = mysqli_query($conn, "SELECT * FROM AdvInfo WHERE Unit = Child");     
 while ($row = mysqli_fetch_array($result, SQLSRV_FETCH_ASSOC))
 {

$childhbc = array_merge($childhbc, $row[0]);
echo $childhbc[0];
 }
share|improve this question
 
can you echoing your select query ? –  VIVEK-MDU Aug 16 at 19:05
 
No. echoing $childhbc also returns nothing –  Erkdance Aug 16 at 19:21
add comment

2 Answers

The second argument to array_merge should be an array. But to quote the documentation:

mysqli_fetch_array [...] returns an array of strings that corresponds to the fetched row or NULL if there are no more rows in resultset.

In your code, $row is an array. $row[0] is a string.

while ($row = mysqli_fetch_array($result, SQLSRV_FETCH_ASSOC))
{
    $childhbc = array_merge($childhbc, $row);
    echo $childhbc[0];
}
share|improve this answer
add comment

Keep it simple, man

$childhbc = array();
$result = mysqli_query($conn, "SELECT * FROM AdvInfo WHERE Unit = Child");     
while ($row = mysqli_fetch_row($result))
{
    $childhbc[] = $row[0];
}

The less intricate words you use - the better your program works

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.