Jump to content


Need help with my code

  • Please log in to reply
No replies to this topic

#1 ghop2003

  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 16 February 2006 - 02:01 AM

I pasted my code below. It isn't my own code, I got it from somewhere that I can't remember and modified it. Right now, to see some entries i use a link like index.php?cat=*&val=*. I want to add another modifier. I'm trying to order the database by something other than 'title' initially. For example, to order by genre, I want something to use a link like index.php?cat=*&val=*&order=genre.

I added this code right before the '//Performing SQL query' comment.

[!--sizeo:1--][span style=\"font-size:8pt;line-height:100%\"][!--/sizeo--]$default_sort = 'title';
$allowed_order = array ('title', 'director','year','genre','owner');

/* if order is not set, or it is not in the allowed
* list, then set it to a default value. Otherwise,
* set it to what was passed in. */
if (!isset ($_GET['order']) ||
!in_array ($_GET['order'], $allowed_order)) {
$order = $default_sort;
} else {
$order = $_GET['order'];

Then, I place $order in the ORDER BY section of the query, but it doesn't seem to work. I've tried ORDER BY $order'; and ORDER BY '$order'\';

Any help would be appreciated.

[!--sizeo:1--][span style=\"font-size:8pt;line-height:100%\"][!--/sizeo--]<?php
// Connecting, selecting database
$link = mysql_connect('localhost', '******', '******')
or die('Could not connect: ' . mysql_error());
mysql_select_db('dvdswapn_movies') or die('Could not select database');

// Performing SQL query
if ($_GET['cat']=='*' or $_GET['cat']==NULL)
$query = 'SELECT title, director, year, genre, cover, owner, review_url, cover_url FROM movies ORDER BY title';
$query = 'SELECT title, director, year, genre, cover, owner, review_url, cover_url FROM movies WHERE '.$_GET['cat'].' LIKE \''.$_GET['val'].'\' ORDER BY title';

$result = mysql_query($query) or die('Query failed: ' . mysql_error());

// Printing results in HTML
echo "<table width=100% border=0 cellpadding=3 cellspacing=0>\n";
echo "\t<tr bgcolor=#222>\n";
echo "\t\t<td><font size=\"-6\"><u>Title</u></font></td>\n";
echo "\t\t<td><font size=\"-6\"><u>Director</u></font></td>\n";
echo "\t\t<td><font size=\"-6\"><u>Year</u></font></td>\n";
echo "\t\t<td><font size=\"-6\"><u>Genre</u></font></td>\n";
echo "\t\t<td><font size=\"-6\"><u>Cover Image</u></font></td>\n";
echo "\t\t<td><font size=\"-6\"><u>Owner</u></font></td>\n";
echo "\t</tr>\n";
$count = 0;
while ($line = mysql_fetch_array($result, MYSQL_BOTH)) {
echo "\t<tr bgcolor=#1E1E1E>\n";
echo "\t<tr bgcolor=#222>\n";
echo "\t\t<td><font size=\"-6\"><a href=\"$line[review_url]\">$line[title]</a></font></td>\n";
echo "\t\t<td><font size=\"-6\">$line[director]</font></td>\n";
echo "\t\t<td><font size=\"-6\">$line[year]</font></td>\n";
echo "\t\t<td><font size=\"-6\">$line[genre]</font></td>\n";
echo "\t\t<td><font size=\"-6\"><a href=\"$line[cover_url]\">$line[cover]</a></font></td>\n";
echo "\t\t<td><font size=\"-6\">$line[owner]</font></td>\n";
echo "\t</tr>\n";
echo "</table>\n";
echo "<hr align=\"left\" width=60% size=1 color=\"#B0B0B0\">\n";
echo "<font color=\"#B0B0B0\">$count results</font>\n";

// Free resultset

// Closing connection
?> [!--sizec--][/span][!--/sizec--]

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users