0

I'm trying to create a table filled with data from database so basically I have to use php for that reason. however I couldn't find a way to implement my code in custom HTML. most of my php code shows up not executed, it's like I've added php into text format. here's an image explaining my situation.

enter image description here

.

should I change the theme I'm working with or is it something I don't know? I'm new to this so please help me. thanks.

  • 1
    When you say "in custom HTML" you mean you're pasting PHP into the admin pages? No, if you want to write PHP you'll need to put it in a template in your theme or in a child theme. You can define templates for individual pages, by ID or by slug. – Rup Jan 2 at 16:27
0

Welcome to WPSE.

First you need to sort out, WHERE you want to execude your php code.

Frontend? Backend? Login Page?

After that:

In case it is backend related, add your code via a filter in your functions.php of your theme.

In case it is frontend code, add it

1) either via a filter

2) or to your theme's template file.

From what I can see of your code, you need to know the "WP_Query" object and some awareness of where to put your code. The WP_Query Object is an internal WordPress function, which makes it easier to query the database and get the results.

To add some PHP code to your backend via a filter you can do:

<?php

     function wpse_filterFunction($args){
         //
         // Do something with the $args/whatever is being passed in here.
         // some of your code..
         return $args
     }
     add_filter('NAME_OF_THE_FILTER','wpse_filterFunction');

NAME_OF_THE_FILTER references to the place/where you might want to add your code. Please google for WordPress filters to learn more.

In case you want to output your code on the frontend, just copy a template file like "page.php" rename to "page-mycustomwhatevername.php" and add the code to that file, select it in the backend for that page. That way it will be output on the frontend.

|improve this answer|||||
0

Based on the image you posted, I'd say the problem is just a syntax error as the comment is on the same line as the start of your while loop. So you're basically commenting out the start of the loop resulting in weird output. So just reformat your code and you should be good to go, something along these lines

if ($result->num_rows > 0) {
  // output data of each row
  // your while loop code
} else {
  // your else code
}

P.s. it is recommended to include the code you're using in your question as it makes it easier for others to spot potential problems instead of just depending on a screenshot.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.