PHP - Moved: Working With Tables
This topic has been moved to HTML Help.
http://www.phpfreaks.com/forums/index.php?topic=342956.0 Similar TutorialsI am entering a question and notes into one table and creating an ID number in Table 1: $qid (Question ID) $question $notes I am then entering an answer and creating an ID for the answer which sites next to question ID in Table 2: $aid (Answer ID) $answer I am now trying to transfer the Question ID into Table 2. I am currently trying to do this as a hidden string: <input name="category" type="hidden" value="$qid" id="qid" > Does any one have any advice on how I can use two fields. Can I display or insert data with the same php script? holla everybody so back again with another crazy question am working on a small database with 3 to 4 tables. need at least 3 tables. the problem is that if i work with two of them, it works perfectly, as soon as i add the 3rd one, and try to edit a record, it edits only the 1st row and not all the rows required the first table is called "perso" containing the personal data of the employees the second table is called "center" this contains the information of the starting and ending dates of an employee on a center. the third table is called "dp" it contains the workplan of the employee all the 3 tables have a common fiield "pid" which is identical now i want the form to display alle the records suppose in the department IT, the workers have their plan of starting their work on a certian center on a certian date to a certian date. usually 2 weeks to a month. they should therefor appear on the plan of the specified center. it is simple if i am using the dp and center tables, but i want the perso table too so that i can display the names according to the pid. and maybe some other tables containing information of vacation etc. but as i said, as soon as i add the 3rd table to the query, it breaks down. please check the code: // the form code <? require "db_credentials.php"; // here is the problem, in the following query, if i add "from dp, perso, center where dp.pid = center pid it wont work. but as long as it looks like below, it works find... $result=mysql_query("select * from dp, perso where dp.pid = perso.pid order by dp.id asc"); // Fetch record rows in $result by while loop and put them into $row. while($row=mysql_fetch_assoc($result)){ ?> // then the table with cells filled with such code: <? echo $row['FirstName'] . " " . $row['LastName']; ?> <select name="monday_<? echo $row['id']; ?>" id="select3"> <option>Select</option> <option style="background-color:#FF0000 ">FDLS</option> <option style="background-color:#FF0000 ">FDFD</option> //and so on till sunday again <? } // End while loop. ?> ********************************************* <? if($_POST['Submit']){ // Connect database. $host="mysql"; $db_user="name"; $db_password="password"; $database="my_db"; mysql_connect($host,$db_user,$db_password); mysql_select_db($database); $result=mysql_query("select id from dp order by id asc"); while($row=mysql_fetch_assoc($result)){ $mo=$_POST["monday_".$row[id]]; mysql_query("update dp set Mo='$mo'' where id='$row[id]'"); } echo "--- DB Updated---"; } ?> ================================ all help will be very much appriciated thanks in advance So I have 2 tables, a student table and a course table. When I add a new course to my course table it should be available to students to sign up for which goes into the student table when they do. However now I have to create a page which displays the different courses (course table) and when you click on a course it should display all the users registered for that specific course. Also when a course gets deleted all the student registered for that course should be deleted. So deleting a course in the course table should delete student in the student table.. I have already created a page which display the different course information and I am familiar with creating pages that allows you to delete table info from the page. However, I am lost on how to display the students when clicking on the course and how to link the 2 tables so when deleting a course it deletes the students aswell. Where should I begin with this and how should I go about it? This is my code up until now for displaying the different courses: Code: [Select] <?php $query=mysql_query("SELECT * FROM course "); while ($rows = mysql_fetch_array($query)): $cname=$rows['cname']; $cid=$rows['cid']; echo "<table> <tr> <td> $cname </td> <td> $cid </td> </tr> </table> "; endwhile; This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=356714.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=308889.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=312429.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=352310.0 This topic is now in MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=357554.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=330205.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=306274.0 This topic has been escorted to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=354341.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=331758.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=353621.0 This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=345725.0 hi everybody simply love this forum because i always get the question perfectly answered. i am here this time with a rather complicated question: i am creating a simple duty plan for different departments for exeample department #1 is "Tech" and department #2 is "Service" different employees working in these departments change their dutys and will are sent to another department or section or go on holidays. this is why i have at least 4 different mysql tables to store the data:- personel(storing the personal information of the workers) dutyplan(storing the week's working daysy of the workers) departments(storing the starting and ending dates of the department change) vacation(stores the start and ending dates of the vacations) in all the tables the common id is the pid which is issued unique to every worker. i am still able to work only with the 1st two tables. i can edit and create new plans for the weeks for employees working in the departments with the following php code(submitting only to edit the plan) if i add a date range for example Monday the 24th of January to Sunday the 30th of January for an employee working in the Tech department to work a few days in service department, it will show the employee in the week on the plan of both departments. if both department heads edit the plan without communicating to each other, and knowing on which date the worker goes out and in to the department, the 1st one will plan him for the whole week on his dutyplan and the second department head will overwrite this plan(if edited) or if creating a new plan(create the duty of the worker also one more time). i want to avoid this confusion and manual work. the same is with the vacation or sickness tables, if the employee has vacation, the program should check and return the selected value in the pulldown menu with the value stored in the vacation or sickness tables appropriate to the date in the plan table. ************************************************************************ form.php: <? require "config.php"; $result=mysql_query("select * from personel, dutyplan, department, vacation WHERE personel.pid = dutyplan.pid and personel.pid = vacation.pid and dp.pid = departments.pid and departments.Section = 'Service' order by dp.id asc"); ?> <? while($row=mysql_fetch_assoc($result)){ ?> // after that i create table, displaying all the days of the week from monday to sunday and use this code <tr> <td><? echo $row['FirstName'] . " " . $row['LastName']; ?>: </td> <td> <select name="monday_<? echo $row['id']; ?>" id="select1"> <option><? echo $row['Mo']; ?></option> <option>Duty</option> <option>Free</option> <option>Vacation</option> //the same way down to sunday, for every day the different options to be selected. it displays the records perfectly, as long as there is no change of department planed and the vacation must also be selected manually. +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ update.php <? if($_POST['Submit']){ require "includes/config.php"; $result=mysql_query("select * from dutyplan, departments, vacation order by dutyplan.id asc"); while($row=mysql_fetch_assoc($result)){ $mo=$_POST["monday_".$row[id]]; $tu=$_POST["tuesday_".$row[id]]; $we=$_POST["wednesday_".$row[id]]; $th=$_POST["thursday_".$row[id]]; $fr=$_POST["friday_".$row[id]]; $sa=$_POST["saturday_".$row[id]]; $su=$_POST["sunday_".$row[id]]; mysql_query("update dp set Mo='$mo', Tu='$tu', We='$we', Th='$th', Fr='$fr', Sa='$sa', Su='$su' where id='$row[id]'"); } echo "Records updated"; } ?> **************************************************** how would you gueys solve this problem? many thanks in advance This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=322398.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=354388.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=348013.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=334481.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=305750.0 |