samedi 27 février 2016

Mysql Matching web

I've a database with table student (ID-Primary), student location as fields and an employer table with location also. I want to match the employer's location with the student's location and copy the student id and paste it to the employer's table where student location= employer' location. I have the following code.

Form: Student ID

    <th style='border: solid 1px black;'>Field Of Study</th>
    <th style='border: solid 1px black;'>Location</th>

</tr>
<?php $count = mysqli_num_rows($search_result);

    while($row = mysqli_fetch_array($search_result)):?>
    <tr>
        <td align="center" style='border: solid 1px black;'><?php echo $row['stud_ID'];?></td>
        <td align="center" style='border: solid 1px black;'><?php echo $row['stud_FIELDOFSTUDY'];?></td>
        <td align="center" style='border: solid 1px black;'><?php echo $row['stud_location'];?></td>


    </tr>
<?php endwhile;?>
</table>
<table style='border: solid 1px black;'>
<tr style='border: solid 1px black;'>

    <th style='border: solid 1px black;'>Location Of Employer</th>

</tr>
<?php $count = mysqli_num_rows($search_result);
while($row = mysqli_fetch_array($search_result2)):?>
    <tr>

        <td align="center" style='border: solid 1px black;'><?php echo $row['emp_location'];?></td>

    </tr>
<?php endwhile;?>

    </table>
    <?php echo ("$count") ." ". ("Students");?>
</div>
<div>
<form action="allocation.php" method="post">
<p style="margin-left: 600px; height: 30px; width: 400px;">
<input type="submit" value="Gereate Allocation"/>
</p>
</form>
</div>

And Database:

<?php

    if (isset($_REQUEST['submit'])){
        $query = "SELECT * FROM student";
        $search_result =filterTable($query);


    }
    else {
        $query = "SELECT * FROM `student`";
        $search_result =filterTable($query);


    }
    if (isset($_REQUEST['submit2'])){
        $query2 = "SELECT * FROM employer";
        $search_result2 =filterTable($query2);


    }
    else {
        $query2 = "SELECT * FROM `employer`";
        $search_result2 =filterTable($query2);


    }

    function filterTable($query)
    {
        $connect=mysqli_connect('127.0.0.1', 'root', 'root',"web");
        $filter_Result = mysqli_query($connect,$query);
        return $filter_Result;
    }
    function filterTable2($query2)
    {
        $connect=mysqli_connect('127.0.0.1', 'root', 'root',"web");
        $filter_Result2 = mysqli_query($connect,$query2);
        return $filter_Result2;
    }
?>




Aucun commentaire:

Enregistrer un commentaire