Jump to content

Looking up a single row

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.

UID    [pk]
Category  [fk]

UID  [pk]

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?

Share this post

Link to post
Share on other sites

It would be better if you could get the log entry and category name at the same time, right?

SELECT e.*, c.CategoryName
FROM tblLogEntries e
JOIN tblCategories c ON e.Category = c.UID


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


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.