n Java, If you want to populate a combobox you first get into an array then populate it into the Combobox. I am assuming the process is similar in PHP. As you probably have guessed I am new to PHP. Loving it’s power just need to learn how to harness it.
I have an array using the fetchAll(); and storing it into $data. Then I run a for loop and storing into a new variable called $row. I am able to print my entire database out using the print_r method. Boom, my whole array is there. Then I think I stumbled onto away of putting into a combobox. The problem is it’s blank.
When I try to put the print_r method inside the loop and print the content I get the first place in my array. If I do this in Java, it should print everything as it goes through the loop. This is not happening. Then Depending on the location i put the print_r method it will just put the entire database into my combobox. The text that is inputted into the Combobox is an array format so it’s no good. Any suggestions or thoughts?
[php]
try{
$conn = new PDO(‘mysql:host=Jamal-PC;dbname=japanesewords’,$username,$password);
$sql =‘SELECT Englishword FROM Japanesedefinition;’;
$stmt = $conn->prepare($sql);
$stmt ->execute();
$data = $stmt->fetchAll(PDO::FETCH_COLUMN);
}catch(PDOException $e){
echo 'ERROR: ’ . $e->getMessage();
}
?>
<?php foreach($data as $row) : ?> <?= $row['EnglishWord']; ?> <?php endforeach ?>[/php]