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 7878445
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:39:43+00:00 2026-06-03T03:39:43+00:00

I export from MYSQL db different info that I put inside an array: $info=array(

  • 0

I export from MYSQL db different info that I put inside an array:

$info=array(
(ID,CALORIES,PROTEIN,CARBOS,FIBER),
...
);
ex: (1,270,24,12,5),(2,280,2,42,10),...

Then, further down the script, I need to get the IDs of the 3 products with the highest calories, of the 6 products with the highest result of 2xPROTEIN+3xCARBOS, etc for 5 charts.

How can I do such a sorting of the array to fill my different tables?

The function sort() only seems to work for a single-dimensioned array (if it works for my case, I don’t know what would be the syntax). It also doesn’t seem to work for my more advanced sortings (2*x+3*y)…

  • 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-03T03:39:45+00:00Added an answer on June 3, 2026 at 3:39 am

    Even tho it is not exactly what you are asking, I would highly suggest you preparing your tables in mysql (using all formulas to sort, etc.). Mysql’s main job is do various selections and sorting, I would leave the work for it. Moreover, advanced sorting in mysql is way easier than thinking of algorithms or functions in php 🙂

    SELECT * FROM `products`
    ORDER BY (2*PROTEIN+3*CARBOS) DESC
    

    Easy as that and no headaches. Apply LIMIT 3 at the end to get the top 3. Update

    SELECT * FROM `products`
    

    to your more advanced query. If having difficulties in code you may try to wrap it up as a subquery as this:

    SELECT * FROM (SELECT * FROM `products` WHERE `type`='fruit' LIMIT 6) a
    ORDER BY (2*PROTEIN+3*CARBOS) DESC LIMIT 3
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a PHP script that produces a .CSV export file from a MySQL
I'm trying to export a profile from WAS 6.1 so that I can give
I want to export data and structure from MySQL database using PHP. I know
Usually, to export CSV reports from a mysql server, I connect & run a
I am using this code to export selected data from MySQL to CSV using
I am using a PHP script to export data from MySQL into Excel. The
I have a script to export data from MYSQL to a CSV file. the
I'm trying to export some tables generated with PHP from MySQL data. I'm trying
This is output from a mysql export function. Problem is I don't know the
I want to split mysql queries from phpmyadmin export format. Each query will be

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.