1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

(For Programmers) Help with PHP Functions

Discussion in 'PHP & Perl' started by FBGuru, Nov 15, 2014.

  1. FBGuru

    FBGuru Senior Member

    Joined:
    Sep 22, 2013
    Messages:
    928
    Likes Received:
    1,171
    Location:
    Personality Type : ESTP
    Hey Guys!

    I'm building a WordPress site now and I need more functionality on it than just the vanilla WordPress features. I searched around the plugins repo and can't find anything that matches to my requirement.

    The feature I need is to pull random column data from the Wordpress Database and display it on the WordPress page and I need it done via the shortcode using php on custom page template.

    I've found some great articles like the one below to get it done.

    Code:
    http://www.whatmarkdid.com/php/displaying-data-custom-table-wordpress/
    
    Let's say I need to display a shop's address and contacts from a city, I'd have the address and contact details in the database and I need it to be displayed on whatever page I create when I add this shortcode to the page.

    [shortcode Nottingham]

    Another feature I need is to display 2 tables for each city and have some information generated dynamically next to the table.

    For ex, let's say I add [shortcode Sheffield to Liverpool] to a page; It should display data in the following format.

    ____________________________________________________________________________________________
    |Sheffield | Liverpool | The next shop is located on Liverpool, 77.1 miles from Sheffield
    |
    |Address | Address
    |##### | #####
    |##### | #####
    |Contact : x | Contact : Y
    |Staff Nos : 10 | Staff Nos : 8 | The Liverpool shop have 20% lesser staffs than the Sheffield shop.
    |___________________________________________________________________________________________

    All the data's are there in the table except the highlighted 20% and it should be generated dynamically by comparing two numbers that we have for the Sheffield and Liverpool as it'll be different for each city.

    Can anyone please shed some light on what functions should I use to make it work?

    I know I can simply pay someone to get his done but I'd really like to see it work through my hands.

    P.S. I can work with the css classes to format the data. I only need help with pulling the data from the table and generating the dynamic numbers by comparing 2 integers for the selected cities.

    Thanks a bunch in Advance! :)
     
  2. MrBlue

    MrBlue Senior Member

    Joined:
    Dec 18, 2009
    Messages:
    954
    Likes Received:
    664
    Occupation:
    Web/Bot Developer
    First you need to learn how to implement your own custom shortcodes. You can include your new shortcode functions directly in your theme's function.php file or have them separated in there own plugin.
    Code:
    http://codex.wordpress.org/Shortcode_API
    Second, you can implement your custom DB queries using the wpdb class:
    Code:
    http://codex.wordpress.org/Function_Reference/wpdb_Class
    This should give you a good starting point
     
    • Thanks Thanks x 1
  3. pr250

    pr250 Junior Member

    Joined:
    Apr 7, 2010
    Messages:
    108
    Likes Received:
    23
    3 gigs? no way man haha! Its very simple and effective, glad you decided to come here instead.
     
  4. vayacondios

    vayacondios Newbie

    Joined:
    Mar 3, 2015
    Messages:
    30
    Likes Received:
    5
    Did you get this working?