My code keeps on print the word "array" instead of the database information. When i try to use print_r()
or var_dump()
it echos all the information about the array
this is with var_dump
array(1) { ["Team"]=> string(8) "Oakville" } array(1) { ["Team"]=> string(8) "Brampton" } array(1) { ["Team"]=> string(7) "Toronto" } array(1) { ["Team"]=> string(11) "Mississauga" }
Here's my code
if(isset($_REQUEST['submit2'])){
$leaguename = $_POST['league'];
$db_host = '**';
$db_user = '**';
$db_pwd = '**';
$database = '**';
$db = new mysqli($db_host, $db_user, $db_pwd, $database);
$sql = "SELECT Team FROM Games WHERE League = '$leaguename' AND Team <> ''";
$result = mysqli_query($db, $sql) or die ("no query");
if (!$result) {
die('Invalid query: ' . mysqli_error());
}
$array = array();
while($row = mysqli_fetch_array($result,MYSQLI_ASSOC)){
$array[] = $row;
}
$teamnumber=count($array);
echo $teamnumber . "<br>";
foreach($array as $teams=>$team){
var_dump($team);
}
I'm trying to print the names of sports teams that are being fetched from a database and put into an array.