1

i have this problem on getting a specific data in my list table. basically, i have a table named orglist which has 8 columns (org no, orgname, orgcode, subject area, date created, year, semester and managerID)

in my page, i have this php code where i execute the data into a list. heres my code:

    $query = "SELECT * FROM orglist WHERE managerID = '$managerID';";
    $result = mysqli_query($conn, $query);
    $check = mysqli_num_rows($result);
    echo "<div class='page-header'>
            <h2>My Organizations</h2>
          </div> 
          <div class='container col-md-6'>
          <div class='list-group'>";
    if($check > 0){
        while ($row = mysqli_fetch_array($result)) {
            $orgname = $row['orgName'];

            echo "  <a class='list-group-item'  href='viewActiveOrg.php'> " . $orgname . "</a>";
        }
    echo "</div></div>";

so after it executes, it displays a list of anchor tags/links that a manager can click. If a manager clicks one of the links, the active page should bring the manager to another page and should show information about the link that the manager clicked. I am thinking after I select the datas and put into list, I should create a session, but the problem is if table orglist has many rows, how can i specifically get the row's data (name and orgcode) that was clicked by the manager?

thank you for answering.

2 Answers 2

2

You can pass it as parameter to your link target and retrieve with the metod GET

echo "<a class='list-group-item' href='viewActiveOrg.php?name=".$row['orgName']."&orgcode=".$row['orgcode']."> ".$orgname."</a>";

//In your viewActiveOrg.php page :

if(isset($_GET['orgName']) && isset($_GET['orgcode'])){
   $name = $_GET['orgName'];
   $orgcode =  $_GET['orgcode'];
   /*
    Do your  staff
   */
}
Sign up to request clarification or add additional context in comments.

1 Comment

same answer but also correct. thank you man. this will help me a lot
0

You could just add a querystring to you link

echo "<a class='list-group-item'  href='viewActiveOrg.php?manager-id=".$row['managerID']."'> " . $orgname . "</a>";

and then in your viewActiveOrg.php fetch the paramater by

$managerId = $_GET['manager-id'];

and query the database again for the manager with this id.

You could of course also add several parameters (org no, orgname, orgcode, subject area, date created, year, semester and managerID) to your querystring and fetch them all in your viewActiveOrg.php page.

echo "<a class='list-group-item'  href='viewActiveOrg.php?manager-id=".$row['managerID']."&org-name=".$row['orgname']."&org-code=".$row['orgcode']."'> " . $orgname . "</a>";

5 Comments

but, stiil it would refer to other links because the manager is currently logged in. what i need is the orgname and the orgcode that was clicked $row['orgname'] and $row['orgcode']
Then add them to the link the same way managerID is addedd, se edited answer
man, i got it. thank you so much. what kind of php-trick is this? sorry new to php
Good that it worked out. You can find more information here
is it safe to use get? i mean from sql injection or something related to hacking?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.