Search the Community
Showing results for tags 'mysqli php array'.
-
I have a foreach statement that contains 20 values. with each value I run a query on tables to return results. I can get it to create an array but it only shows last foreach values returned results. How do I get all 20 results to be in $all_data array. my code so far is $all_data = array(); foreach($id as $idkey => $iduse){ global $all_data, $all_player_data, $temparr, $data; $all_player_data = array(); $temparr = array(); $result_time = $conn->query("SELECT * FROM ".$iduse." order by timedate Asc"); $temptdarray = array(); while ($rowtime = $result_time->fetch_row()) { $timedate = $rowtime[0]; // row 0 $numplayers = $rowtime[1]; // row 1 $maxplayers = $rowtime[2]; // row 2 $status = $rowtime[3]; // row 3 $players = $rowtime[4]; // row 4 $mapname = $rowtime[5]; // row 5 $maptype = $rowtime[6]; // row 6 $data = array("timedate" => $timedate, "numplayers" => $numplayers, "maxplayers" => $maxplayers, "status" => $status, "players" => $players, "mapname" => $mapname, "maptype" => $maptype); array_push($temparr, $data); } $all_player_data[] = array("id" => $idonly[$idkey], "comment" => $comment[$idkey], "data" => $temparr); array_push($all_data[], array($all_player_data)); } if I print_r($all_data) I get all_data Array ( [0] => [1] => [2] => [3] => [4] => [5] => [6] => [7] => [8] => [9] => [10] => [11] => [12] => [13] => [14] => [15] => [16] => [17] => [18] => [19] => ) if I print_r($all_player_data) I get all_player_data Array ( [0] => Array ( [id] => 80 [comment] => FooFire Attack Team [data] => Array ( [0] => Array ( [timedate] => 2021-03-17 16:34 [numplayers] => 0 [maxplayers] => 10 [status] => 1 [players] => [mapname] => SF Village Coop [maptype] => COOP ) [1] => Array ( [timedate] => 2021-03-20 07:12 [numplayers] => 1 [maxplayers] => 10 [status] => 1 [players] => --=P-51=-- [mapname] => SF Village Coop [maptype] => COOP ) [2] => Array ( [timedate] => 2021-03-20 07:26 [numplayers] => 2 [maxplayers] => 10 [status] => 1 [players] => --=P-51=--, [FFAT]herbstfuerst [mapname] => SF Village Coop [maptype] => COOP ) [3] => Array ( [timedate] => 2021-03-20 07:28 [numplayers] => 3 [maxplayers] => 10 [status] => 1 [players] => --=P-51=--, [FFAT]herbstfuerst, YAKIR [mapname] => SF Village Coop [maptype] => COOP ) .................blah blah blah [7223] => Array ( [timedate] => 2021-12-05 06:26 [numplayers] => 0 [maxplayers] => 10 [status] => 1 [players] => [mapname] => SF Village Coop [maptype] => COOP ) [7224] => Array ( [timedate] => 2021-12-05 07:26 [numplayers] => 0 [maxplayers] => 10 [status] => 1 [players] => [mapname] => SF Village Coop [maptype] => COOP ) [7225] => Array ( [timedate] => 2021-12-05 08:26 [numplayers] => 0 [maxplayers] => 10 [status] => 1 [players] => [mapname] => SF Village Coop [maptype] => COOP ) ) ) How do I get all 20 result sets into $all_data?
-
Hello every one so, I've been using mysql for almost 2years and I've heard that using MySQLi is more secure and I m still new in the prepared statement thing that's why I was wandering how to do this prepared statement with arrays ?? in an example I have this code, how can I execute it with prepared statement ? $sql = mysqli_query($con, "SELECT users.regdate, topics.topic_body FROM `users` LEFT JOIN topics ON topics.topic_author = users.id WHERE topics.id=1 order by topic_edit_time ASC"); if( mysqli_num_rows($sql)>0 ) { while($row = mysqli_fetch_array($sql)) { echo htmlentities($row['regdate']) . "<br>" ; echo htmlentities($row['topic_body']); } } else { echo 'not found'; } Thanks