Forum Moderators: coopster

Message Too Old, No Replies

Free PHP Script

         

Imaster

11:03 am on Nov 22, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have to make a program in PHP for a college. As I am new to php, it would be helpful if there was a script available which met my requirements or came somewhere close to it.

The database consists of students name, marks, grade, and other fields.

Now I have to use a mysql database and php script and provide a search interface where if someone enters a grade in search box, he would get all possible results of the students who have got that grade.

I hope I am clear in explaining this. If there were some php script available which revolves around the same theory, then I could do the modifications as per my needs.

Any place I could find this particular script.

TIA

Birdman

11:35 am on Nov 22, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I would recommend writing it yourself. Heck, it's not too hard and the experience would be great.

First, you'll have to decide which fields are searchable and how to determine what field the user wants to search.

The easy way would be to use radio buttons or a select option box. Then you will already know which field to do the search on when the input gets to your script.

If that is not an option and you just want a search box with a button, you will have to parse the input in your script to determine what field the user meant to search.

What are all the fields that would be searchable?

Marcia

11:47 am on Nov 22, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It might not be too easy to do from scratch if there's a deadline to meet for the project and someone has to start learning the language from the ground up.

It sounds pretty much like a search script with the data input into MySQL. There's got to be some that are easy to use over at hotscripts.com

jaski

12:20 pm on Nov 22, 2003 (gmt 0)

10+ Year Member



phpmyadmin [phpmyadmin.net] is a great application. But it probably has more power than your requirements .. like .. it allows even deleting records or dropping tables etc.

Birdman

12:26 pm on Nov 22, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You are right, Marcia. There is most certainly something there at hotscripts. I misread the post originally. I thought Imaster was doing this as a project for a course in college.

I still think it wouldn't be that bad if you were to use the select dropdown to determine the field to search.

HTML:
<form action="search.php" method="post">
Search Type: <select name="fieldname">
<option value="grade">Grade</option>
<option value="name">Name</option>
</select>
<input type="text" name="query" />
<input type="submit" value="Search" />
</form>

SEARCH.PHP:
<?php
/* connect to the db */
$dbh=mysql_connect ("localhost", "USERNAME", "PASSWORD") or die ('I cannot connect to the database.');
mysql_select_db ("NAME OF DB HERE");

/* now build query */
$sql = "SELECT * FROM tablename WHERE $_POST['fieldname'] = '$query'";

/* run the query */
$result = mysql_query($sql);
mysql_close();

/* loop and display the results */
while ($row = mysql_fetch_array($result))
{
print "$row['name'] $row['marks'] $row['grade'] etc...";
}
?>

Of course this a raw example and you would most likely want to do some error checking on the user input.

Imaster

12:37 pm on Nov 22, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What are all the fields that would be searchable?

In fact, all the fields should be searchable. For eg: If someone wants to search for a particular student, or all students with a particular grade, or all students with particular marks, etc.