ID: 42961
User updated by: wilsonwg at gmail dot com
Reported By: wilsonwg at gmail dot com
Status: Open
Bug Type: MySQLi related
Operating System: Windows XP SP2
PHP Version: 5.2.4
New Comment:
I forgot to add under score in my result sections.
SELECT * FROM compounds where compound_name = 'item 1'
Should be:
SELECT * FROM compounds where compound_name = 'item_1'
Previous Comments:
------------------------------------------------------------------------
[2007-10-14 11:20:13] wilsonwg at gmail dot com
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'
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=42961&edit=1