SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Jul 2007
    Location
    Kansas City
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Need help - Problem with output of array using a for loop index

    I am having a problem with output of array using a for loop index. I am stumped. Don't believe it's a difficult task can someone help. My code is displayed below. var_dump results are showing at the bottom.

    <ul>
    <?php
    // get companies

    $companies_array = $hd->view_company($db);
    //var_dump($companies_array);


    $count = count($companies_array);
    for($i = 0; $i < $count ; $i++) {

    echo "<li><a href='company.php?company_id=".$company_id[$i]."'>".$company_name[$i]."</a></li>";
    }
    ?>
    </ul>

    //var_dump($companies_array);
    array(6) { [0]=> array(4) { [0]=> string(1) "1" ["company_id"]=> string(1) "1" [1]=> string(18) "hortondesign, inc." ["company_name"]=> string(18) "hortondesign, inc." } [1]=> array(4) { [0]=> string(1) "2" ["company_id"]=> string(1) "2" [1]=> string(17) "HEMCO Corporation" ["company_name"]=> string(17) "HEMCO Corporation" } [2]=> array(4) { [0]=> string(1) "3" ["company_id"]=> string(1) "3" [1]=> string(9) "VML, Inc." ["company_name"]=> string(9) "VML, Inc." } [3]=> array(4) { [0]=> string(1) "4" ["company_id"]=> string(1) "4" [1]=> string(21) "Plattform Advertising" ["company_name"]=> string(21) "Plattform Advertising" } [4]=> array(4) { [0]=> string(1) "5" ["company_id"]=> string(1) "5" [1]=> string(14) "Hantover, Inc." ["company_name"]=> string(14) "Hantover, Inc." } [5]=> array(4) { [0]=> string(1) "6" ["company_id"]=> string(1) "6" [1]=> string(13) "JUST Peanuts!" ["company_name"]=> string(13) "JUST Peanuts!" } }

  2. #2
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    4,827
    Mentioned
    142 Post(s)
    Tagged
    0 Thread(s)
    I think you want:
    PHP Code:
    echo "<li><a href='company.php?company_id=".$companies_array[$i]['company_id']."'>".$companies_array[$i]['company_name']."</a></li>"
    Be sure to congratulate xMog on earning April's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes

  3. #3
    SitePoint Member
    Join Date
    Jul 2007
    Location
    Kansas City
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That resolved it. Thanks for the quick response.


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
  •