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?

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


Link to post
Share on other sites
This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • 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.