PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
Kingo
Forum Contributor
Posts: 146 Joined: Thu Jun 03, 2004 9:38 am
Post
by Kingo » Thu Jun 03, 2004 10:01 am
I get a parse Error
Parse error: parse error, unexpected '<' in c:\inetpub\wwwroot
If i use this
Code: Select all
echo "<tr><td>";
echo "<a href="".$_SERVER['PHP_SELF']."?sort=name"">Name</a></td></tr>";
magicrobotmonkey
Forum Regular
Posts: 888 Joined: Sun Mar 21, 2004 1:09 pm
Location: Cambridge, MA
Post
by magicrobotmonkey » Thu Jun 03, 2004 10:31 am
look at the color of the code and you can see the problem! an extra " :
Code: Select all
<?php
echo "<tr><td>";
echo "<a href="".$_SERVER['PHP_SELF']."?sort=name">Name</a></td></tr>";
?>
Kingo
Forum Contributor
Posts: 146 Joined: Thu Jun 03, 2004 9:38 am
Post
by Kingo » Thu Jun 03, 2004 10:38 am
It works ..But the columns dont get sorted....They remain the same even after the header is clicked
lostboy
Forum Contributor
Posts: 329 Joined: Mon Dec 30, 2002 8:12 pm
Location: toronto,canada
Post
by lostboy » Thu Jun 03, 2004 10:41 am
Dude,
You need to code to
and then
Code: Select all
$orderby = " order by $sort"
$sql = $sql_select.$orderby;
You can't have thought the href alone would control the sort...it just passes the criteria.
Kingo
Forum Contributor
Posts: 146 Joined: Thu Jun 03, 2004 9:38 am
Post
by Kingo » Thu Jun 03, 2004 10:52 am
When i use this
Code: Select all
$result = mysql_query("SELECT Name,Phone FROM contact LIMIT $start, $rows_per_page");
$rows = mysql_num_rows($result);
$sort = $_GET['sort'];
$orderby = " order by $sort";
$result = $result.$orderby;
I get the following error
Notice: Undefined index: sort in c:\inetpub\wwwroot\PHP_RemoteFiles\example1.php on line 35
Name Phone
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in c:\inetpub\wwwroot\PHP_RemoteFiles\example1.php on line 48
magicrobotmonkey
Forum Regular
Posts: 888 Joined: Sun Mar 21, 2004 1:09 pm
Location: Cambridge, MA
Post
by magicrobotmonkey » Thu Jun 03, 2004 10:59 am
try it like this:
Code: Select all
<?php
$query = "SELECT Name,Phone FROM contact LIMIT $start, $rows_per_page";
if(isset$_GET['sort']){
$sort = $_GET['sort'];
$query.= " ORDER BY $sort";
}
$result = mysql_query($query);
$rows = mysql_num_rows($result);
?>
Kingo
Forum Contributor
Posts: 146 Joined: Thu Jun 03, 2004 9:38 am
Post
by Kingo » Thu Jun 03, 2004 12:14 pm
I still have a problem.
I get the following errors
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in c:\inetpub\wwwroot\PHP_RemoteFiles\example1.php on line 41
Name Phone
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in c:\inetpub\wwwroot\PHP_RemoteFiles\example1.php on line 59
When i use this code
Code: Select all
$query = "SELECT Name,Phone FROM contact LIMIT $start, $rows_per_page";
if(isset ($_GET['sort']))
{
$sort = $_GET['sort'];
$query.= " ORDER BY $sort";
}
$result = mysql_query($query);
$rows = mysql_num_rows($result);
And I'm getting error on this line too
while ($row = mysql_fetch_array($result))
lostboy
Forum Contributor
Posts: 329 Joined: Mon Dec 30, 2002 8:12 pm
Location: toronto,canada
Post
by lostboy » Thu Jun 03, 2004 12:20 pm
Change to this...now what does it say?
Code: Select all
$result = mysql_query($query) or die ("Can't query because ".mysql_error());
magicrobotmonkey
Forum Regular
Posts: 888 Joined: Sun Mar 21, 2004 1:09 pm
Location: Cambridge, MA
Post
by magicrobotmonkey » Thu Jun 03, 2004 12:21 pm
Code: Select all
<?php
//change this line:
$result = mysql_query($query);
//to this:
$result = mysql_query($query) or die("Query failed: ". mysql_error());
?>
edit: got me!
Kingo
Forum Contributor
Posts: 146 Joined: Thu Jun 03, 2004 9:38 am
Post
by Kingo » Thu Jun 03, 2004 12:29 pm
I get the following error
Can't query because You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'ORDER BY name' at line 1
magicrobotmonkey
Forum Regular
Posts: 888 Joined: Sun Mar 21, 2004 1:09 pm
Location: Cambridge, MA
Post
by magicrobotmonkey » Thu Jun 03, 2004 12:30 pm
check your capitalization - in the select pary you have "Name" and there you have "name"
lostboy
Forum Contributor
Posts: 329 Joined: Mon Dec 30, 2002 8:12 pm
Location: toronto,canada
Post
by lostboy » Thu Jun 03, 2004 12:30 pm
sql order is wrong
Code: Select all
$query = "SELECT Name,Phone FROM contact ";
if(isset ($_GET['sort']))
{
$sort = $_GET['sort'];
$query.= " ORDER BY $sort";
}
$query .= " LIMIT $start, $rows_per_page";
$result = mysql_query($query) or die("Query failed: ". mysql_error());
Kingo
Forum Contributor
Posts: 146 Joined: Thu Jun 03, 2004 9:38 am
Post
by Kingo » Thu Jun 03, 2004 12:37 pm
HURRAY!!!! IT WORKS.................THANX VERY MUCH BASTIEN & magicrobotmonkey.......I REALLY APPRECIATE YOUR HELP.
Kingo
Forum Contributor
Posts: 146 Joined: Thu Jun 03, 2004 9:38 am
Post
by Kingo » Thu Jun 03, 2004 3:41 pm
If we want to display alternate color for each row, how do we do that.