2

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];
 }
2
  • can you echoing your select query ? Commented Aug 16, 2013 at 19:05
  • No. echoing $childhbc also returns nothing Commented Aug 16, 2013 at 19:21

2 Answers 2

1

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];
}
1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.