Hi,

I have a mysql database containing item names, descriptions and ids.

I've used the mysql_fetch_array to get all of this data out and stored it into arrays.

I have 3 arrays now, name, details and ids.

I want to output the data so that it shows id - name - description for each going through the array. But to do this I'd need to join the arrays.

I tried array_merge but this just left me with an output of all the ids then all the names then all the descriptions.

I want it to join the data together.

How can I do this?

Thanks a lot,

Matt

    How are you doing this? The simple practice is:

    $result=mysql_query("SELECT id,  name, description FROM  mytable");
    while($row=mysql_fetch_array($result)){
      echo "ID is $row[0], Name is $row[1], Description is $row[2]<BR>\n";
    }

      This is the code I'm using to call data from the database.

      while ($catdet = mysql_fetch_array($rows)) {
      
      $id[] = $catdet['id'];
      $name[] = $catdet['name'];
      $desc[] = $catdet['desc'];
      
      }

      Then what I want is to use these arrays on a separate script to output the id, name and description for each instead of id for all then name for all and description for all.

      If I use the foreach() command then I don't get the desired effect.

      So what can I do instead?

      Thanks,

      Matt

        Why do you even need these extra arrays?

        while($rows[]=mysql_fetch_array($result)){ 
        } 
        foreach $rows as $row{
        echo "ID is $row[0], Name is $row[1], Description is $row[2]<BR>\n"; 
        }

        OR
        in YOUR code
        elements $id[0], $name[0] and $desc[0] are all interrelated, so if you felt the need, you could say

        $i=0;
        while($i<count($id)){
           echo "$id[$i], $name[$i] and $desc[$i] ";
           $i++;
        }

          OH well that was a lot simpler than I had thought!

          Thanks a lot for the help!

            Write a Reply...