Page 2 of 6

Posted: Thu Jun 03, 2004 10:01 am
by Kingo
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>";

Posted: Thu Jun 03, 2004 10:31 am
by magicrobotmonkey
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>"; 

?>

Posted: Thu Jun 03, 2004 10:38 am
by Kingo
It works ..But the columns dont get sorted....They remain the same even after the header is clicked

Posted: Thu Jun 03, 2004 10:41 am
by lostboy
Dude,

You need to code to

Code: Select all

$sort = $_GET['sort'];
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.

Posted: Thu Jun 03, 2004 10:52 am
by Kingo
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

Posted: Thu Jun 03, 2004 10:59 am
by magicrobotmonkey
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); 

?>

Posted: Thu Jun 03, 2004 12:14 pm
by Kingo
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))

Posted: Thu Jun 03, 2004 12:20 pm
by lostboy
Change to this...now what does it say?

Code: Select all

$result = mysql_query($query) or die ("Can't query because ".mysql_error());

Posted: Thu Jun 03, 2004 12:21 pm
by magicrobotmonkey

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!

Posted: Thu Jun 03, 2004 12:29 pm
by Kingo
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

Posted: Thu Jun 03, 2004 12:30 pm
by magicrobotmonkey
check your capitalization - in the select pary you have "Name" and there you have "name"

Posted: Thu Jun 03, 2004 12:30 pm
by lostboy
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());

Posted: Thu Jun 03, 2004 12:33 pm
by magicrobotmonkey
Oh yea, and that!

Posted: Thu Jun 03, 2004 12:37 pm
by Kingo
HURRAY!!!! IT WORKS.................THANX VERY MUCH BASTIEN & magicrobotmonkey.......I REALLY APPRECIATE YOUR HELP.

Alternate colors

Posted: Thu Jun 03, 2004 3:41 pm
by Kingo
If we want to display alternate color for each row, how do we do that.