0

I was wondering how to turn a SQL Query into a variable like this one:

$in = "Lambo 1; Trabant 2; Car 3;";

$result=mysqli_query($conn,$sql_query);

The query currently comes back with Lambo 1; Trabant 2; Car 3; but how would I change it into $in? As if I currently run it through another func I getexplode() expects parameter 2 to be string,

Full code:

<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
    $host = 'localhost';
    $username = '';
    $password = '';
    $database = '';
    $conn = mysqli_connect($host,$username,$password,$database);

$SteamID = "STEAM_0:0:81010017";
$sql_query="SELECT _Inventory FROM Players Where _SteamID='$SteamID'";

$result=mysqli_query($conn,$sql_query);


$in = $result;
foreach (explode(";", $in) as $element) {
        $element = trim($element);
        if (strpos($element, " ") !== false ) {
                list($car, $number) = explode(" ", $element);
                echo $car;
        }
}


?>
3
  • have you tried using mysql_fetch_array() instead of sql_query()? Commented May 22, 2016 at 19:46
  • Still doesn't work Commented May 22, 2016 at 19:53
  • see the answers with the hint from my comment - this should work. Commented May 22, 2016 at 19:53

2 Answers 2

1

mysqli_query returns false or a mysqli_result object.

You need to add something to actually get the results - either by calling fetch_object, fetch_array, fetch_assoc as shown below:

while ($row = $result->fetch_array()){
    $group_arr[] = $row;
}
Sign up to request clarification or add additional context in comments.

2 Comments

Hmm, still doesn't work when using this line of code, still bringing up a HTTP 500 Error
need to add something means not need to use this line of code
0

change your $in variable to:

$in = mysqli_fetch_array($result)[0];

3 Comments

Breaks the code and just displays a HTTP Error 500.
can you var_dump($result)??
Thanks, a small typo in the code caused it. Accepting your answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.