Below i made a MySQL Table in my phpmyadmin.
I want to print on my php page the cat_name of a cat_id of my choosing. What code would i use exactly for that? I am looking at this guide here But i am not figuring it out completely maybe someone can guide me in the right direction?
You need to use WHERE
clause for this. Basically what it does is it filters the records you want.
SELECT Cat_Name
FROM category
WHERE CAt_ID = 1 -- place the value of your desired category id
is that so complicate??
$result = mysql_query("SELECT * FROM yourtablename WHERE cat_id='yourcatidhere' ");
while($row = mysql_fetch_array($result))
{
print_r($row);
}
<?php
if(isset($_POST['submit'])) {
$cat_id = isset($_POST['cat_id'])? (int)$_POST['cat_id']: 0;
$query = mysql_query("SELECT cat_name FROM category WHERE cat_id = '$cat_id'");
$cat_name = mysql_fetch_row($query);
}
?>
<form method="POST" action="">
Category ID: <input type="text" name="cat_id" />
<input type="submit" name="submit" value="Get Category Name" />
</form>
<?php echo isset($cat_name)? $cat_name: ''; ?>