There are some topics narrowing my problem, but no one permits me to solve it.I have a csv file of terms from which i would like to count the number in a table of my db and to write the result in a new csv file.
I need to create a new array, where each key would be a term of the first array and the value would be the related number of records in my database.
Here are some examples of the input :
Lactose
Serine
And i would like to get something like this:
lactose, 25
serine, 3
So i have created an array whose values are the terms in the csv file.
Then i input the values of this array in a sql query.
And then, i have been unable to find the right way on the Internet or in the php documentation. The last line completely fails, but i tried it because it seemed to be the narrower mean to manage my task.
Could someone help me ?
Thanks in advance !
$termslist= array();
$file = fopen('fileterms.csv', 'r');
while (($line = fgetcsv($file)) !== FALSE) {
//$line is an array of the csv elements
foreach ($line AS $molindice => $molvalues)
{
if ( ! in_array( $molvalue, $termslist ) )
{array_push($termslist, $molvalues);}
}
}
fclose($file);
//print_r ($termslist);
$molnumbers = array();
foreach ($termslist as $ancientkey => $ancientvalue)
{
echo $ancientvalue;
$sql3 = "SELECT content from mols WHERE content like '% $ancientvalue %'";
$result3 = mysql_query($sql3)or die(mysql_error());
$count3 = mysql_num_rows($result3);
echo $count3;
$molnumbers [$ancientvalue['molnames']] = $count3['quantities'];
}
In the line:
You have a small error as it should be:
Then in this line:
$ancientvalue is already the value (or molname) itself and not an array by itself.
Thus the line only needs to be:
then it should put the number into the correct part of the array.
For the sql itself:
Here it seems to me that you are searching for %BLANKancientvalueBLANK% if that is not what
you want to do there but instead to look for %ancientvalue%, you should modify the line to: