SitePoint Sponsor

User Tag List

Results 1 to 17 of 17

Threaded View

  1. #1
    SitePoint Evangelist GeekSupport's Avatar
    Join Date
    May 2002
    Location
    Southern California
    Posts
    408
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    (help) Creating an Array of Objects

    How do I create an array of objects? I'm quite new to OOP, please bear with me.

    I have a car rental database (mysql) that retrieves all availiable cars. In each result row, it has: make, model, trans, doors, color, etc.

    The Car class has getters and setters for these attributes. Before displaying all available cars, it will save each individual car into $myCar[]. However, whenever the script runs, i get this error:
    Code:
    small text
    Code:
    Warning: Cannot use a scalar value as an array in /hsphere/local/home/cis235/reservation/index.php on line 46
     
    Fatal error: Call to a member function on a non-object in /hsphere/local/home/cis235/reservation/index.php on line 46


    Here is my code snippet

    Code:
    small text here
    Code:
    function showCars()
    {
    require('includes/car_class.inc.php');
    $myCar = new Car();
     
    # Get list of available cars
    $SQL = 'SELECT DISTINCT 
    	`car_description`.`car_make`,
    	`car_description`.`car_model`,
    	`car_description`.`car_trans`,
    	`car_description`.`car_doors`,
    	`car_description`.`car_color`,
    	`car_description`.`car_type`,
    	`car_description`.`car_year`,
    	`car`.`car_vin`
    FROM
    	`car`
    	INNER JOIN `car_linker` ON (`car`.`car_vin` = `car_linker`.`car_vin`)
    	INNER JOIN `car_description` ON (`car_linker`.`car_id` = `car_description`.`car_id`)
    WHERE
    	(`car`.`available` = 1)
    ORDER BY
    	`car_description`.`car_make`';
     
    $result = mysql_query($SQL);
     
    while ($rowInfo = mysql_fetch_assoc($result))
    { 
    	 $myCar[]->setMake($rowInfo['car_make']);
    	 $myCar[]->setModel($rowInfo['car_model']);
    	 $myCar[]->setTrans($rowInfo['car_trans']);
    	 $myCar[]->setDoors($rowInfo['car_doors']);
    	 $myCar[]->setColor($rowInfo['car_color']);
    	 $myCar[]->setType($rowInfo['car_type']);
    	 $myCar[]->setYear($rowInfo['car_year']);
    	 $myCar[]->setVin($rowInfo['car_vin']); 
    }
    }


    AHHH!!! Finally. after 34 trys, vB 3.0b isn't adding font tags in my php snippet. Nevermind...only a few font tags...good enough. How do you disable the V_BULLETIN_BS_TAGS?

    NO WORKING EDIT AND NO PHP TAGS MAKE GEEKSUPPORT GO SOMETHING SOMETHING....

    Sorry for not using the php vb tags but, i can't figure out how to increase the text w/o adding all those font tags.
    Last edited by GeekSupport; Mar 6, 2003 at 03:01.


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
  •