Jump to content

Looking up a single row


Menoospace

Recommended Posts

I'm working on a really simple database that has log entries and for each log entry, an associated category.  The log entry table contains a number that is a foreign key.  Another table "tblCategories" contains the primary key which is numeric.  The row with the corresponding foreign key to primary key match has the actual category name.

tblLogEntries
=================================
UID    [pk]
Date
Description
Category  [fk]

tblCategories
================
UID  [pk]
CategoryName

I've normalized the database.  However, this means I would need to do an SQL query to find the CategoryName entry for a specific Log Entry. 

I have found various examples online of how to perform a query and how to iterate through the dataset.  https://www.w3schools.com/php/php_mysql_select.asp

From the link above, the relevant code is:

if (mysqli_num_rows($result) > 0) {
    // output data of each row
    while($row = mysqli_fetch_assoc($result)) {
        echo "id: " . $row["id"]. " - Name: " . $row["firstname"]. " " . $row["lastname"]. "<br>";
    }
} else {

However, I really only need the results of row #1.  How do I get just one column's contents from the first row returned in the query?

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.