1

I am hoping someone can help me with this. I am trying to extract all the values from a single column of a database and store the returned values in a numeric array.

$num = 1;
 $q = "SELECT `uninum` FROM `participants` WHERE `islecturer` = '".$num."'";
    $result = @mysqli_query ($dbcon, $q);
    $storeArray = array();
    while ($row = mysqli_fetch_array($result, MYSQLI_NUM)) {
        $storeArray [] =  $row['uninum'];  
    }


    echo $storeArray [1];
3
  • 1
    So whats not working? For a start you can remove the error suppression from the query @ is almost never a good idea Commented Aug 18, 2015 at 15:22
  • Oh okay, thanks Steve. At present I have not got it to work at all. I am getting an error message for this line $storeArray [] = $row['uninum'];for 'Undefined index' for 'uninum' Commented Aug 18, 2015 at 15:29
  • Use " instead of ' around the column name. Commented Aug 18, 2015 at 15:31

1 Answer 1

2

The second parameter to mysqli_fetch_array sets the array type. You have set it to a numerical index. You want an associative index:

while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { //correct flag
    $storeArray [] =  $row['uninum'];  
}

Or just use the mysqli_fetch_assoc function instead:

while ($row = mysqli_fetch_assoc($result)) { 
    $storeArray [] =  $row['uninum'];  
}
Sign up to request clarification or add additional context in comments.

1 Comment

@Ray No problem, glad i could help

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.