I have a problem not displayed the name for id
data base structure for category_list
id name
1 php
2 mysql
... ...
10 html
and data base structure for entries
category_id
8
5
for the results i have this code, this script displays the ID
as a result it shows 2 , but i want the following to be displayed: mysql
but I want to show name
for this ID
, instead of ID
We need to use a join query to get the category name for given id, e.g.:
select c.name
from category_list c join entries e on c.id = e.category_id
where category_id = ?
Presumably your database query is something like this:
SELECT category_id FROM some_table
Thus, you're only selecting the ID, not the Name. You can include the Name by joining the other table. Something like this:
SELECT
category_id,
name
FROM
some_table
INNER JOIN category_list
ON some_table.category_id = category_list.id
Then your results would also include the Name value, which you could output to the page:
echo $rows['name']
Run a second query pulling name from category_list like so:
$sql = "SELECT name FROM category_list WHERE id = '$rows['category_id']';";
$result = mysqli_query($conn, $sql);
$category_name = mysqli_fetch_assoc($result);
echo $category_name['name'];
It would however be better to use a JOIN as others like David have pointed out.