uisneach Posted October 10, 2008 Share Posted October 10, 2008 hello I have a form with 6 drop down menu - it's about the chance to enter cancellation of trains I want people entering e.g a day when the trains has been cancelled Every values is taken from the drop down menu like this the people from the web page mask will choose from the list in the ddm the day, month, year, scheduled hour of train, direction, if the cancellation has been announced or not (yes/no, the choice in the drop down menu) So...My purpose is to enter in the mysql table only one time if is the same train.It's possibile, indeed, that e.g. three people enter for the same train, their values. I would like that php recognize the train has already been entered (eg. 1-10-2008, North(direction), 12.00 (hour scheduled)) while the only thing will change will be if has been yes or not (announced). So, I want only a row in the web page for the same train. php must be able to recognize taht the train problem hase been already reported, and does not add a new row for the same train. I create a table with different field in mysql $ day= $_POST[' day']; // it's $mese= $_POST['']; //month $year = $_POST['year']; // $scheduled_time = $_POST['scheduled_time']; // $direction = $_POST['direction ']; // $announced = $_POST ['announced']; //cancellation $sql = "INSERT INTO cancellation_train (day, month, year, scheduled_time,direction, announced) VALUES ('$day','$month','$year','$scheduled_time','$direction','$announced')"; $result = mysql_query($sql); The table "cancellation_train" will have same fields plus id (primary key) I want that php knows that first 5 fields identify a train and don't print again another row, but count only the number of reports thanks uisneach Quote Link to comment Share on other sites More sharing options...
R0bb0b Posted October 10, 2008 Share Posted October 10, 2008 You will need to add a column to the table called something like "report_amt" to keep track of the number of reports. Then, when a user submits you will query the database for the primary key of the row using all of the posted data except you will leave the column "announced" out since that can differ. If you get a row back, which if done right, there should only be one, you add 1 to the "report_amt" column. I forget(I know you can in postgres) if you can create a combined column unique constraint but you may want to do that for all of the columns except "report_amt", "announced" and your primary key. Quote Link to comment Share on other sites More sharing options...
uisneach Posted October 10, 2008 Author Share Posted October 10, 2008 Thanks Rob, I'm goona try If you want i post you the link where entering the values so you can have a better clue.? paolo p-.s. is in italian but i might explain you the few words ritardo=delay annunciata=announced the remainder is intuitive Quote Link to comment Share on other sites More sharing options...
uisneach Posted October 10, 2008 Author Share Posted October 10, 2008 To query the primary key? $sql = "SELECT * FROM train_cancellation ORDER BY id, day, month, year, hour, direction Anyone has a clue? thx and bye Quote Link to comment Share on other sites More sharing options...
budimir Posted October 10, 2008 Share Posted October 10, 2008 ?? $sql = "SELECT * FROM train_cancellation WHERE id = '$id' ORDER BY id, day, month, year, hour, direction"; ?? Quote Link to comment Share on other sites More sharing options...
R0bb0b Posted October 10, 2008 Share Posted October 10, 2008 The primary key is usually just a numeric column that people set to be auto incrementing. This makes it unique for each row so that you can identify it in your where clause whenever you want to update or delete a row. Quote Link to comment Share on other sites More sharing options...
uisneach Posted October 10, 2008 Author Share Posted October 10, 2008 @rob thanks @budimir. May I ask you which value fills the $id? Thnks and sorry but my php skills is still low, really paolo:) Quote Link to comment Share on other sites More sharing options...
budimir Posted October 10, 2008 Share Posted October 10, 2008 $id is ID field form DB in table cancellation_train As you wrote: The table "cancellation_train" will have same fields plus id (primary key) So, if you want info about some train you do: $id = 4; //this is just an example $sql = "SELECT * FROM train_cancellation WHERE id = '4' ORDER BY id, day, month, year, hour, direction"; Hope it's more clear now... Quote Link to comment Share on other sites More sharing options...
live_to_love Posted October 10, 2008 Share Posted October 10, 2008 Just a sudocode tip. Since you are ordering by the keys, as you loop thru the result, you can save the keys concatenated into another var "saveKeys" The before you print it check if the key has changed. --- in the result loop --- If saveKkeys != key1.key2...keyx { print records saveKeys=key1.key2...keyx --- in the result loop --- } hug Quote Link to comment Share on other sites More sharing options...
uisneach Posted October 10, 2008 Author Share Posted October 10, 2008 @budimir ??? sorry but I am really poor in programming The problem for me is to print a combination only if the sequence is not present yet 1|10|2008|12.00|North|yes could be the entry of an user. (corresp to day, month, year, scheduled_time, direction, announced ARE ALL fields of drop down menu and columns in the table "train_cancelled" with same name. I don't want to print id cause i don't care about it. but probabily you said sometihing right I missed, sorry, i really don't get it. anyway, if php found a record with all the 5 entries already in the table(same combination) , I don't want it to be printed on the screen the ideal would be not to add in the table another record, not only not printing on the screen as if the combination is already present, i am interested only in the number of yes/not @livetolove: thanks you too. i tried to create a variable savekeys with concatenation like that, but it doesn't insert any record on table, even if the combination is not present My brain is grilling, I knock off just 10 minutes see ya late, and thanks lads sorry! Quote Link to comment Share on other sites More sharing options...
uisneach Posted October 15, 2008 Author Share Posted October 15, 2008 Hello eb This is the solution, (after long time spent, eventually!!) it was necessary to use the SELECT . In this way, php recognize the rows inserted where the considered values (in a row) are inserted (already) as it means a train has been already reported thx for eb for effort to help me anyway I appreciated ...Here it is $sql11="SELECT * FROM train_delays WHERE day = '$day' AND month = '$month' AND year = '$year' AND hour = '$hour' AND direction = '$direction'"; $result = mysql_query ($sql11); $num_rows = mysql_num_rows($result); the prob is solved Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.