Ask a Question related to Macromedia Dynamic HTML, Design and Development.
-
jmack159 #1
sort my results in php w/ mysql
hey there,
so i have a table in php that outputs the title, author, abstract and other
info from scolarly papers into. it pulls the data from a mysql database. at the
top of the table, i have two headers for title and author. i want to turn these
headers into links that when clicked will sort the data based on the appropiate
information. so, when the page loads, all the papers load in defualt order,
when the header "title" is clicked, the papers will appear in alph. order based
on titles, when it is clicked again, the papers appear in inverseorder. similar
for the header "author" when clicked --> sort based on order, clicked again -->
sort inverse order. any ideas? im new to php and mysql. thanks! here is my code:
<div id="main">
<br />
<table width="607" border="0" cellpadding="2" cellspacing="2">
<tr>
<th></th>
<th>Title</th>
<th>Author</th>
</tr>
<?
include 'library/connection.php';
mysql_connect($host,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM paper";
$result=mysql_query($query);
$num=mysql_numrows($result);
$i=0;
while ($i < $num) {
$title=mysql_result($result,$i,"title");
$author=mysql_result($result, $i, "author");
$content=mysql_result($result, $i, "content");
$type=mysql_result($result, $i, "type");
$size=mysql_result($result, $i, "size");
$abstract=mysql_result($result, $i, "abstract");
$is_even = ($i % 2);
If ($is_even == 0)
{
echo "<tr class = \"block\">";
}
else {echo "<tr>";}
$author_search =
"http://scholar.google.com/scholar?hl=en&lr=&sa=G&oi=qs&q=author:".$author
?>
<td rowspan="2"><div align="center"><a href="<? echo "$content"; ?>"><img
src="images/icon_pdf.gif" alt="download pdf" /></a><br />
(<? echo "$size"; ?>Mb)</div></td>
<td><a href="<? echo "$content"; ?>"><? echo "$title"; ?></a></td>
<td><a href="<? echo "$author_search"; ?>" title="click to Google this author"</tr>><? echo "$author"; ?></a></td>
<?
If ($is_even == 0)
{
echo "<tr class = \"block\">";
}
else {echo "<tr>";}
?>
<td colspan="2"><? echo "$abstract"; ?></td>
<?
$i++;
} //end of loop
mysql_close();
?>
</table>
</div>
jmack159 Guest
-
How do I get MySQL to NOT sort my resultset?
Hi All The following query works, but MySQL sorts the results set: SELECT STRINGTEXT FROM WEBSTRINGS WHERE GUI=0 AND LANGID='GB' AND TOKENID IN... -
How to sort CFSEARCH results
Was wondering if someone might know an easy way to sort the results of a CFSEARCH query. I can query the Verity collection created of documents,... -
sort by script for sql query results
What is the script for sorting results of a SQL query by a column in the database, though I don't want this column displayed. The variable is... -
Any script to sort SQL results?
Can anybody name the script for sorting results of a SQL query by a column in the database, though I don't want this column displayed. The... -
Ado sort error-Ado Sort -Relate, Compute By, or Sort operations cannot be done on column(s) whose key length is unknown or exceeds 10 KB.
Ado Sort -Relate, Compute By, or Sort operations cannot be done on column(s) whose key length is unknown or exceeds 10 KB. hi, guys i have asp...



Reply With Quote

