Page 3 of 3 FirstFirst 123
Results 21 to 24 of 24

Thread: Array to html table

  1. #21
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    It's an escaped backslash, but I'd think that should only apply when escaping applies to the second backslash in the first place.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  2. #22
    Join Date
    Jul 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Also, though it doesn't apply so easily in this case, you should look into foreach() loops.

    foreach($array as $item) {
    echo $item;
    }

    foreach($array as $key => $item) {
    echo $key.': '.$item;
    }
    I was wondering if you might expound on using the foreach loops to create a table.

    I would like to use:
    PHP Code:
    foreach ($search->body->Items->Item as $object) {
    echo 
    '<td>';
    echo 
    '<a href="' $object->DetailPageURL '"><img src="' $object->MediumImage->URL '" /></a><br />';
    echo 
    '<a href="' $object->DetailPageURL '">' $object->ItemAttributes->Title '</a>';
    echo 
    '</td>';

    I want to be able to dynamically change the number of rows and columns, but have the foreach loop through each item once.... I've tried several suggestions in this post, but am still having trouble with this.

    Thanks in advance for your expert help.

  3. #23
    Join Date
    Jul 2006
    Posts
    497
    Thanks
    8
    Thanked 70 Times in 70 Posts

    Default

    Please don't necromance (bring dead threads back to life). If you really need to draw attention to an old thread, link to it.

    As for your question, you'll have to use the $key => $value syntax because without an iterator (the key) you can't tell which row you should be on. Having that, you can figure whether you need to start a new row with $key % $columns == 0 (which determines whether $key is a multiple of $columns).
    -- Chris
    informal JavaScript student of Douglas Crockford
    I like wikis - a lot.

  4. #24
    Join Date
    May 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default php array into table

    I have this code that I am confused about, I can get the outpoot into an array but I cannot organize it into a table, please help

    <META HTTP-EQUIV="REFRESH" CONTENT="20">
    <?php
    $xmlUrl = "https://secure.ifbyphone.com/ibp_api.php?api_key=6a9212f2af5a0ee41df847fd59eb63acf219404c&action=report.call_detail&start_date=20110517&end_date=20201231&format=csv&date_added=1&phone_label =1&dnis=1&ani=1&call_duration=1&transfer_to_number=1&call_type_filter=All"; // XML feed file/URL
    $xmlStr = file_get_contents($xmlUrl);
    $filearray = explode("\n", $xmlStr);
    while (list($var, $val) = each($filearray)) {
    ++$var;
    $val = trim($val);
    print "Line $var: $val<br />";
    $input =
    $cols = 5;

    echo "<table border=\"5\" cellpadding=\"10\">";

    for ($i=0; $i < count($input); $i++)
    {
    echo "<tr>";
    for ($c=0; $c<$cols; $c++)
    {
    echo "<td>$input[$i]</td>";
    }
    echo "</tr>";

    }

    echo "</table>";


    }

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
  •