1
<?php 
    $link=mysql_connect("localhost","root","")or die("Can't Connect...");
    mysql_select_db("project") or die("Can't Connect to Database...");
    $qqqe="SELECT * FROM groupp";
    $queryRessource10 = mysql_query($qqqe,$link) or die(mysql_error());
    $numrows=mysql_num_rows($queryRessource10);
    if($numrows > 0)
    {

       while($row10 = mysql_fetch_array($queryRessource10 )) {
       $group_id=$row10['group_id'];
       $_SESSION['G_ID']=$group_id;
         echo "<a href=group.php?group_id=".$group_id." title='".$row10['group_name']."'>".$row10['group_name']."</a><br />";
 }}}?>

my problem is not with generate the id i got it perfect group.php?id=(the id of group from database ) my problem when i go to the page the session keep taking the last group_id in while loop ( number 2 ) so how i can get the session to be send correctly for id=1 i send session 1 when i open the group page

enter image description here

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
  • 1
    Did you, errrr start the session? – Funk Forty Niner Nov 30 '16 at 19:25
  • 1
    Did you, errrr leave the question? or did you want to wait for a magic answer? – Funk Forty Niner Nov 30 '16 at 19:29
  • Session is a stateful part of php; you're overwriting the g_id in the while loop, so it will always end up as the last iteration-value of $row10['group_id']. I think you need a javascript click handler for clicking on the link (since you won't know until the link is clicked which one is selected to store it in session in the first place). Does that sound about right? – Malovich Nov 30 '16 at 19:32
  • 2
    Every time you use [the `mysql_`](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php) database extension in new code **[a Kitten is strangled somewhere in the world](http://2.bp.blogspot.com/-zCT6jizimfI/UjJ5UTb_BeI/AAAAAAAACgg/AS6XCd6aNdg/s1600/luna_getting_strangled.jpg)** it is deprecated and has been for years and is gone for ever in PHP7. If you are just learning PHP, spend your energies learning the `PDO` or `mysqli` database extensions. [Start here](http://php.net/manual/en/book.pdo.php) – RiggsFolly Nov 30 '16 at 19:35
  • 1
    Don't set `$_SESSION['G_ID']` here. Set it in `group.php`. `$_SESSION['G_ID'] = $_GET['group_id'];` – AbraCadaver Nov 30 '16 at 19:36
  • Some sensible code indentation would be a good idea. It helps us read the code and more importantly it will help **you debug your code** [Take a quick look at a coding standard](http://www.php-fig.org/psr/psr-2/) for your own benefit. You may be asked to amend this code in a few weeks/months and you will thank me in the end. – RiggsFolly Nov 30 '16 at 19:37
  • @RiggsFolly is that _you_ strangling that cat? If you're the one responsible for doing that every time someone uses `mysql_`, you must be quite a busy guy. And your cat probably doesn't like you. – Don't Panic Nov 30 '16 at 19:39
  • @Don'tPanic No its not me. But the cat does look very like mine – RiggsFolly Nov 30 '16 at 19:45
  • What, might I ask, is the purpose of setting the session variable in the first place? – Malovich Nov 30 '16 at 19:51

0 Answers0