Good morning from Palo Alto, California, where I’m stuck on a problem. My mySQL database has two tables: “names” and “descriptions”. In the names table, each record has three fields: id, which is auto-generated and is the key; star; and name. Star is binary – there’s either a y or a blank.
The second table, “descriptions,” also has three fields: id, which is auto-generated and is the key; link; and description. Link is simply the manually-entered id from the “names” table that connects a record from the description table with a a record from the names table. Some names have descriptions, but most don’t. A name with a description may or may not have a star. A name with a star always has a description.
I want to generate a list that orders the names as follows:
-
First, names with a star, in alphabetical order, each with star.jpg next to it.
-
Second, names with no star, but a description, in alphabetical order.
-
Third, names with neither a star nor a description, in alphabetical order.
I’m able to handle 1 and 3, but not 2. I just can’t figure out how to call the description table to order records from the names table. Here’s what I have so far:
<?
mysql_connect(“ipaddress”, “username”, “password”) or die(mysql_error());
@mysql_select_db(“databasename”) or die( “Unable to select database”);
$query=“SELECT * FROM name ORDER BY star DESC, name”;
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
$i=0;
while ($i < $num) {
$id=mysql_result($result,$i,“id”);
$star=mysql_result($result,$i,“star”);
$name=mysql_result($result,$i,“name”);
?>
<?
if ($star == ‘’) {
echo “”;?><? }
else {
?>
<img src=“star.jpg”>
<?
}
?>
<? echo “$name”;?><br><br>
<?
++$i;
}
?>
Please note that, for a variety of reasons, the two tables need to remain separate. Please, do you have any suggestions? Thank you!