Ohh I see thanks!
Printable View
Ohh I see thanks!
Can you tell me why it doesn't work please? Thanks.
Define "doesn't work". Personally, I think you should go and look over http://php.net and http://www.php-mysql-tutorial.com so that you can learn PHP/MySQL coding. If you need help on a specific item, come back and ask about that issue; but don't have us do all the work for you. Just my two cents.
When I click on the "A-Z" or "Z-A" or the others, it does not reorder.
In the code you posted, I don't see anywhere that you called a query to the database (other than assigning $q as the query to be sent). The content will not sort the way you have the page set up because you have it hardcoded into the page instead of pulling that data from the db.
Hope this helps.
Umm, well I changed it. And I put quotes around them. Here's the code. I changed the actual database access just for security.
HTML Code:
<?php
$link = mysql_connect("localhost","USERNAME_USERNAME","PASSWORD");
mysql_select_db("USERNAME_DATABASE);
$type = ((isset($_GET["sorttype"])?$_GET["sorttype"]:"1") == "1")?"DESC":"ASC";
/*
this is really the equivelant of
$type = "";
if(isset($_GET["sorttype"]))
$type = $_GET["sorttype"];
else
$type = "1";
$type_cmp = $type;
if($type_cmp == "1")
$type = "DESC";
else
$type = "ASC";
unset($type_cmp);
*/
$col = ($_GET["sortname"]);
$q = "SELECT * FROM records ORDER BY `$col` $type";
?>
<?php require('_drawrating.php'); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script type="text/javascript" language="javascript" src="js/behavior.js"></script>
<script type="text/javascript" language="javascript" src="js/rating.js"></script>
<link rel="stylesheet" type="text/css" href="css/rating.css" />
</head>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>Sorth by: <a href="sortexample.php?sorttype=1&sortname=Name">Z to A</a>
<a href="sortexample.php?sorttype=0&sortname=Name">A to Z</a>
<a href="sortexample.php?sorttype=1&sortname=Rating">Top rated to Least</a>
<a href="sortexample.php?sorttype=0&sortname=Rating">Least rated to Top</a></td>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="14%"><p>funny picture </p>
<p>CONTENT</p></td>
<td width="86%">Rating: <?php echo rating_bar('8xxa','5'); ?>
<p> </p></td>
</tr>
<tr>
<td><p>cool picture </p>
<p>CONTENT</p></td>
<td>Rating: <?php echo rating_bar('8x41','5'); ?></td>
</tr>
<tr>
<td><p>test picture</p>
<p>CONTENT</p></td>
<td>Rating: <?php echo rating_bar('84854','5'); ?></td>
</tr>
<tr>
<td><p>test 1 picture</p>
<p>CONTENT</p></td>
<td>Rating: <?php echo rating_bar('8454','5'); ?></td>
</tr>
<tr>
<td><p>5 cool picture</p>
<p>CONTENT</p></td>
<td>Rating: <?php echo rating_bar('8454654a','5'); ?></td>
</tr>
<tr>
<td><p>number test</p>
<p>CONTENT</p></td>
<td>Rating: <?php echo rating_bar('154545','5'); ?></td>
</tr>
<tr>
<td># character testCONTENT</td>
<td>Rating: <?php echo rating_bar('8xxa','5'); ?></td>
</tr>
<tr>
<td><p>hello test </p>
<p>CONTENT</p></td>
<td>Rating: <?php echo rating_bar('815454','5'); ?></td>
</tr>
<tr>
<td><p>1 test</p>
<p> CONTENT</p></td>
<td>Rating: <?php echo rating_bar('822a','5'); ?></td>
</tr>
<tr>
<td><p>z test</p>
<p> CONTENT</p></td>
<td>Rating: <?php echo rating_bar('454xa','5'); ?></td>
</tr>
</table>
</body>
</html>
Ok, let me try to explain again. You are logging into the database, but you are not getting any content from that database. Your code should look something like this instead of what you have above:
Hope this helps.Code:<?php
$link = mysql_connect("localhost","USERNAME_USERNAME","PASSWORD");
mysql_select_db("USERNAME_DATABASE);
$type = ((isset($_GET["sorttype"])?$_GET["sorttype"]:"1") == "1")?"DESC":"ASC";
/*
this is really the equivelant of
$type = "";
if(isset($_GET["sorttype"]))
$type = $_GET["sorttype"];
else
$type = "1";
$type_cmp = $type;
if($type_cmp == "1")
$type = "DESC";
else
$type = "ASC";
unset($type_cmp);
*/
$col = ($_GET["sortname"]);
$q = "SELECT * FROM records ORDER BY `$col` $type";
?>
<?php require('_drawrating.php'); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script type="text/javascript" language="javascript" src="js/behavior.js"></script>
<script type="text/javascript" language="javascript" src="js/rating.js"></script>
<link rel="stylesheet" type="text/css" href="css/rating.css" />
</head>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>Sorth by: <a href="sortexample.php?sorttype=1&sortname=Name">Z to A</a>
<a href="sortexample.php?sorttype=0&sortname=Name">A to Z</a>
<a href="sortexample.php?sorttype=1&sortname=Rating">Top rated to Least</a>
<a href="sortexample.php?sorttype=0&sortname=Rating">Least rated to Top</a></td>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<?php
$result = mysql_query($q);
if (!mysql_num_rows($result)) {
?>
<tr>
<td colspan="2"><h4> No Results Found! </h4></td>
</tr>
<?php
}
else {
while ($info = mysql_fetch_array($result)) {
?>
<tr>
<td><?php echo $info['Name'];?></td>
<td><?php echo $info['Rating'];?></td>
</tr>
<?php
}
}
?>
</table>
</body>
</html>
Thanks, I get this now. Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/athletes/public_html/sortexample.php on line 48
No Results Found!