0

I want to do a specific action on current's episode span but I don't understand how this works. Let me explain in examples:

enter image description here

Marked span is the episode title.

Code responsible for listing these episode titles is:

if ( ! function_exists( 'masvideos_template_loop_episode_title' ) ) {
    function masvideos_template_loop_episode_title() {
        global $episode;
        $episode_number = $episode->get_episode_number();

        if( ! empty( $episode_number ) ) {
            echo '<span class="masvideos-loop-episode__number episode__number">' . $episode_number . $keepchecked."<br />" . '</span>';
        }

        the_title( '<h3 class="masvideos-loop-episode__title  episode__title">', '</h3>' );
    }

I want to echo Yes or No next to this episode title based on row in database. I did it but I don't know how to put variable. When I just simply add my variable to this code it posts everywhere only one result f.e YES YES YES.

Getting value from DB:

$postID = get_queried_object_id();
$current_user =  wp_get_current_user();
$current= $current_user->ID ;
$sql = "SELECT lastname FROM `$current` WHERE id = '$postID'";

mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$result = mysqli_query($conn, $sql);
$row = mysqli_fetch_assoc($result);
$keepchecked= $row['status'];

My main goal is to echo YES or NO next to separate episode title.

cabrerahector
  • 3,653
  • 4
  • 16
  • 27
  • Welcome to Stack Overflow! Where in the code above are you adding the `yes` and `no`? Please edit your question to show how you are currently trying. Also, there might be a better way to get your data than using an explicit SQL query. – disinfor Sep 24 '20 at 13:25
  • I edited, thank you and sorry for trouble. And what is the better way? – Senpai 先輩 Sep 24 '20 at 13:28
  • **Warning:** You are wide open to [SQL Injections](https://stackoverflow.com/a/60496/1839439) and should use parameterized **prepared statements** instead of manually building your queries. They are provided by [PDO](https://php.net/manual/pdo.prepared-statements.php) or by [MySQLi](https://php.net/manual/mysqli.quickstart.prepared-statements.php). Never trust any kind of input! Even when your queries are executed only by trusted users, [you are still in risk of corrupting your data](http://bobby-tables.com/). [Escaping is not enough!](https://stackoverflow.com/q/5741187) – Dharman Sep 24 '20 at 13:28
  • Which kind of "loop" do you mean? – Nico Haase Sep 24 '20 at 13:28
  • @NicoHaase This function somehow makes loop, and thats why im posting my problem here. To know how it works. – Senpai 先輩 Sep 24 '20 at 13:47
  • 1
    That function doesn't make a loop, it's outputting at a specific time. That function appears to be getting called for every episode. The name of the function may be confusing you, as it's getting called IN the template loop. The function itself is doing no looping. You have your `$keepchecked` variable, but I'm not entirely sure how you are setting that variable. Where is the condition to check if that should be YES or NO? – disinfor Sep 24 '20 at 13:56
  • @disinfor Its in other file. Dependable of checkbox status it updates row in database. – Senpai 先輩 Sep 24 '20 at 14:06
  • So, how are you getting the status? Also, is this function from a plugin or theme? If so, editing this function will be overwritten on any theme/plugin updates – disinfor Sep 24 '20 at 14:37

0 Answers0