0

Guys I need ur help please >=<
I finished adding database and all but i need help with search can someone help me?
The description is this

Display the student’s id, name and contact number ONLY in tabular format. The data must be sorted according to the student’s id, hence no duplication of student’s id is allowed.

I will be very happy if u will help me out :)
I am using WAMP Server
Thanks and Regards,
NoobPHP

3
Contributors
4
Replies
5
Views
5 Years
Discussion Span
Last Post by akmozo
0

SELECT studentid, name, contact_number FROM student order by studentid

Connect to your database and run the query. I take it that each record in your database has a unique key and that that key is studentid. if so, then you should not get any duplicates.

Is something like this what you were looking for? You can output the results from the search into a table that is built dynamically by php so it doesn't matter how many records you have, the php will create the table accordingly. You can control programatically the size of the table and use css to style the table to match your page.

0

this is html

        <html>

        <head>
        <title>Searching for a student...</title>
        </head>

        <body bgcolor=#ffffff>

        <h2>Search</h2>

        <form name="search" method="post" action="search.php">
        Seach for: <input type="text" name="find" /> in
        <Select NAME="field">
        <Option VALUE="studentNo">Student Number</option>
        </Select>

        <input type="submit" name="search" value="Search" />
        </form>

        </body>

        </html>
this is the php code
    `<?php


        $host_name = "localhost";
        $user_name = "root";
        $password = "";
        $db_name = "academicform";
        $con = mysql_connect($host_name,$user_name,$password);
        $db_select = mysql_select_db($db_name,$con);

        if(isset($_POST['q']))
        {
            $qry = "SELECT `stuno`, `fullname`, `contno` FROM `details` WHERE `stuno` = '".$_POST['q']."'";
            $res = mysql_fetch_array(mysql_query($qry));
        }
        $rows = mysql_query("SELECT `stuno` FROM `details`");
    ?>
    <form method="post">
        <select name="q" onChange="javascript:this.form.submit();">
            <option value="">Student Number</option>
            <?php while($row = mysql_fetch_array($rows)){ ?>
            <option value="<?php echo $row['stuno']; ?>" <?php if($_POST['q'] == $row['stuno']) {?> selected="selected" <?php } ?>><?php echo $row['stuno']; ?></option>
        <?php } ?>
        </select>
    </form>
    <?php if(@mysql_num_rows(mysql_query($qry))){ ?>
    <table border="0">
        <tr>
            <td>Student Number : </td>    <td><?php echo $res['stuno']; ?></td>
        </tr>
        <tr>
            <td>Full Name : </td> <td><?php echo $res['fullname']; ?></td>
        </tr>
        <tr>
            <td>Contact Number : </td>        <td><?php echo $res['contno']; ?></td>
        </tr>
    </table>
    <?php } ?>`

but it doesnt show anything ><

0
This is some code that I use to populate a table in html from a mysql database through php. will something like this help you?

$query1="select * from events order by event_date desc";

$result=mysql_query($query1) or die(mysql_error()); 

echo "<div align=\"center\">";
echo "<table class=\"hovertable\" width=\"100%\">";
echo "<tr>";
echo "<th>Event Type</th>";
echo "<th>Event Date (yyyy-mm-dd)</th>";
echo "<th>Event Location</th>";
echo "</tr>";

while($row=mysql_fetch_array($result))
{
echo "<tr onmouseover=\"this.style.backgroundColor='#ffff66';\" onmouseout=\"this.style.backgroundColor='#E5E5E5';\">";
echo "</td><td>";
echo $row['event_type'];
echo "</td><td>";
echo $row['event_date'];
echo "</td><td>";
echo $row['event_location'];
echo "</td></tr>";
}
echo "</table>";
mysql_close($connect);
?>
0

Hi,

1 - In your html code you have used an input text named find and in your search.php page you work with p, so you should change the input text name to p if you want that search.php find your student.

<form name="search" method="post" action="search.php">
    Search for: <input type="text" name="**find**" /> in
    <Select NAME="field">
        <Option VALUE="studentNo">Student Number</option>
    </Select>
    <input type="submit" name="search" value="Search" />
</form>

2 - If your search.php page dont show a select so you should verify your database (data : did you insert some students) and the connection parameters.

Edited by akmozo

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.