PHP and script.aculo.us Web 2.0 Application Interfaces- P8
Số trang: 30
Loại file: pdf
Dung lượng: 1.23 MB
Lượt xem: 15
Lượt tải: 0
Xem trước 3 trang đầu tiên của tài liệu này:
Thông tin tài liệu:
PHP and script.aculo.us Web 2.0 Application Interfaces- P8: script.aculo.us là một thư viện JavaScript cung cấp các hiệu ứng thị giác năng động, điều khiển giao diện người dùng, và các tính năng mạnh mẽ AJAX. Đó là những gì phụ-client PHP là phía máy chủ - mạnh mẽ, đơn giản, vui vẻ hoàn tất, và trên tất cả, PHẢI một! Theo các nhà phát triển, chúng tôi tất cả ước mơ xây dựng các ứng dụng mà người sử dụng ngay lập tức có thể rơi vào tình yêu với và nhận được hiệu quả. Đơn giản và các...
Nội dung trích xuất từ tài liệu:
PHP and script.aculo.us Web 2.0 Application Interfaces- P8 Chapter 11Now, when the user submits a tutorial, an alert message will be displayed to theuser. If the tutorial does not exist, the next page will be shown where the user canadd the title, description, and tags.Adding title, description, and tags tothe tutorialNow that the user has submitted the tutorial and we have checked that the tutorialdoes not exist already, its time to add the title, description, and tags to the newlyadded tutorial through tutorialDetails.php.Lets first quickly create a user interface to add the title, description, and tags. Enter a title for the tutorial Enter description for the tutorial [ 199 ]Creating Delicious and Digg Bookmarks Manager Enter Tags for the tutorial Chapter 11We will read the user ID through $_SESSION, and the details of the tutorials postedby the user using $_POST. $ownerid = $_SESSION[uid]; $tutorialID = $_POST[tutorialID]; $title = $_POST[title]; $desc = $_POST[desc]; $tags = $_POST[tags];We have all the details of the tutorials. So, lets update the same in the database. Inthe tutorials class we have a function for adding the tutorials description calledadd_tutorial_desc($title, $desc, $tutorialID). function add_tutorial_desc($title, $desc,$tutorialID){ $query = UPDATE tutorials SET tutorial_title=.$title ., tutorial_desc =.$desc. WHERE tutorialID =.$tutorialID ; return $query; }We will insert the details of the tutorials using the query as follows: $query = UPDATE tutorials SET tutorial_title=.$title ., tutorial_desc =.$desc. WHERE tutorialID =.$tutorialID ; For now, we are not adding any details about the tags. It needs a separate explanation that is covered in next section.The resulting user interface after adding the details is as follows:We also give a link to viewTutorial.php with the ID so that the user can see therecently added tutorial. [ 201 ]Creating Delicious and Digg Bookmarks ManagerView tutorialIn the previous section we successfully created a tutorial. We were able to readback tutorialID of the latest inserted tutorial. Now, lets create a script calledviewTutorial.php that will take tutorialID via $_GET.We need to query the database table tutorials for details with tutorialID as thelast inserted ID.The following is the query to read the values for the recently inserted tutorial: $query=SELECT * FROM tutorials WHERE tutorialD=.$tutorialID;The query returns an array with all the details of the particular tutorial. Loop thedetails, decorate it with CSS, and display it to the user. We have used the same logic and steps for reading the details of the list in our todonow application in Chapter 10. Refer to the viewList.php script.Deleting tutorialsIts not enough to just submit tutorials. Sometimes, we realize that we have made themistake of submitting a wrong tutorial. So, its important to have a mechanism todelete the unwanted tutorials.We refer to these basic set of actions as CRUD, which stands for Create, Read,Update, and Delete. In this section we will be creating our delete function for thetutorials using the AJAX way.In the user profile page we will see all the tutorials submitted by the user. Alongwith each tutorial, we will also have the links for editing and deleting the tutorial.The point is to do it in such a way that we use an AJAX call and do not take the userto a new page.We will prompt the user with a JavaScript confirmation message to verify whetherthe user really wants to delete the tutorial. [ 202 ] Chapter 11Take a look at the following screenshot to see what happens when a user clicks onthe Delete link:When the user clicks on Cancel, nothing happens. If the user clicks on OK, thefollowing steps take place in the given sequence: 1. Read the tutorialID. 2. Read the tableID and rowID. 3. Delete the child row from the table. 4. Call the AJAX function to delete the data from the database. 5. Use the effects to highlight the updated row.While presenting the information about the tutorials submitted by the user, we alsoread tutorialID and place it under the Delete link along with the ID.The tutorial ID will be passed by calling a JavaScript function deleteTutorial(ID). function deleteTutorial(id) { var result = confirm(Are you sure you want to delete?); if(result==true) { deletechildrow(mytutorials-table,id); } } [ 203 ]Creating Delicious and Digg Bookmarks ManagerThis function in return calls another JavaScript function deletechildrow(tableID,rowID), where we actually delete the child row from the table. function deletechildrow(tableID,rowID) { var d = document.getElementById(tableID); var olddiv = document.getElementById(rowID); d.deleteRow(olddiv); alert(Tutorial Deleted); }Did we miss out anything? Yes, we did! We did not make a remote call to the serverto delete the tutorial. I leave it to you to make that call.Lets add a little spice of effects while deleting the child row from the table. new Effect.Highlight($(id)); ...
Nội dung trích xuất từ tài liệu:
PHP and script.aculo.us Web 2.0 Application Interfaces- P8 Chapter 11Now, when the user submits a tutorial, an alert message will be displayed to theuser. If the tutorial does not exist, the next page will be shown where the user canadd the title, description, and tags.Adding title, description, and tags tothe tutorialNow that the user has submitted the tutorial and we have checked that the tutorialdoes not exist already, its time to add the title, description, and tags to the newlyadded tutorial through tutorialDetails.php.Lets first quickly create a user interface to add the title, description, and tags. Enter a title for the tutorial Enter description for the tutorial [ 199 ]Creating Delicious and Digg Bookmarks Manager Enter Tags for the tutorial Chapter 11We will read the user ID through $_SESSION, and the details of the tutorials postedby the user using $_POST. $ownerid = $_SESSION[uid]; $tutorialID = $_POST[tutorialID]; $title = $_POST[title]; $desc = $_POST[desc]; $tags = $_POST[tags];We have all the details of the tutorials. So, lets update the same in the database. Inthe tutorials class we have a function for adding the tutorials description calledadd_tutorial_desc($title, $desc, $tutorialID). function add_tutorial_desc($title, $desc,$tutorialID){ $query = UPDATE tutorials SET tutorial_title=.$title ., tutorial_desc =.$desc. WHERE tutorialID =.$tutorialID ; return $query; }We will insert the details of the tutorials using the query as follows: $query = UPDATE tutorials SET tutorial_title=.$title ., tutorial_desc =.$desc. WHERE tutorialID =.$tutorialID ; For now, we are not adding any details about the tags. It needs a separate explanation that is covered in next section.The resulting user interface after adding the details is as follows:We also give a link to viewTutorial.php with the ID so that the user can see therecently added tutorial. [ 201 ]Creating Delicious and Digg Bookmarks ManagerView tutorialIn the previous section we successfully created a tutorial. We were able to readback tutorialID of the latest inserted tutorial. Now, lets create a script calledviewTutorial.php that will take tutorialID via $_GET.We need to query the database table tutorials for details with tutorialID as thelast inserted ID.The following is the query to read the values for the recently inserted tutorial: $query=SELECT * FROM tutorials WHERE tutorialD=.$tutorialID;The query returns an array with all the details of the particular tutorial. Loop thedetails, decorate it with CSS, and display it to the user. We have used the same logic and steps for reading the details of the list in our todonow application in Chapter 10. Refer to the viewList.php script.Deleting tutorialsIts not enough to just submit tutorials. Sometimes, we realize that we have made themistake of submitting a wrong tutorial. So, its important to have a mechanism todelete the unwanted tutorials.We refer to these basic set of actions as CRUD, which stands for Create, Read,Update, and Delete. In this section we will be creating our delete function for thetutorials using the AJAX way.In the user profile page we will see all the tutorials submitted by the user. Alongwith each tutorial, we will also have the links for editing and deleting the tutorial.The point is to do it in such a way that we use an AJAX call and do not take the userto a new page.We will prompt the user with a JavaScript confirmation message to verify whetherthe user really wants to delete the tutorial. [ 202 ] Chapter 11Take a look at the following screenshot to see what happens when a user clicks onthe Delete link:When the user clicks on Cancel, nothing happens. If the user clicks on OK, thefollowing steps take place in the given sequence: 1. Read the tutorialID. 2. Read the tableID and rowID. 3. Delete the child row from the table. 4. Call the AJAX function to delete the data from the database. 5. Use the effects to highlight the updated row.While presenting the information about the tutorials submitted by the user, we alsoread tutorialID and place it under the Delete link along with the ID.The tutorial ID will be passed by calling a JavaScript function deleteTutorial(ID). function deleteTutorial(id) { var result = confirm(Are you sure you want to delete?); if(result==true) { deletechildrow(mytutorials-table,id); } } [ 203 ]Creating Delicious and Digg Bookmarks ManagerThis function in return calls another JavaScript function deletechildrow(tableID,rowID), where we actually delete the child row from the table. function deletechildrow(tableID,rowID) { var d = document.getElementById(tableID); var olddiv = document.getElementById(rowID); d.deleteRow(olddiv); alert(Tutorial Deleted); }Did we miss out anything? Yes, we did! We did not make a remote call to the serverto delete the tutorial. I leave it to you to make that call.Lets add a little spice of effects while deleting the child row from the table. new Effect.Highlight($(id)); ...
Tìm kiếm theo từ khóa liên quan:
phương pháp lập trình lập trình web với php ngôn ngữ lập trình php lập trình javascriptGợi ý tài liệu liên quan:
-
Giáo trình Lập trình logic trong prolog: Phần 1
114 trang 192 0 0 -
Giáo trình Lập trình C căn bản: Phần 1
64 trang 170 0 0 -
Giáo trình Lập trình C căn bản
135 trang 168 0 0 -
66 trang 154 0 0
-
14 trang 134 0 0
-
Bài giảng Phương pháp lập trình: Chương 9 - GV. Từ Thị Xuân Hiền
36 trang 112 0 0 -
Giáo trình lập trình hướng đối tượng - Lê Thị Mỹ Hạnh ĐH Đà Nẵng
165 trang 112 0 0 -
47 trang 111 2 0
-
78 trang 102 0 0
-
Giáo trình về môn Lập trình C căn bản
131 trang 50 0 0