Jump to content

A Little Syntax Help


Kaizen Maven

Recommended Posts

Hi,

 

I wanted to use the id number from some data that I have in a database to print out the link, name of the link, and a description in a unordered list.  I also want to be able to put it in alphabetical order.

 

Here is the code we currently have...

 

THIS STARTS AT THE TOP OF THE PAGE, BEFORE THE DOCTYPE...

 

//bibliography
//scribner writers series
$sql1 = mysql_query('SELECT * FROM research_databases WHERE id = 254');
$sql11 = mysql_query('SELECT * FROM research_databases WHERE id = 253');

//biography
$sql2 = mysql_query('SELECT DISTINCT r.id, r.db_name, r.db_url, r.comments FROM research_databases r INNER JOIN lnk_subjects_databases l ON r.id = l.database_id WHERE l.subject_id = 49 ORDER BY db_name ASC');

//demographics/statistics
$sql3 = mysql_query('SELECT DISTINCT r.id, r.db_name, r.db_url, r.comments FROM research_databases r INNER JOIN lnk_subjects_databases l ON r.id = l.database_id WHERE l.subject_id = 56 ORDER BY db_name ASC');

//dictionaries/encyclopedias/thesauri
$sql4 = mysql_query('SELECT DISTINCT r.id, r.db_name, r.db_url, r.comments FROM research_databases r INNER JOIN lnk_subjects_databases l ON r.id = l.database_id WHERE l.subject_id = 57 ORDER BY db_name ASC');

//history/political science
$sql5 = mysql_query('SELECT DISTINCT r.id, r.db_name, r.db_url, r.comments FROM research_databases r INNER JOIN lnk_subjects_databases l ON r.id = l.database_id WHERE l.subject_id = 25 OR l.subject_id = 34 ORDER BY db_name ASC');

//access science
$sql6 = mysql_query('SELECT * FROM research_databases WHERE id = 180');

//engineering information village
$sql7 = mysql_query('SELECT * FROM research_databases WHERE id = 181');

//health & wellness
$sql8 = mysql_query('SELECT * FROM research_databases WHERE id = 182');

//accunet photo archive
$sql10 = mysql_query('SELECT * FROM research_databases WHERE id = 156');

//database
$sql12 = mysql_query('SELECT * FROM research_databases WHERE id = 414');

 

 

 

....AND THIS IS THE WHILE LOOPS THAT CURRENTLY PRINTS OUT WHAT WE HAVE...

 

	<?php

if (mysql_num_rows($sql4)>0)
{
echo "<ul>";
while ($row6 = mysql_fetch_array($sql6))
{
echo "<li><a href=\"{$row6['db_url']}\">{$row6['db_name']}</a><br>";
	if (strlen($row6['comments']) > 0) 
	{
	echo "{$row6['comments']}";
	} 
}
while ($row4 = mysql_fetch_array($sql4))
{
	echo "<li><a href=\"{$row4['db_url']}\">{$row4['db_name']}</a><br>";
	if (strlen($row4['comments']) > 0) 
	{
	echo "{$row4['comments']}";
	} 
}
?>

 

My problem is that I would like to add other links to the list (but put them in alphabetical order), but I'm not seeing how to do that with the while loop.

 

So I thought it would be easier just to call all the id with a SELECT statement and then use ORDER BY db_name ASC.  I just can't get the syntax right.

Link to comment
https://forums.phpfreaks.com/topic/102539-a-little-syntax-help/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.