Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2004
    Posts
    1,774
    Plugin Contributions
    14

    Default Code question: set variable = to logic?

    I dont really know how to explain it better, but basically i was wondering if there was some proper way to set a variable to the result of a if statement:

    PHP Code:
    $blahblah = (if ($orders_history->RecordCount() > 0) {
          while (!
    $orders_history->EOF) {
            echo 
    '          <tr>' "\n" .
                 
    '            <td class="smallText" align="center">' zen_datetime_short($orders_history->fields['date_added']) . '</td>' "\n" .
                 
    '            <td class="smallText" align="center">';
            if (
    $orders_history->fields['customer_notified'] == '1') {
              echo 
    zen_image(DIR_WS_ICONS 'tick.gif'ICON_TICK) . "</td>\n";
            } else {
              echo 
    zen_image(DIR_WS_ICONS 'cross.gif'ICON_CROSS) . "</td>\n";
            }
            echo 
    '            <td class="smallText">' $orders_status_array[$orders_history->fields['orders_status_id']] . '</td>' "\n";
            echo 
    '            <td class="smallText">' nl2br(zen_db_output($orders_history->fields['comments'])) . '&nbsp;</td>' "\n" .
                 
    '          </tr>' "\n";
            
    $orders_history->MoveNext();
          }
        } else {
            echo 
    '          <tr>' "\n" .
                 
    '            <td class="smallText" colspan="5">' TEXT_NO_ORDER_HISTORY '</td>' "\n" .
                 
    '          </tr>' "\n";
        }
    ); 
    I'd like blahblah to equal the resulting table of the logic inside of it. Obviously the way I have it shown doesn't work. but how could i get the resulting created table structure as a string for my variable?

  2. #2
    Join Date
    Sep 2003
    Location
    Ohio
    Posts
    69,402
    Plugin Contributions
    6

    Default Re: Code question: set variable = to logic?

    If you are trying to make $blah contain all the echo statements ...

    Set $blah to blank ...

    Then on each echo that you have you would use:

    PHP Code:
    $blah .=  '          <tr>' "\n" .
                 
    '            <td class="smallText" align="center">' zen_datetime_short($orders_history->fields['date_added']) . '</td>' "\n" .
                 
    '            <td class="smallText" align="center">'
    Notice the echo is removed and the .= is there ... this means to keep adding on to $blah

    So it starts out with
    $blah = '';

    Then you build the content only if you enter the IF statement because the record count is > 0 ... otherwise at the end of the IF $blah will still be blank or contain nothing ...
    PHP Code:
    if ($orders_history->RecordCount() > 0) { 
    Linda McGrath
    If you have to think ... you haven't been zenned ...

    Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!

    Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today: v1.5.5]
    Officially PayPal-Certified! Just click here

    Try our Zen Cart Recommended Services - Hosting, Payment and more ...
    Signup for our Announcements Forums to stay up to date on important changes and updates!

  3. #3
    Join Date
    Feb 2004
    Posts
    1,774
    Plugin Contributions
    14

    Default Re: Code question: set variable = to logic?

    Well what I'm trying to do is get the table structure.. not so much the echos, but I need to let the code execute to go through the WHILE loop and pull data from the database. For each new line of data, it adds a <tr><td>. Since this data changes for each order, I need to have it all execute first, then get that data and then use

    so now $blahblah actually equals '<tr><td>1</td><td>2</td></tr>';

    PHP Code:
    $contents[] = array('text' => $blahblah); 
    so that it appends the table to the contents array. I will try the .= method to add to the blah blah using normal logic parsing tho.

 

 

Similar Threads

  1. v151 php help please - set variable based on items on order
    By philip937 in forum General Questions
    Replies: 11
    Last Post: 13 Aug 2014, 07:27 PM
  2. product ticket event set avail but diff variable
    By charliepingpong in forum Setting Up Categories, Products, Attributes
    Replies: 11
    Last Post: 1 Jun 2011, 03:26 AM
  3. I want to set my own cookie or session variable
    By rweeks in forum General Questions
    Replies: 7
    Last Post: 20 Feb 2010, 11:44 AM
  4. Pass variable from link to Discount Coupon Code
    By MrForce in forum General Questions
    Replies: 0
    Last Post: 17 Apr 2008, 06:07 AM
  5. Where can I set a new variable?
    By Dan Ballance in forum Templates, Stylesheets, Page Layout
    Replies: 1
    Last Post: 10 Jun 2007, 11:30 AM

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
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR