Jump to content


Photo

simple PHP problem...


  • Please log in to reply
6 replies to this topic

#1 subzerostudio

subzerostudio
  • Members
  • PipPip
  • Member
  • 19 posts

Posted 11 September 2006 - 01:38 PM

I'm having an unexpected problem with PHP.. I am simply trying to assign a variable!

This line works:
echo $order->delivery['city'];
  output: BRISTOL

This line DOES NOT work:
$city = $order->delivery['city'];
echo $city;
output: NOTHING

Any ideas why?

Mike

#2 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 11 September 2006 - 01:41 PM

are you doing both of those on the same page? my question is, on the second example, are you instantiating the $order object before you try to access it?
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#3 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 11 September 2006 - 01:42 PM

You'd almost have to show us the class since that isn't standard PHP.  Normally that should work fine.

Info: PHP Manual


#4 subzerostudio

subzerostudio
  • Members
  • PipPip
  • Member
  • 19 posts

Posted 11 September 2006 - 02:00 PM

are you doing both of those on the same page? my question is, on the second example, are you instantiating the $order object before you try to access it?


Yes I am..  I can place the statements directly after each other on the same page.

The class is part of the osCommerce package.  So I don't think posting the class would be wise, as it would involve posting a few thousand lines of code of a couple of different classes..

or maybe I should? hmm..  I'm not *that* confident with PHP, but i expected that to work! ???

#5 Jenk

Jenk
  • Members
  • PipPipPip
  • Advanced Member
  • 778 posts

Posted 11 September 2006 - 02:03 PM

var_dump($city); and show us the output.

#6 subzerostudio

subzerostudio
  • Members
  • PipPip
  • Member
  • 19 posts

Posted 11 September 2006 - 02:19 PM

var_dump returns nothing as well..  Maybe if i put it in context that will help:

// class methods
    function quote($method = '') {
      global $order;

      //GET THE CITY HERE
      $city = $order->delivery['city'];

      $this->quotes = array('id' => $this->code,
                            'module' => MODULE_SHIPPING_FLAT_TEXT_TITLE,
                            'methods' => array(array('id' => $this->code,
                                                     'title' => $city,
                                                     'cost' => MODULE_SHIPPING_FLAT_COST)));

      if ($this->tax_class > 0) {
        $this->quotes['tax'] = tep_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
      }

      if (tep_not_null($this->icon)) $this->quotes['icon'] = tep_image($this->icon, $this->title);

      return $this->quotes;
    }

In the above case, 'title' is blank when returned. However if i subsitute this line:

'title' => $city,

For this:

$order->delivery['city']

It works.

??

#7 Jenk

Jenk
  • Members
  • PipPipPip
  • Advanced Member
  • 778 posts

Posted 11 September 2006 - 02:30 PM

var_dump() won't return nothing, it always returns something even if it is just NULL.

var_dump($order->delivery['city']); to see what that returns..




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users