php array help

They have: 426 posts

Joined: Feb 2005

I have managed to parse a file and split it up from its deliminators.

However when i reconstruct the file i want to put the first part into a table then the second and third parts into another table? Because they are all in one foreach loop, i cant just insert a table because i will get multiple table rather than multiple

here is my code:

<?php
foreach($file as $selector => $styles)
{
               
// i want this to be in one table
       
echo \"<br><br><b>\".$selector.\"</b><br><br>\";
   
   foreach(
$styles as $attribute => $value)
   {
          // and this lot in needs to be in another table
         echo
$attribute.\"<br>\";
      echo
$value
   }
}

?>

In summery this is a stylesheet so i have the $selector which is body, table etc in one tabe which i need to be linked tabs so that when clicked on will show a table with all the values for that selector?

Take the following link as an example of what i want to do, except the links are body, table etc and for now the values in the table below are in input boxes.

http://www.mywackospace.com/myspace-editor/

Greg K's picture

He has: 2,145 posts

Joined: Nov 2003

Can you give a sample of the final html code you want to given out?

-Greg

They have: 426 posts

Joined: Feb 2005

<?php
</head>
<
body>


// echo the links at the top

echo \"<table id=\\"$selector\\" align=\\"center\\" width=\\"100%\\" border=1><tr>\";
foreach(
$file as $selector => $style)
{
    echo \"<td><a href=\\"
style.php?part=$selector\\">$selector<a/></td>\";   
}
echo \"</tr></table>\";
       


// at the moment im echoing each selector 3 in all one table under another

        foreach(
$file as $selector => $styles)
        {
            echo \"<table id=\\"
$selector\\" align=\\"center\\" width=\\"100%\\" border=1><tr><td>
            echo
$selector.\"<br>\";

               foreach(
$styles as $attribute => $value)
               {
                     echo
$value.\"<br>\";
                  echo
$attribute;
            }
            echo \"</td></tr></table>\";
        }


</td><tr></table>
</body>
</html>
?>

However i just though if i can use a function to only show the table that relates to the selector passed in the URL. Check the top links.

Abhishek Reddy's picture

He has: 3,348 posts

Joined: Jul 2001

Sorry, I'm able to get a rough idea of what you're trying to do, but not enough to be helpful. Could you clearly show what kind of data you have and how you'd like that printed as markup? Smiling

He has: 11 posts

Joined: Feb 2007

Hey,

Maybe this will work for you Smiling

Not tested, just going off what I would do.

<?php
       
//Start main loop
       
foreach($file as $selector => $styles){
           
//Place your main table
           
echo \"<table id=\\"$selector\\" align=\\"center\\" width=\\"100%\\" border=1><tr><td>\";
            //Print selector
            echo
$selector;
            //Place your container table here
            echo \"<table border=0 cellpadding=2><tr>\";
                 //Inner loop
                 foreach(
$styles as $attribute => $value){
                     echo \"<td>\".
$value.\"<BR>\";
                     echo
$attribute;
                     echo \"</td>\";
                     }
              //Out of the loop - so close the container table.
              echo \"</tr></table>\";
              //Close your real table
              echo \"</td></tr></table>\";
            }
            //All done.
?>

ACJavascripts.com - Free Cut and Paste Javascripts
SimplyProgram.com - Personal Blog
CYWebmaster.com - Webmaster Forum (re-designing)

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.