Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6905433
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:10:58+00:00 2026-05-27T08:10:58+00:00

I am running PHP with CodeIgniter. My application needs to output formatted addresses throughout

  • 0

I am running PHP with CodeIgniter. My application needs to output formatted addresses throughout the site, pulled from MySQL. In some cases, address_1 may be blank or may be filled, in other cases postcode may or may not be there, etc. I have written a helper function that formats these addresses neatly, when passed a MySQL result set.

The issue is that due to the size and complexity of the site, in some places I need to use this function with multiple addresses in the same result set, and in other places I may pass the results as $query->row('address_1') or as $row->address_1.

I have written my function out like this:

// Get every element from the MySQL Resultset       
            if(method_exists($address, 'row'))
            {
                $a['abode']         = ($address->row($prefix.'abode')         ? $address->row($prefix.'abode') : '');
                $a['building_no']   = ($address->row($prefix.'building_no')   ? $address->row($prefix.'building_no') : ''); 
                $a['building_name'] = ($address->row($prefix.'building_name') ? $address->row($prefix.'building_name') : '');
                $a['office_number'] = ($address->row($prefix.'office_number') ? $address->row($prefix.'office_number') : '');
                $a['address_1']     = ($address->row($prefix.'address_1')     ? $address->row($prefix.'address_1') : '');
                $a['address_2']     = ($address->row($prefix.'address_2')     ? $address->row($prefix.'address_2') : '');
                $a['town']          = ($address->row($prefix.'town')          ? $address->row($prefix.'town') : '');
                $a['county']        = ($address->row($prefix.'county')        ? $address->row($prefix.'county') : '');
                $a['postcode']      = ($address->row($prefix.'postcode')      ? $address->row($prefix.'postcode') : '');
                $a['country']       = ($address->row($prefix.'country')       ? $address->row($prefix.'country') : '');
            }
            else
            {
                // PHP Variable Variables
                $a['abode']         = (isset($address->{$prefix.'abode'})           ? $address->{$prefix.'abode'}: '');     
                $a['building_no']   = (isset($address->{$prefix.'building_no'})     ? $address->{$prefix.'building_no'} : '');
                $a['building_name'] = (isset($address->{$prefix.'building_name'})   ? $address->{$prefix.'building_name'} : '');
                $a['office_number'] = (isset($address->{$prefix.'office_number'})   ? $address->{$prefix.'office_number'} : '');
                $a['address_1']     = (isset($address->${$prefix.'address_1'})      ? $address->${$prefix.'address_1'} : '');
                $a['address_2']     = (isset($address->{$prefix.'address_2'})       ? $address->{$prefix.'address_2'} : ''); 
                $a['town']          = (isset($address->{$prefix.'town'})            ? $address->{$prefix.'town'} : ''); 
                $a['county']        = (isset($address->{$prefix.'county'})          ? $address->{$prefix.'county'} : ''); 
                $a['postcode']      = (isset($address->{$prefix.'postcode'})        ? $address->{$prefix.'postcode'} : ''); 
                $a['country']       = (isset($address->{$prefix.'country'})         ? $address->{$prefix.'country'} : '');
            }

As you can see I was ‘experimenting’ a little on $a['address_1'] of the else statement trying to find a combination that worked.

I am trying to get the else statement case to work, but PHP throws no errors or anything except for the $a['address_1'] line, in which it says:

Message: Undefined variable: app_address_1, Filename: helpers/address_helper.php.

My $prefix variable is set to app_, but this isn’t working. Why?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T08:10:59+00:00Added an answer on May 27, 2026 at 8:10 am

    Look carefully at that line:

    $a['address_1']     = (isset($address->${$prefix.'address_1'})      ? $address->${$prefix.'address_1'} : '');
    

    Do you see what I see?

    $address->${$prefix.'address_1'} 
    ----------^
    

    You have an excess $ in there! The error is because it’s trying to find the value of a variable named app_address_1, which is the result of $prefix.'address_1'.

    Let’s evaluate step-by-step:

    $address->${$prefix.'address_1'}
    $address->${'app_address_1'}
    $address->{$app_address_1}
    $address->{NULL}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application running with Codeigniter, its name is SAF. folder structure: /SAF/index.php
I'm running PHP on Windows/IIS. My session variables don't seem to be preserved from
I have a system running in PHP and am using CodeIgniter (if there is
I'm having some trouble prevent mod_deflate from jumping in on this scenario: user running
I'm running php/codeigniter. could somone give me any clues?
A client of mine has a site running on CodeIgniter (i did not create
I'm doing a pagination feature using Codeigniter but I think this applies to PHP/mySQL
I am creating an intranet application in php that is running on a client's
Running PHP under IIS on my Win XP Pro system. I cannot debug my
Running PHP debug session in Netbeans always opens as a new tab in browser

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.