Jump to content

[SOLVED] Creating a multidimensional array from mysql data


overlordofevil

Recommended Posts

hello all,

 

I am a bit stuck on this. I am trying to pull data from a mysql table to display on a web page and I want to separate the data by the "type" of item it is.

 

So my table consists of the following elements.

 

skillName

skillType

Fcost

Tcost

Rcost

Scost

prereq

 

now what I want to do is pull the data and put it all into an array called skills, then another arrays in it called type.

 

Simple enough on what I want to do but I can't figure it out so any hints on what to look at to try and set this up.  I'm not looking for someone to do the work just point me to the right area to find the info and figure it out.

 

Thanks for any help

 

 

 

try

<?php    
$sql = "SELECT skillName, skillType, Fcost, Tcost, Rcost, Scost, prereq
        FROM tablename";
$res = mysql_query($sql);
while ($row = mysql_fetch_assoc($res))
{
    $skills[$row['skillName']][] = $row;
    $types[$row['skillType']][] = $row; 
} 
?>

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.