PHP Query a table column based on value from another column in same table

PHP Query a table column based on value from another column in same table

<a href="https://i.stack.imgur.com/NNyIW.png" target="_blank"><img src="https://i.stack.imgur.com/NNyIW.png"></a>I have a database I have to query using PHP. There are 3 different columns I'm dealing with. What I have to do require a handful of steps so I'll list the steps 1 by 1...... 1) I have to go through each value in the 'nid' column. However, some of the 'nids' have duplicate value. Therefore I have to choose the 'nid' with the highest 'vid' value. 2) Once I select the 'nid' with the highest 'vid' value I then have to get the value of the 'title' column that's in the same row of the highest 'vid'. For example if I have a 'vid' of 1253 I have to select the content that's in column title that corresponds with 'vid' 1253. I have a lot of the steps. However, I'm getting stuck on once I grab the highest vid, being able to grab the content in the title column. Below is my code

I have a database I have to query using PHP. There are 3 different columns I'm dealing with. What I have to do require a handful of steps so I'll list the steps 1 by 1...... 1) I have to go through each value in the 'nid' column. However, some of the 'nids' have duplicate value. Therefore I have to choose the 'nid' with the highest 'vid' value. 2) Once I select the 'nid' with the highest 'vid' value I then have to get the value of the 'title' column that's in the same row of the highest 'vid'. For example if I have a 'vid' of 1253 I have to select the content that's in column title that corresponds with 'vid' 1253. I have a lot of the steps. However, I'm getting stuck on once I grab the highest vid, being able to grab the content in the title column. Below is my code

<?php
    // Establish all database credential variables
    $serverName = "localhost";
    $username = "root";
    $password = "root";
    $databaseName = "redesign_static";
    // Create Database Connection
    $connection = new mysqli($serverName, $username, $password, $databaseName);
    // Check Database Connection
    if ($connection->connect_error) {
      die("Connection failed:" . $connection->connect_error);
    } // line ends if statement
    $queryNodeRevision = "SELECT nid, vid, title FROM node_revision";
    // line above creates variable $queryNodeRevision > selects column "nid" from table "node_revision"
    $results = mysqli_query($connection, $queryNodeRevision) or die("Bad Query: $results");
    // line above creates variable $results > actually queries that database and passes in variable "$queryNodeRevision"
    $storeNIDAndVIDValues = []; // empty array to store max 'vid' values

for ($i = 0; $i &lt; 8000; $i++) {
  $storeNIDAndVIDValues[$i] = 0;
  // line above assigns initial 'vid'; starts at 0
}

while ($row = mysqli_fetch_array($results)) {
  $currentNID = $row['nid'];
  // line above creates variable that represents the current 'nid' of row (aka the key)
  $currentVID = $row['vid'];
  // line above creates variable that represents the current value of the 'vid' (the number you want to compare)
if ($currentVID &gt; $storeNIDAndVIDValues[$currentNID]) {
    // if the value of'$currentVID' is greater than what's stored in array '$storeNIDAndVIDValues' at current nid position
    // $storeNIDAndVIDValues[$currentNID] = goes into array $storeNIDAndVIDValues and gets the value of nid key (in this case value represents what position the nid is at)
       $storeNIDAndVIDValues[$currentNID] = $currentVID;
       // line above &gt; becomes max 'vid' at that time 
       $titleOfSelectedVID = $row['title'];
      // $row['title'] = gets the value of the current 'title'
    $queryTitle = "SELECT title FROM node_revision WHERE $currentVID ";
    // line above is query variable that targets 'title' column row that has highest 'vid' value
 } // line ends if statement
} // line closes while loop

?>

$queryTitle = "SELECT title FROM node_revision WHERE

The $queryTitle line is where I'm getting stuck. This is where I want to get the content of title column but only the title that corresponds with the highest vid.

Angular 9 Tutorial: Learn to Build a CRUD Angular App Quickly

What's new in Bootstrap 5 and when Bootstrap 5 release date?

Brave, Chrome, Firefox, Opera or Edge: Which is Better and Faster?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

MySQL Database Bootcamp: Go from SQL Beginner to Expert | Simpliv

MySQL Database Bootcamp: Go from SQL Beginner to Expert

PHP / MySQL - Count how many table in database contain Specific name

I'm building an admin to control an interactive game, and I'm using PHP/MySql to store all the data for all the rounds. Each of the tables that I want to load into the game via PHP are titled "Puzzle*" with the * being an incremental index number. There are a few other tables in my database for global game data and bonus rounds.

SQL Full Course - SQL Tutorial For Beginners - MySQL Essentials - SQL Training

This SQL Full Course video will cover all the topics of SQL starting from scratch. This video is great for beginners who want to learn SQL and for advanced people to brush up their skills.