Jump to content

Using Foreach to loop data in array to display it on a table with 5 columns


sniesler08

Recommended Posts

Now I am stumped this is far any help would be awesome

 

This is what I have gotten so far, this is what it does right now is display each Header above each bit of data and spans across 5 columns for each foreach loop but what i am trying to understand here is i am trying to get the header then the data then another header and data and so on but only about 4 or number of my choosing grouped header/data but select how many are in each column up to 5 columns. Heres an example of what i am trying to do.

 

 

A

D

K

N

S

AlexandraHeadlands

DickyBeach

KingsBeach

Nambour

SandstonePoint

Aroona

Diddillibah

KielMountain

Ninderry

ShellyBeach

[/td]

Doonan

KundaPark

NoosaHeads

SippyDowns

B

Dulong

Kuluin

Ningi

SunriseBeach

Beachmere

DeceptionBay

Kilcoy

NorthArm

SunshineBeach

BanksiaBeach

Noosaville

Scarborough

Beerburrum

E

L

Beerwah

EerwahVale

Landsborough

O

T

Bellara

Elimbah

Tanawha

Bellmere

Eudlo

M

P

TowenMountain

Birtinya

Eumundi

Maleny

Petrie

Tewantin

Bongaree

Mapleton

Palmview

TwinWaters

Bokarina

F

Marcoola

Palmwoods

BribieIslandArea

Flaxton

MarcusBeach

Parklands

U

Buddina

ForestGlen

MaroochyRiver

Parrearra

UpperCaboolture

Burnside

Maroochydore

PeregianBeach

Buderim

G

Minyama

Pinbarren

V

Burpengary

GlassHouseMountains

MoffatBeach

PointArkwright

Valdora

BliBli

Mons

PelicanWaters

H

Montville

PacificParadise

W

C

Highworth

Mooloolaba

WeybaDowns

CoolumBeach

Hunchy

Mooloolah

Q

Warana

Caboolture

MountainCreek

WestWoombye

CabooltureSouth

I

MountCoolum

R

Woombye

Caloundra

ImageFlat

Morayfield

Rosemount

Woorim

CastawaysBeach

Mudjimba

Redcliffe

WamuranBasin

Chevallum

J

Woodford

CoesCreek

WoodyPoint

Cooroy

Wamuran

Currimundi

Wurtulla

X

Y

 

YandinaCreek

 

Yandina

 

 

Z

[td]

 

 

 

 

This is an example of how it is being displayed right now

 

A

Airlie Beach  Andergrove  Alexandra  Armstrong Beach

Alligator Creek

B

Bucasia  Blacks Beach  Beaconsfield  Bakers Creek 

Balberra  Bloomsbury  Breadalbane  Ball Bay  Belmunda

C

Cannonvale  Calen  Crystal Brook  Cremorne 

Chelona  Campwin Beach  Cape Hillsborough 

Conway

 

 

 

Heres The Code i have so far.

 

 

<?php
  $file = "widget.csv";
@$fp = fopen($file, "r") or die("Could not open file for reading");
$outputArray = array();
$count = 0;

while(($shop = fgetcsv($fp, 1000, ",")) !== FALSE)
{
    $outputArray[array_shift($shop)] =  array_filter($shop);
}

echo "<table>";
foreach ($outputArray as $alphabetical=>$value){
    echo "<th colspan='4'><b>" . $alphabetical ."</b></th>";
    echo "<tr>";
foreach ($value as $key){
	$afterkey=preg_replace('/\s+/','-',$key);
    if ($count == 4){
    echo '</tr><tr><td><a href="map.php?mapaddress='.$afterkey.'-qld&mapname='.$key.'">'.$key.'</a></td>';
    $count = 0;
    }else{
    echo '<td><a href="map.php?mapaddress='.$afterkey.'-qld&mapname='.$key.'">'.$key.'</a></td>';
    }
$count++;    
}
    echo "</tr>";
$count = 0;
}
    echo "</table>";

    echo "\n<br />";

?>

 

 

 

Heres my CSV File:

 

 

A,Airlie Beach,Andergrove,Alexandra,Armstrong Beach,Alligator Creek,,,,,,,,,,,,,,

B,Bucasia,Blacks Beach,Beaconsfield,Bakers Creek,Balberra,Bloomsbury,Breadalbane,Ball Bay,Belmunda,,,,,,,,,,

C,Cannonvale,Calen,Crystal Brook,Cremorne,Chelona,Campwin Beach,Cape Hillsborough,Conway,,,,,,,,,,,

D,Dows Creek,Dumbleton,Dolphin Heads,,,,,,,,,,,,,,,,

E,Eimeo,Eton,Erakala,,,,,,,,,,,,,,,,

F,Foulden,Foxdale,Flametree,Farleigh,Freshwater Point,,,,,,,,,,,,,,

G,Glen Isla,Glenella,,,,,,,,,,,,,,,,,

H,Homebush,Hampden,,,,,,,,,,,,,,,,,

I,,,,,,,,,,,,,,,,,,,

J,Jubilee Pocket,,,,,,,,,,,,,,,,,,

K,Kinchant Dam,Kolijo,Koumala,Kuttabul,,,,,,,,,,,,,,,

L,Laguna Quays,,,,,,,,,,,,,,,,,,

M,McEwens Beach,Mackay,Mackay Harbour,Mandalay,Marian,Mia Mia,Middlemount,Midge Point,Mirani,Moranbah,Mount Charlton,Mount Jukes,Mount Julian,Mount Marlow,Mount Martin,Mount Ossa,Mount Pelion,Mount Pleasant,Mount Rooper

N,Narpi,Nebo,Nindaroo,North Eton,,,,,,,,,,,,,,,

O,Oakenden,Ooralea,,,,,,,,,,,,,,,,,

P,Palmyra,Paget,Pindi Pindi,Pinevale,Pioneer Valley,Pleystowe,Preston,Proserpine,,,,,,,,,,,

Q,,,,,,,,,,,,,,,,,,,

R,Racecourse,Richmond,Riordanvale,Rosella,Rural View,,,,,,,,,,,,,,

S,St Helens Beach,Sandiford,Sarina,Seaforth,Slade Point,Shoal Point,Shute Harbour,Shutehaven,Strathdickie,Sugarloaf,Sunnyside,,,,,,,,

T,Te Kowai,The Leap,,,,,,,,,,,,,,,,,

U,,,,,,,,,,,,,,,,,,,

V,Victoria Plains,,,,,,,,,,,,,,,,,,

W,Wagoora,Walkerston,Woodwark,,,,,,,,,,,,,,,,

X,,,,,,,,,,,,,,,,,,,

Y,Yalboroo,,,,,,,,,,,,,,,,,,

Z,,,,,,,,,,,,,,,,,,,

Link to comment
Share on other sites

This is what I have gotten so far, this is what it does right now is display each Header above each bit of data and spans across 5 columns for each foreach loop but what i am trying to understand here is i am trying to get the header then the data then another header and data and so on but only about 4 or number of my choosing grouped header/data but select how many are in each column up to 5 columns. Heres an example of what i am trying to do.

 

Seriously, did you actually make an attempt to proof read what you wrote there?  Try actual sentences, punctuation and reading what you wrote out loud if you're unclear.

 

Do an html only mockup before you try to get it working in code.

 

-Tables can have nested tables. 

 

-If each section is a table with a th and one td per tr, you will have the basis for the section for one letter.  You know how to do this already.

 

-Your outer container table simply needs to have one row with 5

 

Once you understand the html, figuring out how to output it correctly should be pretty easy to accomplish.

 

 

 

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.