Help with Displaying the Output from a table in a Database

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 »

Do i need to pass the sort parameters here

Code: Select all

if ($screen > 0) { 
$url = "view3.php?screen=" . ($screen - 1); 
echo "<a href="$url"><font size="2" face="Arial, Helvetica, sans-serif">Previous</font></a>\n"; 
}
Kingo
Forum Contributor
Posts: 146
Joined: Thu Jun 03, 2004 9:38 am

Post by Kingo »

I passed the sort parameters here

Code: Select all

echo "<font size="2" face="Arial, Helvetica, sans-serif"><a href="".$_SERVER['PHP_SELF']."?sort=name"><b>Name</b></a></font></td>";
echo "<td><font size="2" face="Arial, Helvetica, sans-serif"><a href="".$_SERVER['PHP_SELF']."?sort=phone"><b>Phone</b></a></font></td>";
echo "<td><font size="2" face="Arial, Helvetica, sans-serif"><a href="".$_SERVER['PHP_SELF']."?sort=email"><b>Email</b></a></font></td></tr>";
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

try:

Code: Select all

if ($screen > 0) { 
$url = "view3.php?screen=" . ($screen - 1) . (isset($_GET['sort'])?('&sort='.$_GET['sort']):('')); 
echo "<a href="$url"><font size="2" face="Arial, Helvetica, sans-serif">Previous</font></a>\n"; 
}
Kingo
Forum Contributor
Posts: 146
Joined: Thu Jun 03, 2004 9:38 am

Post by Kingo »

Thanx very much. It works perfectly. I really appreciate your help. It would be great if you could explain me this part.

Code: Select all

(isset($_GET['sort'])?('&sort='.$_GET['sort']):(''));
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

?: is called a trinary operator: has 3 arguments.

expression ? true statement : false statement

it functions almost exactly like a compact if..else

when expression evaluates to true, true statement is run, otherwise false statement is run.
Post Reply