headcutter
-
Posts
8 -
Joined
-
Last visited
Never
Posts posted by headcutter
-
-
Thanks for the code. I edited it to suit my needs but I get an error:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource on line:
while($rankings = mysql_fetch_array($sql)){
Maybe someone will be able to find the reason for this error. Here is the code:
<?php include ("dbconfig.php") ?>
<?php
#display columns names as links, where you can sort players by
$columns ="<font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"2\" color=\"dcc59f\">Click on column name to sort list by that column.</font><br><br>";
$columns.="<table border=\"0\" width=\"70%\"><tr>";
$columns.="<td width=\"25%\"><div align=\"left\"><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"2\" color=\"dcc59f\"><a href=\"$PHP_SELF?sortby=name\">Name</a></font></div></td>";
$columns.="<td width=\"25%\"><div align=\"left\"><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"2\" color=\"dcc59f\"><a href=\"$PHP_SELF?sortby=name\">Name</a></font></div></td>";
$columns.="<td width=\"25%\"><div align=\"right\"><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"2\" color=\"dcc59f\"><a href=\"$PHP_SELF?sortby=pet\">Pet</a></font></div></td>";
$columns.="<td width=\"25%\"><div align=\"right\"><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"2\" color=\"dcc59f\"><a href=\"$PHP_SELF?sortby=pet\">Pet</a></font></div></td>";
$columns.="</tr></table>";
$columns.="<table border=\"0\" width=\"70%\"><tr><td><hr></td></tr></table>";
echo($columns);
if(!isset($_GET['page'])){
$page = 1;
} else {
$page = $_GET['page'];
}
// Define the number of results per page
$max_results = 100;
// Figure out the limit for the query based
// on the current page number.
$from = (($page * $max_results) - $max_results);
// Perform MySQL query on only the current page number's results; determine how user wants to see rank list
if(!isset($_GET['sortby'])){
$sortby = "name";
$sql = "SELECT * FROM friends ORDER BY $sortby LIMIT $from, $max_results";
}
else {
$sortby = $_GET['sortby'];
$sql = "SELECT * FROM friends ORDER BY $sortby ";
if ($sortby != 'name'){ $sql.= "DESC "; }
$sql.="LIMIT $from, $max_results";
}
mysql_query($sql) or die(mysql_error());
echo("<table border=\"0\" width=\"70%\">");
while($rankings = mysql_fetch_array($sql)){
// Build your formatted results here.
$listranks="<tr><td width=\"25%\">";
$listranks.="<div align=\"left\"><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"1\" color=\"dcc59f\"><a href=\"attack.php?targetplayer=".$rankings["name"]."\">".$rankings["name"]."</a></div></font>";
$listranks.="</td><td width=\"25%\">";
$listranks.="<div align=\"right\"><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"1\" color=\"dcc59f\">".$rankings["name"]."</font></div>";
$listranks.="</td><td width=\"25%\">";
$listranks.="<div align=\"right\"><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"1\" color=\"dcc59f\">".$rankings["pet"]."</font></div>";
$listranks.="</td><td width=\"25%\">";
$listranks.="<font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"1\" color=\"dcc59f\"><div align=\"right\">".$rankings["pet"]."</div></font>";
$listranks.="</td></tr>";
echo($listranks);
}
echo("</table>");
echo("<table border=\"0\" width=\"70%\"><tr><td><hr></td></tr></table>");
echo("<table border=\"0\" width=\"70%\"><tr><td>");
// Figure out the total number of results in DB:
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM friends"),0);
// Figure out the total number of pages. Always round up using ceil()
$total_pages = ceil($total_results / $max_results);
// Build Page Number Hyperlinks
echo "<font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"1\" color=\"dcc59f\"><center>Select a Page<br />";
// Build Previous Link
if($page > 1){
$prev = ($page - 1);
echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$prev&sortby=$sortby\"><<</a> ";
}
for($i = 1; $i <= $total_pages; $i++){
if(($page) == $i){
echo "<font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"1\" color=\"000000\">$i </font>";
} else {
echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$i&sortby=$sortby\">$i</a> ";
}
}
// Build Next Link
if($page < $total_pages){
$next = ($page + 1);
echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$next&sortby=$sortby\">>></a>";
}
echo "</center></font>";
echo("</td></tr></table>");
?> -
I want the users on my website to be able to sort columns by content (for example clicking on the colums name to sort all of them alphabetically or to sort numbers)
Could anyone recommend any guide or post a sample code? Thanks. -
Hi, I am trying to make alternating row colors work reading this tutorial:
[a href=\"http://www.geekpedia.com/prog_ttrls.php?id=10\" target=\"_blank\"]http://www.geekpedia.com/prog_ttrls.php?id=10[/a]
Anyway it is not working, so I am wondering what I did wrong or if there is an easier way to do it since the code is quite long.
Here is what I have done so far:
<?php
$data = mysql_query("SELECT * FROM friends ORDER BY name")
or die(mysql_error());
$i = 0;
Print "<table border=0 width=100%>";
Print "<tr>";
Print "<th>Name:</th>";
Print "<th>Pet:</th> </tr>";
while($row = mysql_fetch_array( $data ))
{
if($i%2 == 0)
{
Print "<tr bgcolor=#FFFFFF><td><a href=\"" . $row['pet'] . ".html\">" . $row['pet'] . "</a></td>";
Print "<td><a href=\"pets.html\">".$row['pet'] . "</a></td></tr>";
}
else
{
Print "<tr bgcolor=#CCCCCC><td><a href=\"" . $row['pet'] . ".html\">" . $row['pet'] . "</a></td>";
Print "<td><a href=\"pets.html\">".$row['pet'] . "</a></td></tr>";
$i++;
}
}
Print "</table>";
mysql_close();
?>
Any suggestions?
-
I am getting an error:
Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING
(Print "<td><a href=\" . $row['pet'] . ".html . "\">".$row['pet'] . "</a></td>";)
With this code:
while($row = mysql_fetch_array( $data ))
{
Print "<td><a href=\" . $row['pet'] . ".html . "\">".$row['pet'] . "</a></td>";
Print "<td><a href=\"pets.html\">".$row['pet'] . "</a></td></tr>";
}
And 2 errors if I use this code:
Warning: Unexpected character in input: '\' (ASCII=92) state=1
Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING
while($row = mysql_fetch_array( $data ))
{
Print "<td><a href=\"" . $row['pet'] . ".html . "\">".$row['pet'] . "</a></td>";
Print "<td><a href=\"pets.html\">".$row['pet'] . "</a></td></tr>";
}
-
Displaying in colums is working now.
I get this error:
parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING, this line: Print "<tr><td><a href=\".$row['link'] . "\>".$row['name'] . "</td> ";
when I want each of the entries to have seperate links. I created a "link" variable to store the link address.
Here is the code:
$data = mysql_query("SELECT * FROM friends ORDER BY name")
or die(mysql_error());
Print "<table border=0 width=100%>";
Print "<tr>";
Print "<th>Name:</th>";
Print "<th>Pet:</th> </tr>";
while($row = mysql_fetch_array( $data ))
{
Print "<tr><td><a href=\".$row['link'] . "\>".$row['name'] . "</td> ";
Print "<td><a href=\"pets.html\">".$row['pet'] . "</a></td></tr>";
}
Print "</table>";
mysql_close();
?> -
Thanks, that worked.
I was also wondering if there is an easy way to link each animal to webpages of each animal (frog.html, dog.html and cat.html) instead of linking all of the animals to one file. Any ideas?
Additionaly I have a question about displaying data in colums instead of rows.
It looks like this right now:
Name:Rose Pet: Cat
Name:Bradley Pet: Frog
Name:Marie Pet: Dog
Name:Ann Pet: Cat
Name:Rose Pet: Cat
Name:Bradley Pet: Frog
Name:Marie Pet: Dog
Name:Ann Pet: Cat
How can I modify it to this?:
Name: Pet:
Rose Cat
Bradley Frog
Marie Dog
Ann Cat
Rose Cat
Bradley Frog
Marie Dog
Ann Cat
I know I probably have to modify this piece of code:
Print "<table border cellpadding=0>";
while($info = mysql_fetch_array( $data ))
{
Print "<tr>";
Print "<th>Name:</th> <td>".$info['name'] . "</td> ";
Print "<th>Pet:</th> <td><a href=\"pets.html\">".$info['pet'] . "</a></td></tr>";
}
Print "</table>";
Again thanks for any help.
-
Hi, I am using this code to create a table:
CREATE TABLE friends (name VARCHAR(30), fav_color VARCHAR(30), fav_food VARCHAR(30), pet VARCHAR(30));
INSERT INTO friends VALUES ( "Rose", "Pink", "Tacos", "Cat" ), ( "Bradley", "Blue", "Potatoes", "Frog" ), ( "Marie", "Black", "Popcorn", "Dog" ), ( "Ann", "Orange", "Soup", "Cat" )
I display the table by this code:
Print "<table border cellpadding=0>";
while($info = mysql_fetch_array( $data ))
{
Print "<tr>";
Print "<th>Name:</th> <td>".$info['name'] . "</td> ";
Print "<th>Pet:</th> <td>".$info['pet'] . " </td></tr>";
}
Print "</table>";
?>
What should I do if I want all of the pets to be clickable (links)? Is there some way to integrate
<a href="pets.html"> into the code? I want the users to be able to click on the pets name for example frog and I want them to be redirected to pets.html
Thanks for any help- I cant find anything on the internet.
set a limit on number of downloaded mp3?
in PHP Coding Help
Posted