krio Posted August 26, 2009 Share Posted August 26, 2009 Hello, I have a numbered array named $games with strings as values I have a column named games in a mysql table I want to fetch the rows where any string from $games is found in the games column so that I can iterate through them I tried to explain it as easy as possible but I'm not really good with all scripting vocab yet =/ Can someone point me in the right direction? I want to write it myself, but am really stumped. I've been reading on how to insert an array into a database, but can't figure out how to search through the database for rows meeting the array critera. Also, I understand how to use LIKE and WHERE it's just the whole array thing that throwing me off Thanks for any help Kevin Link to comment https://forums.phpfreaks.com/topic/171887-searching-database-for-array-entries/ Share on other sites More sharing options...
redarrow Posted August 26, 2009 Share Posted August 26, 2009 do you under stand this so far mate. <?php //read a array with foreach. // set the array. $a=array("a","b","c"); // get info from the array. foreach($a as $res){ // see the array. //echo $res; // see whats in the array print_r($$res); } ?> <?php // database conection. // adding info to a database from a array. // set the array. $a=array("a","b","c"); // get info from the array. foreach($a as $res){ // insert info from the array into the database // but all the array names go in the database under the //database table name, as shown. $insert_info='INSERT INTO database (table name)VALUES('$res'); $result_query=mysql_query($inset_info)or die(mysql_error()); } ?> Link to comment https://forums.phpfreaks.com/topic/171887-searching-database-for-array-entries/#findComment-906359 Share on other sites More sharing options...
krio Posted August 26, 2009 Author Share Posted August 26, 2009 thanks... i guess I was just complicating something simple.. let me know if you can think of a better way to do this.. I'm going to post the code in case someone coming later needs help function getCartContents($productsInCart) { $db = new mysqli(DB_SERVER, DB_USER, DB_PASSWORD, DB_DBNAME); foreach ($productsInCart as $id) { $query = "SELECT * FROM products WHERE id_product=$id"; $result = $db->query($query); while ($row = $result->fetch_object()) { echo "<tr>"; echo "<td>" . $row->id_product . "</td>"; echo "</tr>"; } } } Link to comment https://forums.phpfreaks.com/topic/171887-searching-database-for-array-entries/#findComment-906428 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.