Jump to content

Ordering Array


Nodral

Recommended Posts

Hi

 

I have an array which pull data from a DB (which I didn't create nor can modify)  I need to be able to export it to an excel sheet with the data in a specified order.  how do I do this?

 

eg run sql queries and end up with array which would be

[0] - a

[1] - b

[2] - c

[3] - d

[4] - e

 

how would I be able to specify the order  eg d , a, c, e, b.  to match it up with the column headers on the excel sheet?

 

To make it more of a challenge, I can't amend the column headers either.  I can only manipulate the array.

 

I will be pulling multiple arrays out and not all have all the value is them!!!  Deep Deep Joy!!!

Link to comment
Share on other sites

Essentailly you need to get your php script to output a CSV file. You can then import this csv file into open office calc or some less worthy spreadsheet program and all the values will be in there own cell accordingly.

 

implode the arrays with a comma and write each line to a file from php http://www.tizag.com/phpT/filewrite.php

 

 

You haven't given any code to look at though so...

Link to comment
Share on other sites

I've not posted any code as I haven't got any yet.  I just need a pseudo-code theory on how to do this.

 

I have 2 DB tables

 

One is the field names and information about them, the other is the content.

I pull an array from the field table which gives me the headings then pull several arrays from the content table which correspond to each individual entry. (against the field names), however the order in which the data comes out of the DB tables into the arrays is not the correct order for the output file.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.