I'm trying to fill one array with the data obtained by one sql select query execution but I can't do it, if someone please could help me.
I'm still very new to programming on php so sorry for that, probably this is really bad coding but I don't know how to fill the array with the foreach loop.
The data returned by the sql database server is:
1 La Defense - Chateau de Vincennes
2 Porte Dauphine - Nation
3 Pont de Levallois Becon - Gallieni
3bis Gambetta - Porte des Lilas
4 Porte de Clignancourt - Mairie de Montrouge
5 Bobigny Pablo Picasso - Place d’Italie
6 Charles de Gaulle Etoile - Nation
7 Louis Leblanc - Pre Saint Gervais
8 Balard - Pointe du Lac
9 Pont de Sèvres - Mairie de Montreuil
10 Boulogne Pont de Saint Cloud - Gare d’Austerlit...
11 Chatelet - Mairie des Lilas
12 Front Populaire - Mairie d’Issy
13 Gare Saint Lazare - Olympiades
My php function is:
function select($tipoTte) {
$connection = connectDB();
$sql = mysqli_prepare($connection, "SELECT DISTINCT linea FROM lugar_transporte WHERE tipoTte = ?");
mysqli_stmt_bind_param($sql, "s", $tipoTte);
$query = $sql->execute();
if(!$query)
die();
$result = $sql->store_result();
$realresult = $sql->bind_result($linea);
$rawdata = array();
$sql->fetch();
for($i = 0; $i < 14; $i++) {
$rawdata[$i] = utf8_encode($linea);
}
disconnectDB($connection);
return $rawdata;
}
How can I fill the rawdata array with all the rows from the query? I mean I want to rawdata have the data like this:
rawdata["Linea 1 La Défense - Chateau de Vincennes", "Linea 2 Porte Dauphine - Nation ", ...]
EDIT: OK, with the new version of the code I got:
rawdata["Linea 1 La Défense - Chateau de Vincennes", "Linea 1 La Défense - Chateau de Vincennes", "Linea 1 La Défense - Chateau de Vincennes", ...]
How can I do to iterate throw the rows of the query result? I don't know if I'm explaining myself correctly...
$rawdata[] = 'Linea ' . $valor;rawdata['linea'] = $valor;this is a syntax error missing$, also you may wish to use$rawdata['linea'][] = $valor;as others note