Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8268377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T05:51:56+00:00 2026-06-08T05:51:56+00:00

There are some topics narrowing my problem, but no one permits me to solve

  • 0

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'];
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T05:51:59+00:00Added an answer on June 8, 2026 at 5:51 am

    In the line:

    if ( ! in_array( $molvalue, $termslist ) )
    

    You have a small error as it should be:

    if ( ! in_array( $molvalues, $termslist ) )
    

    Then in this line:

    $molnumbers [$ancientvalue['molnames']] = $count3['quantities'];
    

    $ancientvalue is already the value (or molname) itself and not an array by itself.
    Thus the line only needs to be:

        $molnumbers [$ancientvalue] = $count3['quantities'];
    

    then it should put the number into the correct part of the array.
    For the sql itself:

    $sql3 = "SELECT content from mols WHERE content like '% $ancientvalue %'";
    

    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:

    $sql3 = 'SELECT content from mols WHERE content like \'%'.$ancientvalue.'%\'';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I saw some topics about this, but the problem is that the solutions required
I know that there have been plenty of topics describing this topic but I
I have a database which contains some topics each with a title and some
I need some tutorials or samples which cover the following topics, does anyone have
There are some similar topics in stackoverflow, but still I didn't succeed to rename
I know there are some topics about this here already but I could not
I have seen the same topics here and some topics on other sites, but
i cam across some older topics about this but since there is a lot
I know there are already some posts about this topic, but I cannot find
First of all, I know that there are some topics about icon packs here

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.