Results 1 to 2 of 2

Thread: Help with converting array into for loop statement in php

  1. #1
    Join Date
    Nov 2006
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Help with converting array into for loop statement in php

    I have the following example of array, what I want to do it have it be store in a database and then retrieve it using "for loop" statement. How to do that?

    I know how to get the $mode array, but how to programmed the $transport array in php.

    code for $mode array:

    $sql = "select distinct model from tblcar order by car_di";
    $rssql= DBUtils::runQuery($sql,$dbhandle); --> this execute the query

    $mode = array();
    while ($rsdata = mysql_fetch_assoc($rssql)) {
    $mode[] = $rsdata['model'];}





    Array Example:

    $mode = array('air','water','land');

    $transports = array(
    'air'=>array('plane','helicopter','air-baloon'),
    'water'=>array('boat','watersky','submarine'),
    'land'=>array('motorcycle','car')
    );

    $brands = array(
    'plane'=>array('Boeing707', 'F-16', 'Columbia'),
    'helicopter'=>array('BayWatch Heli', 'Police Heli'),
    'air-baloon'=>array('Zeppelin'),
    'boat'=>array('Baywatch Safeguard Boat', 'JetBoat'),
    'watersky'=>array('JetSky','Board-Sky'),
    'submarine'=>array('K-19'),
    'motorcycle'=>array("Yamaha", "Harley Davidson", "Ducati"),
    'car'=>array("Hummer", "Renault", "Porsche")
    );

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

    Default

    You don't need a for loop if you're already using a while loop.

    I don't really understand the question.

    What should happen? You get data from the database, then you determine which part of the arrays it matches?
    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

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
  •