I have a list file(buy.txt). It contains some lists of words/items. For example,"Book","Table","Fan".
I want to iterate through the list,and match the words of that list with my mysql table and select the data according to the list item from the mysql data. So,if I iterate,I should get all data of three items "Book","Table","Fan" from the mysql database. I get the data. But I get data of only one word/item from the list. For example,instead of "Book","Table","Fan",I get only "Fan" data from mysql table. Other two don't show up.
Looks like,I am not iterating the list file correctly. Can anyone help to get all data(i.e "Book","Table","Fan") not just one from the mysql....?
Looks like,I am not iterating the list file correctly. Can anyone help to get all data(i.e "Book","Table","Fan") not just one from the mysql....? .And the 'buy.txt' file contains lists like this order :
Book
Table
Fan
Here is the php code...... :
<?php
$server='localhost';
$user='root';
$pass='123456';
$database='stock';
$all = array(); //let's store the data here
$link=mysqli_connect($server,$user, $pass, $database);
$file = "buy.txt";
$contents = file_get_contents($file);
$lines = explode("
", $contents);
foreach($lines as $symbol) {
$sql= "SELECT * FROM `test` WHERE `price` = '$symbol'";
$data=mysqli_query($link,$sql);
$all[] = mysqli_fetch_array($data);
} }
}
//now $all is an array and it contains all the infos, lets check it
print "<xmp>"; //<xmp> tag beautifies the output
print_r($all);
print "</xmp>";
?>
The output is :
Array ( [0] => [1] => [2] => )
Thank you.