user72261 user72261 - 4 years ago 84
SQL Question

Show links in webpage from database with selected values

I have a data base with a tbl in it called : tbl_admin_link in this table there are hundreds of links that are set out like so:

uri | id | title | category | status


How do I get only links with a set category value?

The category value is a number from 1 to 19 in my case the ones I need are links with only the category value of 7.

I can get all the links in the admin table using this code but can figure out the rest:

$getLinks=mysql_query("SELECT * FROM `tbl_admin_link`");
$cnt=0;
while($row=mysql_fetch_array($getLinks))
{
$cnt++;
?>
<td align="center" class="homeButtonsNew" onclick="javascript:window.location.href ='<?=$row['uri'];?>';">
<img width="24" height="24" src="info.png" hspace="2" style="margin-bottom: 3px;"> <br><?=$row['title'];?></td>
<?
if($cnt%3==0)
{
?>
</tr>
<tr>
<?
$cnt=0;
}

}
?>

Answer Source

I assume you just don't know mysql syntax or is there something more to it? If it is just to filter all links which have category 7 this is the right query.

If category is a number field in the database:

SELECT * FROM tbl_admin_link WHERE category=7

If category is a string field in the database:

SELECT * FROM tbl_admin_link WHERE category='7'

And lastly, do check how many records are there with category 7, if there is none then you will just get a blank page.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download