Jump to content

Archived

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

ghop2003

Need help with my code

Recommended Posts

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'];
}[!--sizec--][/span][!--/sizec--]

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';
else
$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)) {
$count++;
if($count%2)
echo "\t<tr bgcolor=#1E1E1E>\n";
else
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
mysql_free_result($result);

// Closing connection
mysql_close($link);
?> [!--sizec--][/span][!--/sizec--]

Share this post


Link to post
Share on other sites

×

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.