jeudi 6 septembre 2018

Make an if-else condition state inside php with an element array [[["5"]]]

I wish you are fine.

I would like to make this one: I want to create an if-else statement inside in a php file but i faced a serious problem. Look at the code below:

first.php

<?php
/* Attempt MySQL server connection. Assuming you are running MySQL
server with default setting (user 'root' with no password) */
$link = mysqli_connect("127.0.0.1", "root", "", "mysql3");
// Check connection
if($link === false) {
    die("ERROR: Could not connect. " . mysqli_connect_error());
}

$user_id =$_POST['user_id'];
$book_id =$_POST['book_id'];
$game_id =$_POST['game_id'];
$site_id =$_POST['site_id'];

    //Attempt insert query execution
$query = "SELECT site_id FROM components WHERE user_id='$user_id' && book_id='$book_id' && game_id='$game_id' ORDER BY site_id DESC LIMIT 1";
$res = mysqli_query($link,$query);
$result = array();

//while($row = mysqli_fetch_array($res)){
//array_push($result, array($row[0]));}
//echo json_encode(array($result));

// Close connection
mysqli_close($link);
?>

When i echo the result (i believe that my output is $result - if i am wrong tell me) then my browser shows me this value [[["5"]]]. Is it possible to have an array inside an array? How can i manipulate this element (for example 5, 3, whatever) in order to make an if-else statement?

Is there a way?

Aucun commentaire:

Enregistrer un commentaire