only retrieving 1 row of data from MYSQL database

Vbshout

New Member
I am trying to input multiple pieces of data through a form and all the data will be separated by (,). I plan to use this data to find the corresponding id for further processing through an sql query.Below is the code I use.\[code\]$key_code = explode(",", $keyword); //$key_count = count($key_code); $list = "'". implode("','", $key_code) ."'"; //$row_count = ''; $sql4= "SELECT key_id FROM keyword WHERE key_code IN (".$list.")"; if(!$result4 = mysql_query($sql4, $connect)) { mysql_close($connect); $error = true; }else{ //$i = 0; while($row = mysql_fetch_array($result4)) { $keyword_id[] = $row['key_id']; //$i++; } //return $keyword_id; }\[/code\]The problem i see is that keyword_id[0] is the only element that contains any data (the data is accurate). Even if I input multiple values through the aforementioned form. I thought it might be an error in the sql but I echo'ed it and it looks like:\[code\]SELECT key_id FROM keyword WHERE key_code IN ('WED','WATER','WASTE')\[/code\]The values in the brackets are exactly what I inputted. I even tried to figure out how many rows are being returned by the query and it shows only 1. I assume something is wrong with my query but I cannot figure where. Any help will be greatly appreciated. Edit: Alright Solved the problem. Thanks to suggestions made I copied and pasted the $sql_query I had echo'ed on the website into mysql console; which resulted in only 1 row being retrieved. After taking a closer look I realized that there was a whitespace between ' and the second word. I believe the problem starts when I input the key_code as: \[quote\] WED, WATER, WASTE\[/quote\]Instead inputting it as \[quote\] WED,WATER,WASTE\[/quote\]fixes the problem. I think I should make it so that it works both ways though. Anyway, thank you for the help.
 
Back
Top