Menoospace Posted December 26, 2018 Share Posted December 26, 2018 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? Quote Link to comment https://forums.phpfreaks.com/topic/308076-looking-up-a-single-row/ Share on other sites More sharing options...
requinix Posted December 26, 2018 Share Posted December 26, 2018 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 WHERE... Quote Link to comment https://forums.phpfreaks.com/topic/308076-looking-up-a-single-row/#findComment-1563102 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.