0

I am trying to query two tables from a database, while using fetch_assoc() (instead of fetch_row()). The code is below and I am not getting any data from this query. I managed to query the first table, then added some code to query the second one and now I am not getting any output. Any help will be appreciated.

    $mysqli = mysqli_connect($servername, $username, $password, "6dwxnmkq", 3314);

    if(!$mysqli){
        die('Connection failed!');
    }

    $sql = "SELECT IndexJedlo, Jedlo, Cena, Priloha FROM `jedalny_listok`";
    $sql .= "SELECT index, polievka, cena FROM `polievky`";

    $jedla = array(8);
    $ceny = array(8);
    $index = array(8);

    $polievky = array(2);
    $polievkyCeny = array(2);
    $polievkyIndex = array(2);
    $i = 0;

    if ($mysqli->multi_query($sql)) {
        do {
            if ($result = $mysqli->store_result()) {
                while ($row = $result->fetch_assoc()) {
                    if($i == 0){
                        array_push($jedla, $row['Jedlo']);
                        array_push($ceny, $row['Cena']);
                        array_push($index, $row['IndexJedlo']);
                    }else{
                        array_push($polievky, $row['polievka']);
                        array_push($polievkyCeny, $row['cena']);
                        array_push($polievkyIndex, $row['index']);
                    }
                }
                $result->free();
            }
            if ($mysqli->more_results()) {
                $i = $i + 1;
            }


        } while ($mysqli->next_result());
    }

    $mysqli->close();
Peter Utekal
  • 87
  • 10
  • 1) Why isn't all this one query? I don't see a connection. 2) That is not valid SQL syntax, you didn't terminate the first `SELECT` by adding a `;` at the end. 3) Here's a thorough [tutorial](https://stackoverflow.com/a/22662582/4205384) on debugging db related problems. – El_Vanja Mar 25 '20 at 20:50
  • 2
    Why are you using multi-query? Just run two separate queries. It much simpler, and there's no reason to use multi-query. – Bill Karwin Mar 25 '20 at 21:34

0 Answers0