Page 1 of 1

Retrieving index columns from a table

Posted: Mon Jan 31, 2011 11:27 am
by Cigana
Hello, I am trying to figure out how to automatically retrieve values from a table which are numbered in an index fashion.

Each of these column headings begin as Value then followed by an index so you have:

Country1, Country2, Country3 ....through to Country50.

I would like to have a more automatic way to retrieve these values rather than stick to the

$result .= "<th>$Country1</th>";

But as I have no experience in PHP coding I can only work out the logic. Also not all of these values are populated, so they do not require to be printed if that's the case, so the results could be

<th>Value of Country1</th>
<th>Value of Country2</th>
<th>Value of Country3</th>
<th>Value of Country8</th>
<th>Value of Country24</th>
<th>Value of Country30</th>

I know that I need some sort of array range and a loop to count through to the records, what is the best way of doing this?

Thanks a lot!

Re: Retrieving index columns from a table

Posted: Mon Jan 31, 2011 12:43 pm
by AbraCadaver
Show your database query code.

Re: Retrieving index columns from a table

Posted: Tue Feb 01, 2011 3:48 am
by Cigana
It's not a database but an excel sheet. I also forgot to mention that each <th> must also contain the id of the country which will eventually be better converted as an array i.e.

<th id="Country30">data for country30</th>
<th id="Country48">data for country 48</th>
<th id="Country49">data for country 49</th>

Does that make sense?