The download policy has been changed*: no more free downloads.
Choose from bronze, silver or gold donation pack the one that is suitable for you.
Only subscribed NLSTART donators will be able to download e107 plugins. Please login or sign up.
Existing members can login and click the 'Manage your subscriptions here' link from their profile. Of course, signing up for free is still an option; so you can participate on the NLSTART member forums or subscribe to the NLSTART newsletter.

Thank you for your support.
* as per September 2013

How to retrieve variables easily

Category:   Blog | Author:   nlstart

When initially I started coding for e107, I was unaware of the power of PHP. I developed many plugins before I discovered this handy way of getting my variables.

Suppose the table design looks as follows:
Image: http://e107.webstartinternet.com/images/newspost_images/blog001.jpg

Up and until yourfirstplugin v1.4 I would use the following construction to retrieve the variables:

    // Select the single record from the database
    $sql -> db_Select("yourfirstplugin_categories", "*", "yourfirstplugin_id=".intval($_GET['yourfirstplugin_id']));
    if($row = $sql-> db_Fetch())
    {
        $yourfirstplugin_id = $row['yourfirstplugin_id'];
        $yourfirstplugin_name = $row['yourfirstplugin_name'];
        $yourfirstplugin_image_path = $row['yourfirstplugin_image_path'];
        $yourfirstplugin_test_01 = $row['yourfirstplugin_test_01'];
        $yourfirstplugin_test_02 = $row['yourfirstplugin_test_02'];
        $yourfirstplugin_test_03 = $row['yourfirstplugin_test_03'];
        $yourfirstplugin_test_04 = $row['yourfirstplugin_test_04'];
        $yourfirstplugin_test_integer = $row['yourfirstplugin_test_integer'];
        $yourfirstplugin_active_status = $row['yourfirstplugin_active_status'];
        $yourfirstplugin_order = $row['yourfirstplugin_order'];
    }

Typically, all variables are named the very same as the name of the field name of the row that is retrieved from the e107 MySQL database.
If you use variables with their original table field name, instead of having the trouble to define them all individually you can also do this:
    // Select the single record from the database
    $sql -> db_Select("yourfirstplugin_categories", "*", "yourfirstplugin_id=".intval($_GET['yourfirstplugin_id']));
    if($row = $sql-> db_Fetch())
    {
        extract($row);
    }

This second piece of coding has the exact same result as the first example, and further in the coding variables like e.g. $yourfirstplugin_name can be used. Much more efficient by using the PHP function extract on the array that is the result of db_Fetch. It saves a lot of code lines, the code is easier to read and when the table is expanded with new fields these will be taken into account as well without having to add them to the code.

printer friendly LAN_NEWS_24

Comments

Jaricanese7

Hmm interesting I didn't know this. Thanks.

You must be logged in to make comments on this site - please log in, or if you are not registered click here to signup

Your ways to participate

Thank you for using my NLSTART plugins. You can show your appreciation and support future development by donating.

Please give my plugins a maximum rating at the download details section. Or translate and create language packs, improve the Wiki, deliver code contributions, discuss and answer questions in the forums, join the test team, enter bug reports and promote the NLSTART plugins by writing about it in your blog, tweets, etc. Otherwise, purchase a virtual T-shirt image!. Alternatively, send me something from my wishlist. Or send some bananas for this code monkey.