Search the Community
Showing results for tags 'MySql'.
Found 3 results
-
To save your time I'll assume that my readers know what Moodle is otherwise this post will not be relevant to them. For info. about Moodle please visit the official website The Problem: Moodle has it's own reports module where you can use a well organized interface for pulling out different reports about the activities of the users. For me as a course tutor, I need to have a quick check on the assignments submitted by my students in a certain course, certain course topic. The current reports module in Moodle is not straight forward with that regard. It pulls more data than I need which kind of doesn't highlight the parts that I'm interested in. I also hate to login every time I need to check the assignments submission. Moodle usually is a bit slow script. The Solution: It would be more practical to write a code that queries the Moodle data base and displays only what I need. A wizard interface would be ideal in my situation. Just to be specific, I'm using: Moodle version: 1.9 PHP version 5.2.17 MySQL version 5.5.29-log Application Outline: 1- A code to connect to the database : db-config.php, that will be included wheneverf we need to query the database 2- The index.php includes the db-config.php and: connects to the Moodle DB query table mdl_course to select the id and fullname fields to populate a drop-down list for the user to choose. posts the user input to sections.php 3- The sections.php will: connect to the Moodle DB query table mdl_course_sections and select the sections field that match the previously selected course id. populate a drop-down list for the user to choose posts the user input to report.php 4- Finally the report.php will: connect to the Moodle DB query mdl_assignment, mdl_assignment_submissions and mdl_user using RIGHT JOIN on the id field select only the submitted assignments using WHERE ( --- OR ----) AND ------ based on the user input, ie the course and section you selected in the previous steps in the wizard. use a while loop to display the record set in a table The Code: I tried to post the code using the BBcode but it doesn't show in the preview, so I'll try to attach it. Your feedbak is most welcome Thank you db-config.phpindex.phpsections.phpreport.php
-
So often I need to query several table that are linked through some key.I never understood the difference between different types of JOIN although I used it in one of my application, but it just worked without knowing how.The main problem with using the wrong JOIN is that you get lots of duplicated records no matter you try to filter the results using WHEREMy question is general and not specific to a certain case. I only need to understand the difference between the different types of Join.Can any expert help me?Thanks
-
I got this code from this form.. from developer... who posted but he is nt replying me anything for any update so i like to do open discussion so it can make workable code.. please... First of all when i setup everything correct..... while using admin: admin and password : password and i hit login... nothing hppns stays same page, now when i enter ip and click yes to block i recievied this error "Could not Block Ip, MySql Error" ok.... after this was nt working i went to mysql db and entered ip and time by manually in that table.. now i visited .. the ipadmin.php again.. now same problem.. except.. in blocked ip list... i can see the ip added. hence my db is working connected to ... now when i select 1 ip and try to remove.. again it doesnt do anything.. ip remains der.. please some1 try this code... its very easy .. but very useful... and help me to fix the issue.. thank you the First thing we are going to do is make the form that is actually blocking the site. Note: You Must have this in a PHP file to work, it must be at the VERY TOP!!!!! klist.php ][color=#666600]<?[/color][color=#000000]php[/color][color=#000000]$vip [/color][color=#666600]=[/color][color=#000000] $_SERVER[/color][color=#666600][[/color][color=#008800]'REMOTE_ADDR'[/color][color=#666600]];[/color][color=#000000]include [/color][color=#008800]"config.php"[/color][color=#666600];[/color][color=#880000]##############################[/color][color=#880000]# See if the Ip is in the blocked list #[/color][color=#880000]##############################[/color][color=#000000]$get_info [/color][color=#666600]=[/color][color=#000000] mysql_query[/color][color=#666600]([/color][color=#008800]"SELECT * FROM blocked WHERE ip = '$vip'"[/color][color=#666600]);[/color][color=#000000]$do_block [/color][color=#666600]=[/color][color=#000000] mysql_fetch_array[/color][color=#666600]([/color][color=#000000]$get_info[/color][color=#666600]);[/color][color=#880000]############################################[/color][color=#880000]# Now we are just checking to see if we need to block the user #[/color][color=#880000]############################################[/color][color=#000000] [/color][color=#000088]if[/color][color=#666600]([/color][color=#000000] $do_block[/color][color=#666600][[/color][color=#008800]'ip'[/color][color=#666600]][/color][color=#000000] [/color][color=#666600]==[/color][color=#000000] [/color][color=#008800]"$vip"[/color][color=#000000] [/color][color=#666600]){[/color][color=#000000] [/color][color=#000088]die[/color][color=#666600]([/color][color=#008800]"Sorry! Your Ip has been blocked from viewing our sites content"[/color][color=#666600]);[/color][color=#666600]}[/color][color=#666600]?>[/color] The above just save it however you want to... I would recommend ipblochp before that works we need to create the table inside of a database that will have the ip's stored inside of them So in phpMyAdmin or your MySql Query Window type in USE 'databasename'; Excute it... CREATE TABLE blocked( id int not null auto_increment primary key, ip varchar(15), added datetime); Excute... Now you are set up! Ok, Good Job on the MySql Database set up... Now, we need to create a config file which will store how we are connecting and what database we are using [color=#666600]<?[/color][color=#000000]php[/color][color=#880000]#########################[/color][color=#880000]# Config File #[/color][color=#880000]#########################[/color][color=#000000]$dbhost [/color][color=#666600]=[/color][color=#000000] [/color][color=#008800]"localhost"[/color][color=#666600];[/color][color=#000000] [/color][color=#880000]// This is your database host name usally localhost[/color][color=#000000]$dbuser [/color][color=#666600]=[/color][color=#000000] [/color][color=#008800]"user"[/color][color=#666600];[/color][color=#000000] [/color][color=#880000]// This is your database user name...[/color][color=#000000]$dbpass [/color][color=#666600]=[/color][color=#000000] [/color][color=#008800]"pass"[/color][color=#666600];[/color][color=#000000] [/color][color=#880000]// this is your password used to login to the database[/color][color=#000000]$dbname [/color][color=#666600]=[/color][color=#000000] [/color][color=#008800]"database"[/color][color=#666600];[/color][color=#000000] [/color][color=#880000]// this is your database name.[/color][color=#880000]##########################[/color][color=#880000]# Edit the above to suit your needs ##[/color][color=#880000]##########################[/color][color=#000000] $conn [/color][color=#666600]=[/color][color=#000000] mysql_connect[/color][color=#666600]([/color][color=#008800]"$dbhost"[/color][color=#666600],[/color][color=#008800]"$dbuser"[/color][color=#666600],[/color][color=#008800]"$dbpass"[/color][color=#666600]);[/color][color=#000000] mysql_select_db[/color][color=#666600]([/color][color=#008800]"$dbname"[/color][color=#666600],[/color][color=#000000] $conn [/color][color=#666600]);[/color][color=#666600]?>[/color] Then Your Done... I would save this as config.php because thats what we imported into our ip checker file (e.g. inlcude "config.php"; ) Ok, as I said you need to put this line of code on your first line after <?php or if you are using session_start(); after that it's should like this [color=#666600]<?[/color][color=#000000]phpinclude [/color][color=#008800]"ipblocklist.php"[/color][color=#666600];[/color][color=#880000]// The rest of your code[/color][color=#666600]?>[/color][color=#282828][font=helvetica, arial, sans-serif]Now, it's time to make a admin type area so you can add or remove blocked Ip's...[/font][/color][color=#666600]<?[/color][color=#000000]phpsession_start[/color][color=#666600]();[/color][color=#880000]#####################[/color][color=#880000]# Get the Config File #[/color][color=#880000]#####################[/color][color=#000000]include [/color][color=#008800]"config.php"[/color][color=#666600];[/color][color=#880000]#########################[/color][color=#880000]# Set the admin credentials # [/color][color=#880000]#########################[/color][color=#000000]$admin [/color][color=#666600]=[/color][color=#000000] [/color][color=#008800]'admin'[/color][color=#666600];[/color][color=#000000]$pass [/color][color=#666600]=[/color][color=#000000] [/color][color=#008800]'password'[/color][color=#666600];[/color][color=#000000]$s_user [/color][color=#666600]=[/color][color=#000000] $_POST[/color][color=#666600][[/color][color=#008800]"admin"[/color][color=#666600]];[/color][color=#000000]$s_pass [/color][color=#666600]=[/color][color=#000000] $_POST[/color][color=#666600][[/color][color=#008800]"pass"[/color][color=#666600]];[/color][color=#000088]if[/color][color=#666600]([/color][color=#000000] $ses_user [/color][color=#666600]<=[/color][color=#000000] [/color][color=#008800]" "[/color][color=#000000] [/color][color=#666600]){[/color][color=#880000]#########################[/color][color=#880000]# Admin Login Form #[/color][color=#880000]#########################[/color][color=#000000]echo [/color][color=#008800]"<form action='ipadmin.php' method='post'>"[/color][color=#666600];[/color][color=#000000]echo [/color][color=#008800]"Admin: <input type='text' name='admin'><br>"[/color][color=#666600];[/color][color=#000000]echo [/color][color=#008800]"Pass: <input type='password' name='pass'><br>"[/color][color=#666600];[/color][color=#000000]echo [/color][color=#008800]"<input type='submit' value='Login'>"[/color][color=#666600];[/color][color=#000000]echo [/color][color=#008800]"</form>"[/color][color=#666600];[/color][color=#666600]}[/color][color=#000000] [/color][color=#000088]if[/color][color=#666600]([/color][color=#000000] $s_user [/color][color=#666600]==[/color][color=#000000] $admin [/color][color=#000088]and[/color][color=#000000] $s_pass [/color][color=#666600]==[/color][color=#000000] $pass [/color][color=#666600]){[/color][color=#000000] $ses_user [/color][color=#666600]=[/color][color=#000000] $_SESSION[/color][color=#666600][[/color][color=#008800]'admin'[/color][color=#666600]][/color][color=#000000] [/color][color=#666600]=[/color][color=#000000] $s_pass[/color][color=#666600];[/color][color=#000000] $go [/color][color=#666600]=[/color][color=#000000] [/color][color=#006666]1[/color][color=#666600];[/color][color=#666600]}[/color][color=#000088]if[/color][color=#666600]([/color][color=#000000] $go [/color][color=#666600]=[/color][color=#000000] [/color][color=#006666]1[/color][color=#000000] [/color][color=#666600]){[/color][color=#000000]echo [/color][color=#008800]"Add a Ip to the Blocked List"[/color][color=#666600];[/color][color=#000000]echo [/color][color=#008800]"<form action='ipadmin.php' method='post'>Ip: <input type='text' name='ip'><input type=submit value='Block Ip'></form>"[/color][color=#666600];[/color][color=#666600]}[/color][color=#000088]if[/color][color=#666600]([/color][color=#000000] $_POST[/color][color=#666600][[/color][color=#008800]"ip"[/color][color=#666600]][/color][color=#000000] [/color][color=#666600]>[/color][color=#000000] [/color][color=#008800]" "[/color][color=#000000] [/color][color=#666600]){[/color][color=#000000]$ip2 [/color][color=#666600]=[/color][color=#000000] $_POST[/color][color=#666600][[/color][color=#008800]"ip"[/color][color=#666600]];[/color][color=#000000]echo [/color][color=#008800]"Are you sure you want to block $ip2"[/color][color=#666600];[/color][color=#000000]echo [/color][color=#008800]"<form action='ipadmin.php' method='post'><input type='hidden' name='ip2' value='$ip2'><input type='submit' name='block' value='yes'>"[/color][color=#666600];[/color][color=#666600]}[/color][color=#000088]if[/color][color=#666600]([/color][color=#000000] $_POST[/color][color=#666600][[/color][color=#008800]"block"[/color][color=#666600]][/color][color=#000000] [/color][color=#666600]==[/color][color=#000000] [/color][color=#008800]"yes"[/color][color=#000000] [/color][color=#666600]){[/color][color=#000000] mysql_query[/color][color=#666600]([/color][color=#008800]"INSERT INTO blocked SET ip = '$ip2' added = NOW()"[/color][color=#666600])[/color][color=#000000] [/color][color=#000088]or[/color][color=#000000] [/color][color=#000088]die[/color][color=#666600]([/color][color=#008800]"Could not Block Ip, MySql Error"[/color][color=#666600]);[/color][color=#666600]}[/color][color=#000000]echo [/color][color=#008800]"<center>Remove Blocked Ips<br><br>"[/color][color=#666600];[/color][color=#000000]echo [/color][color=#008800]"<form action='ipadmin.php' method='post'><select name='remove'><option value=''>Select One</option>"[/color][color=#666600];[/color][color=#000000]$ips [/color][color=#666600]=[/color][color=#000000] mysql_query[/color][color=#666600]([/color][color=#008800]"SELECT * FROM blocked"[/color][color=#666600]);[/color][color=#000088]while[/color][color=#666600]([/color][color=#000000] $showips [/color][color=#666600]=[/color][color=#000000] mysql_fetch_array[/color][color=#666600]([/color][color=#000000]$ips[/color][color=#666600])){[/color][color=#000000]$ip_value [/color][color=#666600]=[/color][color=#000000] $showips[/color][color=#666600][[/color][color=#008800]'ip'[/color][color=#666600]];[/color][color=#000000]echo [/color][color=#008800]"<option value='$ip_value'>$ip_value</option>"[/color][color=#666600];[/color][color=#666600]}[/color][color=#000000]echo [/color][color=#008800]"<input type='submit' value='RemoveIp' name='Remove Ip'>"[/color][color=#666600];[/color][color=#000000]echo [/color][color=#008800]"</form>"[/color][color=#666600];[/color][color=#000088]if[/color][color=#666600]([/color][color=#000000] $_POST[/color][color=#666600][[/color][color=#008800]"Remove Ip"[/color][color=#666600]][/color][color=#000000] [/color][color=#666600]==[/color][color=#000000] [/color][color=#008800]"RemoveIp"[/color][color=#000000] [/color][color=#666600]){[/color][color=#000000]$del_ip [/color][color=#666600]=[/color][color=#000000] $_POST[/color][color=#666600][[/color][color=#008800]'remove'[/color][color=#666600]];[/color][color=#000000]mysql_query[/color][color=#666600]([/color][color=#008800]"DELETE FROM blocked WHERE ip = '$del_ip' LIMIT 1"[/color][color=#666600]);[/color][color=#000000]echo [/color][color=#008800]"The Ip $del_ip has been removed from the blocked list!"[/color][color=#666600];[/color][color=#666600]}[/color][color=#666600]?>[/color] OK now save that above as ipadmin.php Everything Should work succesfully any question