Jump to content

Recommended Posts

Hello everyone.

 

I am trying to filler a query result. This is my script

 

// Require the configuration :
require ('./includes/configuration.inc.php');

// Require the database connection:
require (MYSQL);

echo '<a href="">Tutor</a> | <a href="">Institute</a>';

$q = "SELECT
           'tutor' AS Member_Type,
           tutor_code AS Member_Code,
           tutor_name AS Member_Name
       FROM tutors
       UNION
       SELECT
           'institute',
           institute_code,
           institute_name
       FROM institutes";

$r = mysqli_query( $dbc, $q);

echo '<table border="1">
           <tr>
             <td>Member Type</td>
             <td>Member Code</td>
             <td>Member Name</td>
           </tr>';
while ( $row = mysqli_fetch_array($r, MYSQLI_ASSOC)) {
   echo '<tr>
             <td>'.$row['Member_Type'].'</td>
             <td>'.$row['Member_Code'].'</td>
             <td>'.$row['Member_Name'].'</td>
           </tr>';
}
echo '</table>';

 

My output is something similar to this..

 

+-------------+-------------+--------------------------------------+
| Member_Type | Member_Code | Member_Name		  |
+-------------+-------------+--------------------------------------+
| tutor	   |	    1250 | Edward 				 |
| tutor	   |	    1251 | Sachin 				  |
| tutor	   |	    1252 | Virath 				   |
| tutor	   |	    1253 | Cris 	                  |
| institute   |	    2500 | Montana               |
| institute   |	    2501 | Millanium 			  |
| institute   |	    2502 | Viswa 				   |
| institute   |	    2503 | Separd                  |
| institute   |	    2504 | Madurasanga 	  |
+-------------+-------------+--------------------------------------+

 

Now I need to filter this result using my tutor and institute link. So can I know is this possible to do it?

 

Hope someone will help me..

Thank you

You should probably do this :

 

echo '<a href="?tutor=link">Tutor</a> | <a href="?institute=link">Institute</a>';


if (isset($_REQUEST['tutor'])) {

   $q = "SELECT
                       'tutor' AS Member_Type,
                       tutor_code AS Member_Code,
                       tutor_name AS Member_Name
               FROM tutors";
}


elseif (isset($_REQUEST['institute'] {
   $q = "SELECT
                       'institute',
                       institute_code,
                       institute_name
               FROM institutes";

} else {
$q = "SELECT
                       'tutor' AS Member_Type,
                       tutor_code AS Member_Code,
                       tutor_name AS Member_Name
               FROM tutors
               UNION
               SELECT
                       'institute',
                       institute_code,
                       institute_name
               FROM institutes";
}

$r = mysqli_query( $dbc, $q);


echo '<table border="1">
                       <tr>
                         <td>Member Type</td>
                         <td>Member Code</td>
                         <td>Member Name</td>
                       </tr>';
while ( $row = mysqli_fetch_array($r, MYSQLI_ASSOC)) {
       echo '<tr>
                         <td>'.$row['Member_Type'].'</td>
                         <td>'.$row['Member_Code'].'</td>
                         <td>'.$row['Member_Name'].'</td>
                       </tr>';
}
echo '</table>';

or

 

echo '<a href="?tutor=link">Tutor</a> | <a href="?institute=link">Institute</a>';


$tutor = isset($_GET['institute']) ? '0' : '1';    
$institute = isset($_GET['tutor']) ? '0' : '1';

$q = "SELECT
    'tutor' AS Member_Type,
    tutor_code AS Member_Code,
    tutor_name AS Member_Name
    FROM tutors
    WHERE $tutor
UNION
SELECT
    'institute',
    institute_code,
    institute_name
    FROM institutes
    WHERE $institute
    ";

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.