
CaptainSlow
Members-
Posts
11 -
Joined
-
Last visited
Never
Profile Information
-
Gender
Not Telling
CaptainSlow's Achievements

Newbie (1/5)
0
Reputation
-
[quote author=xProteuSx link=topic=114424.msg465588#msg465588 date=1163104924] I am not sure what you are showing. You have double quotes and periods all over the place. You might very well be right, but I am too confused to know where to add all the quotes and the periods. [/quote] I didn't really show double quotes and periods all over the place. If you look at the code that I submitted you will notice that for each line a double quote is added to signify a string and at the end of each line there is another double quote followed by a period which signifies the end of a string (double quote) and an indicator that states this string will be appended to the next string (the period).
-
Thanks for the help and tips shoz! I'll give it a try later today.
-
I am somewhat of a new user to with regards to PHP and MySQL but when creating a statement like that do you not need double quotes around the whole thing? For example: [code] <?php $sql = "CREATE TABLE users ( ". "'users_id' int(6) NOT NULL auto_increment, ". "....(rest of code)..... ". "UNIQUE('users_handle') ". ") TYPE=MYISAM;"; ?> [/code]
-
Thanks for the reply pnj, however I'm not quite sure I understand how that is better. Within this example I know which courses and course numbers George is wanting to change however in the real world the only thing I will know is that an array of selected courses will be passed from the form page to the processing page and any combination of courseIDs could be in that array. Therefore I wouldn't know what criteria, other than the instID, to enter into the WHERE clause. In order for me to use the way you suggested I think I would have to get the array, determine which courses are NOT in the array, determine whether the instructorCourse table has entries for the courses that are no longer in the array, if so then delete the rows, otherwise enter the new courses from the array. To me this sounds really complicated though I might be making it more complicated than it seems. Perhaps offering a different example and getting help on that will help me understand how my approach is wrong or whether the approach proposed by pnj will fit my needs: George decides he still wants to teach courseID 1 (reading), not longer wants to teach courseID 4 (science), and wants to start teaching courseID 2 and 3 (math and cooking). In the final implementation of my application (not sure if that's the correct term) there will be 29 different courses and instructor can teach and from what I've seen of the real data some instructors are associated with up to 12 different courses. This may make my code (DELETE FROM instructorCourse WHERE instID = 1;) a poor choice to use due to its inefficiency, however, it's the only approach I really understand at this point.
-
I did play around with the code you gave me and it does exactly what I need. Also, thanks for adding the additional PHP code that creates arrays for courses George can teach and cannot teach. I have written code previously that parses data from an array and enters it into the text area. However I do have another issue I was concerned about. So at this point George can teach courses 1 and 4 which are reading and science respectively. However, using the method I have implemented (javascript) he moved courses 1 and 4 (reading and science) to the left text box (pool of all courses) and to the right text box (courses instructor can teach) he moved the courses 2 and 3 (math and cooking). So after this George can now ONLY teach 2 and 3, math and cooking, and he CANNOT teach courses 1 and 4, reading and science. Now that I have these values how do I enter them into the 'instructorCourse' table while removing the old values relating to the courses he cannot teach (1 and 4, reading and science)? My only thought was before entering the values I would execute this query: [CODE] DELETE FROM instructorCourse WHERE instID = 1; [/CODE] This would then remove the rows: instID skillID 1 1 1 4 After doing that I would just enter the new courses into the table using an INSERT command. Is this the correct way to approach this or am I doing something wrong?
-
What does [code]IF (ISNULL(ic.courseID), 0, 1)[/code] mean? I wasn't aware that you were able to add IF statements in SQL queries. Actually I think I may have figured it out. Let me know if this is correct. If the ic.courseID of $instID is null enter a zero otherwise enter a 1.
-
Hey there! I've got a SQL question that I hope I can get some help on. I'll first start with some back story to help you understand what I'm trying to do and then I'll go to my question. Here the problem (tables have been simplified). I've got three tables. First, I have an instructor table with fields for an instID, fname, and lname. I then have a table called course with fields for courseID, courseName. Finally, I have a table called instructorCourse with fields instID, courseID. Both these fields are primary and foreign keys. This table lists all the courses an instructor can teach. As a data example say I have the following in each table: Instructor ID fname lname 1 George Costanza Courses ID courseName 1 reading 2 math 3 cooking 4 science instructorCourse instID courseID 1 1 1 4 So essentially George Costanza can teach reading and science. What I want to do is have two text areas on form, side by side. The first text area (left side)will list the courses George CAN teach (in this case, 1 and 4, or reading and science) and the second text area (right side) will list the courses George CANNOT teach (in this case, 2 and 3, or math and cooking). Any idea as to what kind of SQL statement I will need to do this? I think I know how to display the courses he can teach but I have no idea on how to list the courses he cannot teach. Any help would be greatly appreciated. P.S. I am using PHP to get the SQL results from the MySQL DB. Thanks again!
-
Multi-Select Transfer Box + Javascript + PHP + MySQL
CaptainSlow replied to CaptainSlow's topic in PHP Coding Help
[quote author=sasa link=topic=113429.msg463160#msg463160 date=1162711715] change[code]<SELECT NAME="chosen" SIZE="4"[/code] to [code]<SELECT NAME="chosen[]" id="chosen" SIZE="4"[/code] [/quote] Wow, thanks that worked! Do you have any explanation as to why that worked? When I was trying to figure it out for myself I tried just making the name value an array (NAME = "chosen[]") rather than adding the id parameter and it essentially broke the transfer boxes. Also, what does the parameter "id" mean exactly. I asked a friend and he told me it was mainly used for CSS. Because of this I have not been using the id parameter in any of my code. Is this okay or should I be adding it to all my HTML code? -
Multi-Select Transfer Box + Javascript + PHP + MySQL
CaptainSlow replied to CaptainSlow's topic in PHP Coding Help
Anyone have any ideas or suggestions? -
Multi-Select Transfer Box + Javascript + PHP + MySQL
CaptainSlow replied to CaptainSlow's topic in PHP Coding Help
[quote author=HuggieBear link=topic=113429.msg460990#msg460990 date=1162372457] Are you getting the same response in both IE and Firefox? What browser are you using? Regards Huggie [/quote] I get the response in both Internet Explorer and Firefox. The browser I am using currently for testing is FireFox 2.0. -
Hello! I'm having a bit of trouble with an application I'm trying to write and could use some assistance. I have two major questions but I will provide some background that may help. I have a database containing a table called Courses. Within this table there are two columns: courseID and courseName. Here's what the table looks like: [table] [tr] [td] courseID [/td] [td] courseName [/td] [/tr] [tr] [td] 1 [/td] [td] Cooking [/td] [/tr] [tr] [td] 2 [/td] [td] Math [/td] [/tr] [tr] [td] 3 [/td] [td] Science [/td] [/tr] [tr] [td] 4 [/td] [td] Gym [/td] [/tr] [/table] Now what I wanted to do was add a feature on a form that two select boxes: the one on the left displayed all the course names and the one on the right would hold courses that the user added. Along with these two boxes there would be two buttons in the middle: one to transfer a course from the left to the right and one to transfer a course from the right to the left. I found the javascript code that could help me with this from http://www.quirksmode.org/js/transfer.html (if you don't understand what I am trying to describe they show an example there). After some minor editing I came up with this code: [code] function copyToList(from,to) { fromList = eval('document.forms[0].' + from); toList = eval('document.forms[0].' + to); if (toList.options.length > 0 && toList.options[0].value == 'temp') { toList.options.length = 0; } var sel = false; for (i=0;i<fromList.options.length;i++) { var current = fromList.options[i]; if (current.selected) { sel = true; if (current.value == 'temp') { alert ('You cannot move this text!'); return; } txt = current.text; val = current.value; toList.options[toList.length] = new Option(txt,val); fromList.options[i] = null; i--; } } if (!sel) alert ('You haven\'t selected any options!'); } function allSelect() { List = document.forms[0].chosen; if (List.length && List.options[0].value == 'temp') return; for (i=0;i<List.length;i++) { List.options[i].selected = true; } } <FORM method = "POST" onSubmit="allSelect()" action = "process.php"> <TABLE> <tr> <td> <SELECT NAME="possible" SIZE="4" MULTIPLE WIDTH=200 STYLE="width: 200px"> <OPTION VALUE="1">Option 1: Cooking <OPTION VALUE="2">Option 2: Math <OPTION VALUE="3">Option 3: Science <OPTION VALUE="4">Option 4: Gym </SELECT> </td> <td><A HREF="javascript:copyToList('possible','chosen')">--></A><BR> <A HREF="javascript:copyToList('chosen','possible')"><--</A> </td> <td> <SELECT NAME="chosen" SIZE="4" MULTIPLE WIDTH=200 STYLE="width: 200px"> <OPTION VALUE="temp">Make your choice on the left </SELECT> </td> </tr> <tr> <td><input name = "submit" type = "submit" value = "sumbit form"></td> </tr> </TABLE> </FORM> [/code] Now the problem I seem to be having is trying to access the form variables (particularly the ones in the right box) so I can enter them into the MySQL database. My process.php is just displaying the variables that were passed to that page and it looks like this: [code]<?php echo "<PRE>"; print_r($_POST); echo "</PRE>"; ?>[/code] And here's the output I get when I press submit and get to that particular page: [pre]Array ( [chosen] => 4 [submit] => sumbit form ) [/pre] I am mainly concerned with the [chosen] array. [b]How do I access all the variables that were in there?[/b] I add 2-3 courses and press submit but the only result I get is the last option that was submitted (in this case, option 4). My second question is somewhat similar and involves the select boxes again. Say I have a teacher that has courses associated with them in the database (i.e math and cooking). [b]Is there an easy way to make it so that when the two boxes load on an instructor edit page the left box has the courses that the instructor is already associated with, in this case math and cooking, and the right box has the courses that the instructor is not associated with, in this case science and gym?[/b] I thank you for any help you can give and I know most of my questions involve javascript with a little bit of PHP but I was told that this community is very helpful in all subjects involving web programming. If this question is not on topic let me know and I can try and find a more suitable forum. Thanks again!