Search the Community
Showing results for tags 'mysqli_fetch_array'.
-
Hi everybody, Please can someone check the snippet of code below and say why it generates a warning as "Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in functions.php on line 6". Same warning is generated for the next line i.e. line 7. Ofcourse this is only due to the earlier line i.e. line 6. 1. $con = mysqli_connect($db_host, $db_user, $db_pass, $db); 2. if(mysqli_connect_errno($con)) die('Could not connect: '. mysqli_connect_error()); 3. 4. $query = "Select * FROM $table WHERE username = '$user' AND id = $id "; // AND id = '$id' AND 5. $result=mysqli_query($con, $query); 6. $row = mysqli_fetch_array($result,MYSQLI_ASSOC); 7. mysqli_free_result($result); I have checked the usage of mysqli_fetch_array($result,MYSQLI_ASSOC) on google and it seems to be almost the same. The difference was only in the $query which on w3schools examples was as follows $query ="SELECT Lastname,Age FROM Persons ORDER BY Lastname"; Can someone please help. Thanks all
-
php array format from the mysqli_fetch_assoc rows
amirelgohary1990 posted a topic in PHP Coding Help
I need to output the exact below array format from the mysqli_fetch_assoc rows The Array "Need to achieve like this" ["172"=>["4","6"],"174"=>["4","6"],"175"=>["4","3","6"],"176"=>["4","3"],"177"=>["4","6"],"181"=>["3","6"],"182"=>["7"],"183"=>["3","4"],"184"=>["4","3","6"],"185"=>["3","6"],"186"=>["8","6"],"188"=>["3","6"],"189"=>["3","6"],"190"=>["6"],"191"=>["3","6","4","7"]]; It's var_dump "Need to achieve like this" array(15) { [172]=> array(2) { [0]=> string(1) "4" [1]=> string(1) "6"} [174]=> array(2) { [0]=> string(1) "4" [1]=> string(1) "6" } [175]=> array(3) { [0]=> string(1) "4" [1]=> string(1) "3" [2]=> string(1) "6" } [176]=> array(2) { [0]=> string(1) "4" [1]=> string(1) "3" } [177]=> array(2) { [0]=> string(1) "4" [1]=> string(1) "6" } [181]=> array(2) { [0]=> string(1) "3" [1]=> string(1) "6" } [182]=> array(1) { [0]=> string(1) "7" } [183]=> array(2) { [0]=> string(1) "3" [1]=> string(1) "4" } [184]=> array(3) { [0]=> string(1) "4" [1]=> string(1) "3" [2]=> string(1) "6" } [185]=> array(2) { [0]=> string(1) "3" [1]=> string(1) "6" } [186]=> array(2) { [0]=> string(1) "8" [1]=> string(1) "6" } [188]=> array(2) { [0]=> string(1) "3" [1]=> string(1) "6" } [189]=> array(2) { [0]=> string(1) "3" [1]=> string(1) "6" } [190]=> array(1) { [0]=> string(1) "6" } [191]=> array(4) { [0]=> string(1) "3" [1]=> string(1) "6" [2]=> string(1) "4" [3]=> string(1) "7" } } My Code $query = mysqli_query($dbConnection,"SELECT id, job_category_id FROM jobs"); while($row = mysqli_fetch_assoc($query)){ $job_id = $row['id']; $job_category_id = htmlspecialchars($row['job_category_id']); $job_category_id = unserialize(base64_decode($job_category_id)); $asscArrays = [$job_id=>$job_category_id]; // Here I am trying to achieve the array template like the I mentioned above } var_dump $asscArrays array(1) { [172]=> array(2) { [0]=> string(1) "4" [1]=> string(1) "6" } } array(1) { [174]=> array(2) { [0]=> string(1) "4" [1]=> string(1) "6" } } array(1) { [175]=> array(3) { [0]=> string(1) "4" [1]=> string(1) "3" [2]=> string(1) "6" } } array(1) { [176]=> array(2) { [0]=> string(1) "4" [1]=> string(1) "3" } } array(1) { [177]=> array(2) { [0]=> string(1) "4" [1]=> string(1) "6" } } array(1) { [181]=> array(2) { [0]=> string(1) "3" [1]=> string(1) "6" } } array(1) { [182]=> array(1) { [0]=> string(1) "7" } }