Jump to content


Photo

$_SESSION, $_GET, etc confusion


  • Please log in to reply
2 replies to this topic

#1 gstrother1

gstrother1
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 25 May 2006 - 07:21 PM

the website i'm working on is: [a href=\"http://poker.mwrarmyalaska.com/Points/overall2.php\" target=\"_blank\"]http://poker.mwrarmyalaska.com/Points/overall2.php[/a] (still a work in progress)

I want the top links on the table to send the corresponding names to the page so that it will ORDER BY

here is some of the code. I'm not sure if I have to use a form (im guessing so?) this is my first page i'm trying to create in PHP

I know I'm probably doing something stupidly wrong, but I've been playing with it all morning and can't get it to work. Thanks in advance for the help!

George

<?php


    $sortby = $_SESSION['SortByValue'];
    
    switch($sortby){
        case 'Name':
        $sortby = 'P.Last';
                ... snip ...
        default:
        $sortby = 't.OverAll';
                 }


$overall_query = "SELECT P.First, P.Last, P.PlayerID, t.Game1,t.Game2,t.Game3,t.Game4,t.Game5,t.Game6,t.Game7,t.Game8, t.OverAll FROM Player AS P, Tournament1Points AS t WHERE P.PlayerID = t.PlayerID AND t.OverAll > 0 ORDER BY $sortby DESC";

$overallresult = mysql_query($overall_query);

echo "<br /><table border=1 style='margin-right: auto; margin-left:auto'>" .
        "<tr>" .
        "<td><a href=\"overall2.php?SortByValue='Name'\">Name</a></td>" .
        "<td><a href=\"overall2.php?SortByValue='PlayerID'\">PlayerID</a></td>" .
        "<td><a href=\"overall2.php?SortByValue='Game1'\">Game 1</a></td>" .
        "<td><a href=\"overall2.php?SortByValue='Game2'\">Game 2</a></td>" .
        "<td><a href=\"overall2.php?SortByValue='Game3'\">Game 3</a></td>" .
        "<td><a href=\"overall2.php?SortByValue='Game4'\">Game 4</a></td>" .
        "<td><a href=\"overall2.php?SortByValue='Game5'\">Game 5</a></td>" .
        "<td><a href=\"overall2.php?SortByValue='Game6'\">Game 6</a></td>" .
        "<td><a href=\"overall2.php?SortByValue='Game7'\">Game 7</a></td>" .
        "<td><a href=\"overall2.php?SortByValue='Game8'\">Game 8</a></td>" .
        "<td><a href=\"overall2.php?SortByValue='OverAll'\">Over All</a></td>" .
        "</tr>";

while ($row = mysql_fetch_row($overallresult))
{
    $Fname = $row[0];
    $Lname = $row[1];
    $PlayerID = $row[2];
    $Game1 = $row[3];
    $Game2 = $row[4];
    $Game3 = $row[5];
    $Game4 = $row[6];
    $Game5 = $row[7];
    $Game6 = $row[8];
    $Game7 = $row[9];
    $Game8 = $row[10];
    $OverAll = $row[11];
echo "<tr>" .
        "<td> $Lname, $Fname </td>" .
        "<td> $PlayerID </td>" .
        "<td> $Game1 </td>" .
        "<td> $Game2 </td>" .
        "<td> $Game3 </td>" .
        "<td> $Game4 </td>" .
        "<td> $Game5 </td>" .
        "<td> $Game6 </td>" .
        "<td> $Game7 </td>" .
        "<td> $Game8 </td>" .
        "<td> $OverAll </td>" .
        "<tr>";

}
echo "</table>";
    mysql_close($conn);
?>



#2 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 25 May 2006 - 07:36 PM

if you have 'sort by' links that you want the list to be sorted by, you would use the $_GET like so:

$value = 'blah'; //whatever you are sorting by
echo "<a href='blah.php?SortByValue=".$value."'>Sort by ".$value."</a>";

and then in blah.php:
$sortby = $_GET['SortByValue'];

also you can get rid of a lot of those lines of code by making Game an array instead of doing Game1, Game2, etc.. and just looping the links and echoes...

Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#3 gstrother1

gstrother1
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 26 May 2006 - 12:45 AM

Thanks Crayon Violent.. I really appreciate the fast response and I got it working!


[!--quoteo(post=377109:date=May 25 2006, 11:36 AM:name=Crayon Violent)--][div class=\'quotetop\']QUOTE(Crayon Violent @ May 25 2006, 11:36 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
if you have 'sort by' links that you want the list to be sorted by, you would use the $_GET like so:

$value = 'blah'; //whatever you are sorting by
echo "<a href='blah.php?SortByValue=".$value."'>Sort by ".$value."</a>";

and then in blah.php:
$sortby = $_GET['SortByValue'];

also you can get rid of a lot of those lines of code by making Game an array instead of doing Game1, Game2, etc.. and just looping the links and echoes...
[/quote]





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users