09-23-2005, 06:43 PM
I have created a mysql databse with one master table with several slave tables. Now I created an update table that updates the master and all slave tables. The update table received the form variable (studentid) from a page where I select the student from another form. Now it is the form on the other page that passes studentid onto the update page that I am having issues with. I am in the process of learning php/mysql but need to get this working alot faster than I will be done the courses.
I need the form to have a pull down menu that lists the last, middle, and first name of the student. Then the form passes the studentid of the that student on to the update page. Now the last, middle, and first name are in three different columns in the database. I am not sure how to create this form at all. Detailed help is appreciated.
09-24-2005, 10:34 AM
Can you provide us with your database schema? I am confused by how you are explaining the setup for it.
If I read this correct, you are saying you have a database table, with at least three different columns, Firstname, Lastname, and Middlename. I would also assume you have an Id (studentid) which is an autoincrementing number. As I understand it, you want to create a select menu listing all students names is that correct? I'm not certain if this is accurate, let alone how your update pages work, but thats not the issue right now.
To create a list of all fields, do a query for all fields:
$query = mysql_query("SELECT `studentid`, `firstname`, `middlename`, lastname FROM `students` ORDER BY lastname ASC");
if (mysql_num_rows($query) > 0)
echo "<select name=\"selectname\">\n";
while ($rows = mysql_fetch_assoc($query))
echo "<option value=\"" . $rows['studentid'] . "\">" . $rows['lastname'] . ", " . $rows['firstname'] . " " . $rows['middlename'] . "</option>\n";
You can also select rows based on certain criteria, studentid for example, by putting that into the query using a WHERE clause. You can generate the data required for this using a request method: $_GET, $_POST, $_REQUEST, $_COOKIE, $_SESSION, etc, but you need to know how to clean these variables so as to prevent sql-injections.
Another thing to watch for is your number of rows, be kind to the users browser. The longer the select list (or generally more select lists will cause problems), the more likely the browser will become unstable. To counteract this, I would recommend instead setting a alphabetical listing, where the user selects what letter the last name starts with and querying the database using a LIKE clause.
Is this along the idea you are looking for? If it is, I can give you more help with it. If not, can you explain a little more indepth what it is you are looking for?
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.