You are here: Re: Problems with sortby « PHP Programming Language « IT news, forums, messages
Re: Problems with sortby

Posted by Michael Cooney on 11/09/06 05:52

$sortby should be the exact column name. eg: 'author.name', not just
'author'

Nancy wrote:
> Having trouble getting this script to work. Errorr states query failed
> when click on sections to sort.
>
> $s = $HTTP_GET_VARS["sort"];
> include("deskheader.php");
>
> include("config.php");
>
>
> function loadlist($s) {
> Global $dbhost, $dbname, $dbuser, $dbpasswd;
>
> switch ($s) {
> case "title" :
> $sortby = "title";
> break;
> case "author" :
> $sortby = "author";
> break;
> case "section" :
> $sortby = "section";
> break;
> case "category" :
> $sortby = "category";
> break;
> case "subcat" :
> $sortby = "subcat";
> break;
> case "division" :
> $sortby = "division";
> break;
> case "subdiv" :
> $sortby = "subdiv";
> break;
> default:
> $sortby = "pageid";
> }
>
> $dbh = mysql_connect($dbhost, $dbuser, $dbpasswd) or die("Could
> not connect");
> mysql_select_db($dbname,$dbh) or die("Could not select database");
> $q1 = "SELECT page.pageid, page.title, author.name,
> section.name, category.name,
> subcat.name, division.name,
> subdiv.name
> FROM page
> INNER JOIN (author, section, category, subcat,
> division, subdiv)
> ON (author.authorid = page.authorid AND
> section.sectionid = page.sectionid AND
> category.categoryid = page.categoryid AND
> subcat.subcatid = page.subcatid AND
> division.divisionid = page.divisionid AND
> subdiv.subdivid = page.subdivid)
> ORDER BY $sortby";
> $rslt = mysql_query($q1, $dbh) or die("Query failed");
>
> echo "<table><tr><th colspan=9>Article List</th></tr>";
> echo "<tr><th><a href=".$_SERVER['SCRIPT_NAME'].">Seq</a></th><th><a
> href=".$_SERVER['SCRIPT_NAME']."?sort=name>Name</a></th>
> <th><a href=".$_SERVER['SCRIPT_NAME']."?sort=title>title</a></th>
> <th><a
> href=".$_SERVER['SCRIPT_NAME']."?sort=author>author</a></th>
> <th><a
> href=".$_SERVER['SCRIPT_NAME']."?sort=section>section</a></th>
> <th><a
> href=".$_SERVER['SCRIPT_NAME']."?sort=category>category</a></th>
> <th><a
> href=".$_SERVER['SCRIPT_NAME']."?sort=subcat>subcat</a></th>
> <th><a
> href=".$_SERVER['SCRIPT_NAME']."?sort=division>division</a></th>
> <th><a
> href=".$_SERVER['SCRIPT_NAME']."?sort=subdiv>subdiv</a></th>
> <th></th></tr>\n";
> while ($row1 = mysql_fetch_array($rslt, MYSQL_ASSOC)) {
> echo "\t<tr>\n";

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация