|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2007-10-14 11:24 UTC] wilsonwg at gmail dot com
[2007-10-14 11:26 UTC] wilsonwg at gmail dot com
[2007-10-15 10:02 UTC] jani@php.net
[2007-10-16 03:49 UTC] wilsonwg at gmail dot com
|
|||||||||||||||||||||||||||
Copyright © 2001-2026 The PHP GroupAll rights reserved. |
Last updated: Thu Feb 12 23:00:01 2026 UTC |
Description: ------------ I set up an array in the code and then use the for loop to query my database. However, the mysqli functions would not return the result values. This is the table used for the query(columns separated a comma): ------------- id, item_name ------------- 1, item_1 2, item_2 3, item_3 4, item_4 ------------- Reproduce code: --------------- $mysqli_connect =mysqli_connect("localhost", "root", "password", "myDB"); $array_items = "item_1,item_2,item_3,item_4"; $array_list = explode (",", $array_items); for ($i=0; $i<count($array_list); $i++){ $select_item = "SELECT * FROM compounds where item_name = '".$array_list[$i]."'"; echo "$select_item <p>"; $search_item_query = mysqli_query($mysqli_connect, $select_item); $result = mysqli_fetch_array($search_item_query); $id = $result['item_id']; echo "$id <p>"; } Expected result: ---------------- SELECT * FROM compounds where compound_name = 'item 1' 1 SELECT * FROM compounds where compound_name = 'item 2' 2 SELECT * FROM compounds where compound_name = 'item 3' 3 SELECT * FROM compounds where compound_name = 'item 4' 4 Actual result: -------------- SELECT * FROM compounds where compound_name = 'item 1' SELECT * FROM compounds where compound_name = 'item 2' SELECT * FROM compounds where compound_name = 'item 3' SELECT * FROM compounds where compound_name = 'item 4'