Results 1 to 4 of 4

Thread: php array

  1. #1
    Join Date
    Feb 2014
    Beans
    45

    php array

    how can i display the contents of this array under respective headings :
    PHP Code:
    $projects['p/z/1']['Title']=$row->Title
                 
    $projects['p/z/2']['Project date']=$row->pdate;
                 
    $projects['p/z/3']['Description']=$row->Description
    like this:
    Code:
    id                 title                       date                          desc
    p/z/1         yyyy                12/1/2104                yeee
    Last edited by lisati; February 5th, 2015 at 11:43 AM. Reason: formating

  2. #2
    Join Date
    Feb 2013
    Beans
    Hidden!

    Re: php array

    Code:
    foreach ($projects as $id => $project) {
        echo "id\t";
        foreach (array_keys($project) as $key) {
            echo "$key\t";
        }
        echo "\n";
        echo "$id\t";
        foreach ($project as $val) {
            echo "$val\t";
        }
        echo "\n";

  3. #3
    Join Date
    Nov 2012
    Location
    Halloween Town
    Beans
    Hidden!
    Distro
    Xubuntu Development Release

    Re: php array

    Moved to the Programming Talk sub-forum

  4. #4
    Join Date
    Nov 2008
    Location
    Metro Boston
    Beans
    15,576
    Distro
    Kubuntu 20.04 Focal Fossa

    Re: php array

    Do you want to display the results in a web page? If so, use an HTML table.

    First, I'm guessing your array actually has entries like this:
    Code:
    $projects['p/z/1']['Title']=$row->Title;
    $projects['p/z/1']['Project date']=$row->pdate;
    $projects['p/z/1']['Description']=$row->Description;
    So lets try:
    Code:
    <?php
    echo "<table>\n<tr><td>ID</td><td>Title</td><td>Date</td><td>Description</td></tr>\n";
    
    foreach ($projects as $key=>$data) {
         echo "<tr><td>$key</td>";
         echo "<td>".$data['Title']."</td><td>".$data['Project_date']."</td><td>".$data['Description']."</td></tr>\n";
    }
    
    echo "</table>\n";
    ?>
    If you ask for help, do not abandon your request. Please have the courtesy to check for responses and thank the people who helped you.

    Blog · Linode System Administration Guides · Android Apps for Ubuntu Users

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •