• [ Moderator note: moved to Developing with WordPress. ]

    Hi
    I am new to WordPress and getting to understand the concepts. I have developed websites before but in other environments/ languages.
    What I want to do, just to see how it works, is add a MySQL query to a new page on my site – which I will delete once I get it working.
    I have defined a custom table, and tested the simple query in myPhpAdmin, and that works fine.
    I intend to learn how to add functions etc to the server over the next few weeks/months, so I can write my own plugins, and have a few books I’ve been going through etc.

    However, for today I just want to know if.how it is possible to add a SQL query to a page, something like this:

    SELECT * FROM wp_myTable WHERE name LIKE ‘%joe%’

    I don’t even know how to phrase the question right… is it possible, without creating a file and uploading it to the server, to add some code with the above query to display data on a wordpress page?
    I just want to see some query results on a page and have fun before deleting it all and progressing into proper development.
    In other words, can I add some SQL/php code to a page just from the WordPress backend?

    As I said, I don’t know enough to be able to even ask the question properly – there are still a lot of concepts that I haven’t absorbed yet.
    Hopefully you can understand what I am asking.

    Regards

    Garrett

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hi,
    I have same issue here. Done just pure PHP before, and now started to learn WP.
    For now i have used Insert PHP-plugin in pages to do code as “Old way”, but there has been conflicts with some of other plugins.
    Looking forward if someone could guide this in simple way.

    Br,

    -matti

    Thread Starter GarrettB

    (@garrettb)

    Essentially I am looking for a quick fox to see how things look, before I head on in to the deeper world of proper code development.

    When I look at the backend, and select a page, there are two tabs allowing content to be added to a page – the Visual tab and th eText tab.
    I assume HTML code can be added via the Text tab.
    Can I add php code there?
    If so can I add a php code to query a table and display the results?
    That’s all I want to know fo rnow.
    I am guessing it is not a safe way to code – and it certainly isn’t a long term solution, but just for kicks now…
    I have searched for two days now on the subject and still haven’t found what I’m looking for (just like Bono)

    Garrett

    Here is one example what i use for query sub-sites in my WP Multisite environment page. It uses native WP functions and basic PHP-code for displaying results.
    But i like to find simple function for query anything i like to see from database.

    [insert_php]
    $subsites = get_sites();
    echo'<form name=”form”><select class=”pagetitle” name=”jumpit” style=”border:none; width:100%; padding:8px 8px 8px 10px;” onchange=”document.location.href=this.value”>
    <option>TEAMSINNET SIVUSTOT</option>’;
    foreach( $subsites as $subsite ) {
    $subsite_id = get_object_vars($subsite)[“blog_id”];
    $subsite_name = get_blog_details($subsite_id)->blogname;
    $subsite_url = get_blog_details($subsite_id)->siteurl;
    if($subsite_name<>”TeamsInNet Merlin”) {
    echo ‘<option value=”‘ . $subsite_url . ‘” title=”ID ‘ . $subsite_id . ‘”>’ . $subsite_name . ‘</option>’;
    } }
    echo'</select></form>’;
    [/insert_php]

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    @masimies, Please create a new thread to discuss your issue: https://ww.wp.xz.cn/support/forum/how-to-and-troubleshooting#new-post

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    When I look at the backend, and select a page, there are two tabs allowing content to be added to a page – the Visual tab and th eText tab.
    I assume HTML code can be added via the Text tab.
    Can I add php code there?

    No.

    If so can I add a php code to query a table and display the results?

    You need to do this in the template file. Which theme are you using? Make sure you create a Child Theme before carrying out any modifications.
    https://codex.ww.wp.xz.cn/Child_Themes

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘DB select query’ is closed to new replies.