Jump to content

gmc1103

Members
  • Posts

    251
  • Joined

  • Last visited

Everything posted by gmc1103

  1. Hi I need some advices and help regarding this database. This is what i have so far with all tables necessary This is a school timetable where the teachers must register the class summary My main problem is this: Every monday there is classes....so every teacher must register the summary, how do i know from timetable table and "apoios" table is the summary has been registered? Thanks
  2. gmc1103

    Query help

    Hi I'm trying to run a query but is not giving me the right values i need I need to run a query to have all classes ordered and the names of that classes ASC Example Class A have 20 students Class B have 18 So my query would have to give me A Names ASC B Names ASC etc This is what i have but with no success SELECT t1.`idstudent`, t1.`nome`, t1.`numero`, t1.`inscrito`, t1.`estado`, t1.`processo`, t2.`turma` FROM `esmaior_ca`.`alunos` AS t1 INNER JOIN `esmaior_ca`.`turma` AS t2 ON (t1.`turma_idturma` = t2.`idturma`) ORDER BY t2.`turma` AND t1.`nome` ASC; Any help?
  3. Hi Barand Yes it does, i made from the related tables but your examples seems to be better. I think it covers all needs regarding having a database to store all fields. Thank you again and have a nice week-end.
  4. Hi I have followed the user "Barand" implementation and i have another tables to uses Now i must uses another tables to make this database even more reliable I must add to an user the subject class, i mean, user A can teach Mats A and Maths B, user B can teach English and French So i create a table "users_disc" where i use foreign keys from table user and table "esmaior_disc" And the "esmaior_disc" where i have the subjects class must have a year where they belongnew All the new schema are in red Any suggestions?
  5. I have fixed using if($val!=null){ try { $sql = "SELECT t1.`user_proc`, t1.`user_name` FROM `esmaior_alunos` as t1 INNER JOIN `esmaior_turma` as t2 ON (t1.`user_id_ano_turma` = t2.`id_turma`) WHERE (t2.`id_turma` = :val);"; $query = $DB_con->prepare($sql); $query->bindparam(":val", $val); $query->execute(); $result = $query->fetchAll(PDO::FETCH_ASSOC); foreach ($result as $row) { echo "<option value='{$row['user_proc']}'>{$row['user_name']}</option>\n"; } } catch (PDOException $e) { echo $e->getMessage(); } } and the ajax <script> $(document).on("change", '#turma', function(e) { var turmas = $(this).val(); $.ajax({ type: 'post', url: 'classes/getFromDatabase.php', data: {get_option:turmas}, dataType: 'html', success: function(resposta) { console.log(resposta); document.getElementById("alunos").innerHTML=resposta; } }); }); </script> For those with same problem
  6. Thank you for helping me I have removed that but i still have the same problem, i receive this in my php Array ( [data] => 2016-02-12 [hora] => 12:12 [ati] => fertertert [turma] => 17 [alunos] => Array ( [0] => 1 [1] => 4 [2] => 5 ) [docente] => 88 ) And [alunos] don't have the user_proc number wich is by that order 15497 15789 15805 and i receive 1, 4 and 5 So i need pass to <option value "user_proc">user_name> to get the correct values in my database
  7. Hi I have a select dropdown where the user select an item and the second dropdown shows the options in multiple select options. From my database i have $val = filter_input(INPUT_POST, 'get_option'); if($val!=null){ try { $sql = "SELECT t1.`user_proc`, t1.`user_name` FROM `esmaior_alunos` as t1 INNER JOIN `esmaior_turma` as t2 ON (t1.`user_id_ano_turma` = t2.`id_turma`) WHERE (t2.`id_turma` = :val);"; $query = $DB_con->prepare($sql); $query->bindparam(":val", $val); $query->execute(); $result = $query->fetchAll(PDO::FETCH_ASSOC); echo json_encode($result); } catch (PDOException $e) { echo $e->getMessage(); } } And i get the result here <script> $(document).on("change", '#turma', function(e) { var turmas = $(this).val(); $.ajax({ type: 'post', url: 'classes/getFromDatabase.php', data: {get_option:turmas}, dataType: 'json', success: function(resposta) { var $el = $("#alunos"); $el.empty(); var nomes = resposta.map( function( el ){ var processo = []; processo.push(el.user_proc); for (var i = 0; i < processo.length; i++) { getNumerosProcessos(processo); } return el.user_name; }); $.each(nomes, function(value, key) { $el.append($("<option></option>").attr("value", value).text(key)); }); } }); }); </script> This is working but the main problem it's i have to get the "user_proc" into my multiple select option value but i can't have that since this is dynamic My select is this <div class="form-group"> <label for="exampleInputFile">Alunos Ausentes (tecla "shift" para seguidos, "ctrl" para separados)</label> <select name="alunos[]" id="alunos[]" class="form-control" multiple title="Escolha os alunos" style="height: 240pt;"> <option value=""></option> </select> </div> So with this code how i can pass to <option value "user_proc">Name> any help? Thanks
  8. Hi Barand, i will try to implement your schema. Any doubt i will open a new topic Thank you again.
  9. What i have so far is Table class CREATE TABLE `esmaior_turma` ( `id_turma` int(11) NOT NULL AUTO_INCREMENT, `turma` varchar(100) COLLATE utf8_bin NOT NULL, `estado` tinyint(1) NOT NULL, PRIMARY KEY (`id_turma`) ) ENGINE=InnoDB AUTO_INCREMENT=37 DEFAULT CHARSET=utf8 COLLATE=utf8_bin and table students Create Table CREATE TABLE `esmaior_alunos` ( `id_aluno` int(11) NOT NULL AUTO_INCREMENT, `user_proc` int(11) NOT NULL, `user_name` varchar(200) COLLATE utf8_bin NOT NULL, `user_id_ano_turma` int(11) NOT NULL, `user_num_turma` int(20) NOT NULL, PRIMARY KEY (`id_aluno`), KEY `user_id_ano_turma` (`user_id_ano_turma`), CONSTRAINT `esmaior_alunos_ibfk_1` FOREIGN KEY (`user_id_ano_turma`) REFERENCES `esmaior_turma` (`id_turma`) ) ENGINE=InnoDB AUTO_INCREMENT=50 DEFAULT CHARSET=utf8 COLLATE=utf8_bin Now i need to think about a table where i can insert records by id_user, what i pretend to to is: When the teacher add new record, he select the class, then select all the students (user_id) presents of that classes and when i make a query by user_id i can check all the lessons he went..
  10. Can a student belong to more than one class? No, a student belong to one class only (ex 10ºA) Can a student have more than one private lesson? Yes but not in same time (Ex can have English, Maths in different hours time) Can a class have more than one one private lesson? yes (One private lesson can have class A and B and more)
  11. Hi I would to have some opinions about a new task i have regarding inserting records into database This is school scenario The school has private lessons and the principal wants to know wich students going to get in the end of the year a full report The students belongs to class The private lessons can have several classes So when i will insert records into database wich approach i must follow 1- Insert by class then choose every student of that class 2- Insert by students and then by student id i can get his class 3- another one Thank you for any opinion
  12. Hi Barand Thank you again. Best regards
  13. I have this table Field Type Comment idsala int(11) NOT NULL sala varchar(45) NOT NULL estado tinyint(1) NOT NULL And i want to avoid 3 records from the database I'm using this query but those records are showed SELECT `idsala` , `sala` FROM `req_material_sala` WHERE (`idsala` !=23) OR (`idsala` !=24) OR (`idsala` !=39); Any help please?
  14. Hi I'm trying to use the followwing code to get the user name but i need also the user_id. The code is the following <script type="text/javascript"> function autocomplet() { var min_length = 2; var keyword = $('#nome_id').val(); if (keyword.length >= min_length) { $.ajax({ url: 'getFromDB/getFromDatabase.php', type: 'POST', data: {keyword:keyword}, success:function(data){ $('#nome_list_id').show(); $('#nome_list_id').html(data); } }); } else { $('#nome_list_id').hide(); } } function set_item(item) { $('#nome_id').val(item); $('#nome_list_id').hide(); } </script> and in my pdo i have this $keyword = '%'.$_POST['keyword'].'%'; if ($keyword!= null) { $sql = "SELECT * FROM utilizador WHERE nome LIKE (:keyword) and estado = 1 ORDER BY idutilizador ASC LIMIT 0, 10"; $query = $DB_con->prepare($sql); $query->bindParam(':keyword', $keyword, PDO::PARAM_STR); $query->execute(); $list = $query->fetchAll(); foreach ($list as $rs) { $nome = str_replace($_POST['keyword'], '<b>'.$_POST['keyword'].'</b>', $rs['nome']); $iduser = $rs['idutilizador']; echo '<li onclick="set_item(\''.str_replace("'", "\'", $rs['nome']).'\')">'.$nome.'</li>'; } } In the following line i need to pass the variable $iduser echo '<li onclick="set_item(\''.str_replace("'", "\'", $rs['nome']).'\')">'.$nome.'</li>'; any help?
  15. Hi again With this code require_once "{$_SERVER['DOCUMENT_ROOT']}/include/membersite_config.php"; i have this error Warning: require_once(/home/ebspma/public_html/include/membersite_config.php): failed to open stream: No such file or directory in /home/ebspma/public_html/gesdocente/admin_pages/adminAtividadesByMonthChart.php on line 4 Wtis this code require_once "{$_SERVER['DOCUMENT_ROOT']}../include/membersite_config.php"; I have this error too Warning: require_once(/home/ebspma/public_html../include/membersite_config.php): failed to open stream: No such file or directory in /home/ebspma/public_html/gesdocente/admin_pages/adminAtividadesByMonthChart.php on line 4 So, i think there is somthing wrong This is my code <?PHP error_reporting(E_ALL | E_NOTICE); ini_set('display_errors', '1'); require_once "{$_SERVER['DOCUMENT_ROOT']}../include/membersite_config.php"; if (!$ebspma->CheckLogin()) { $ebspma->RedirectToURL("index.php"); exit; } include '../menus/menus.php'; ?> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>EBSPMA - Gráfico</title> <link href="../css/bootstrap.min.css" rel="stylesheet" type="text/css"/> <link href="../css/bootstrap-table.css" rel="stylesheet" type="text/css"/> <link href="../css/bootstrap-editable.css" rel="stylesheet" type="text/css"/> <link rel="stylesheet" href="../css/formValidation.min.css"> </head> <body> <div class="row"> <div class="col-md-12"> <div class="row clearfix"> <div class="col-md-12 column"> <div class="alert alert-info"><h3>Atividades por meses</h3></div> </div> </div> <div class="col-md-2"></div> <div class="col-md-8" id="visualization" style="width: 800px; height: 400px;"></div> <div class="col-md-2"></div> <?php include 'mysqliconn.php'; $query = "SELECT idativade, DATE_FORMAT(data, '%b') AS Datas, COUNT( * ) AS Atividades FROM `ebspma_paad_ebspma`.`nem_pae_atividades` GROUP BY Datas ORDER BY data"; $result = $mysqli->query($query); $num_results = $result->num_rows; if ($num_results > 0) { ?> <script type="text/javascript" src="http://www.google.com/jsapi"></script> <script type="text/javascript"> google.load('visualization', '1', {'packages': ['corechart', 'geochart', 'table']}); </script> <script type="text/javascript"> function drawVisualization() { // Create and populate the data table. var data = google.visualization.arrayToDataTable([ ['Datas', 'Atividades'], <?php while ($row = $result->fetch_assoc()) { extract($row); echo "['{$Datas}', {$Atividades}],"; } ?> ]); new google.visualization.ColumnChart(document.getElementById('visualization')). draw(data, {title: "Distribuição Mensal"}); } google.setOnLoadCallback(drawVisualization); </script> <?php } else { echo "Sem atividades registadas"; } ?> </div> </div> <script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="../js/formValidation.min.js"></script> <script src="../js/bootstrap.min.js"></script> <script src="../js/bootstrap.min2.js"></script> <script src="../js/bootstrap-table.js"></script> <script src="../js/bootstrap-table-export.js"></script> <script src="../js/bootstrap-table-pt-PT.js"></script> <script type="text/javascript" src="../js/tableExport.js"></script> <script type="text/javascript" src="../js/jquery.base64.js"></script> <script type="text/javascript" src="../js/sprintf.js"></script> <script type="text/javascript" src="../js/jspdf.js"></script> <script type="text/javascript" src="../js/base64.js"></script> </body> </html>
  16. No...it gives me that error Warning: require_once(/home/ebspma/public_html../include/membersite_config.php): failed to open stream: No such file or directory in /home/ebspma/public_html/gesdocente/admin_pages/adminAtividadesByMonthChart.php on line 4
  17. Hi I'm having a problem regarding this function I have a folder (admin_pages) who have inside a file, that file should call another file inside a root folder i have tried require_once("../include/membersite_config.php"); And it gives me error Warning: require_once(./include/fg_membersite.php): failed to open stream: No such file or directory in /home/ebspma/public_html/gesdocente/include/membersite_config.php on line 2 This is my structure any help to get into include folder from admin_pages file folder? Thanks
  18. Hi This is what i have with phpinfo(); MysqlI Support enabled Client API library version 5.5.46 Active Persistent Links 0 Inactive Persistent Links 0 Active Links 0 Client API header version 5.5.45 MYSQLI_SOCKET /var/lib/mysql/mysql.sock Directive Local Value Master Value mysqli.allow_local_infile On On mysqli.allow_persistent On On mysqli.default_host no value no value mysqli.default_port 3306 3306 mysqli.default_pw no value no value mysqli.default_socket no value no value mysqli.default_user no value no value mysqli.max_links Unlimited Unlimited mysqli.max_persistent Unlimited Unlimited mysqli.reconnect Off Off Regarding the code i'm changing to pdo, but i have problems regarding the password match I'm using this public function getUserByEmailAndPassword($email, $password) { $stmt = $this->conn->prepare("SELECT * FROM users WHERE email = :email"); $stmt->bindparam(":email", $email); if ($stmt->execute()) { $user = $stmt->fetch(); $salt = $user['salt']; $encrypted_password1 = $user['encrypted_password']; echo $encrypted_password1; $hash = $this->checkhashSSHA($salt, $password); if ($encrypted_password1 == $hash) { return $user; } } else { return NULL; } } But $user is always empty Thanks
  19. Sorry Current PHP version: 5.5.302.0
  20. Variable_name Value ----------------------- ------------------------------ innodb_version 5.5.46 protocol_version 10 slave_type_conversions version 5.5.46-cll version_comment MySQL Community Server (GPL) version_compile_machine x86_64 version_compile_os Linux I must check how to use PDO in that case, do you have an example?
  21. Hi Ok, to avoid any mistake this is the original code i'm trying to handle. <?php class DB_Functions { private $conn; function __construct() { require_once 'DB_Connect.php'; // connecting to database $db = new Db_Connect(); $this->conn = $db->connect(); } function __destruct() { } public function storeUser($name, $email, $password) { $uuid = uniqid('', true); $hash = $this->hashSSHA($password); $encrypted_password = $hash["encrypted"]; // encrypted password $salt = $hash["salt"]; // salt $stmt = $this->conn->prepare("INSERT INTO users(unique_id, name, email, encrypted_password, salt, created_at) VALUES(?, ?, ?, ?, ?, NOW())"); $stmt->bind_param("sssss", $uuid, $name, $email, $encrypted_password, $salt); $result = $stmt->execute(); $stmt->close(); if ($result) { $stmt = $this->conn->prepare("SELECT * FROM users WHERE email = ?"); $stmt->bind_param("s", $email); $stmt->execute(); $user = $stmt->get_result()->fetch_assoc(); $stmt->close(); return $user; } else { return false; } } public function getUserByEmailAndPassword($email, $password) { $stmt = $this->conn->prepare("SELECT * FROM users WHERE email = ?"); $stmt->bind_param("s", $email); if ($stmt->execute()) { $user = $stmt->get_result()->fetch_assoc(); $stmt->close(); return $user; } else { return NULL; } } } The first function "storeUser($name, $email, $password)" works since all the data is inserted into my DB The second function "getUserByEmailAndPassword($email, $password)" i'm getting the following error. Fatal error: Call to undefined method mysqli_stmt::get_result() in /home/xxxxx/public_html/mobile/include/DB_Functions.php on line 48 The line 48 is $user = $stmt->get_result()->fetch_assoc(); Yes, Barand, i'm puzzled too..and if you check the first function i have get_result() there. So...i'm lost
  22. Hi Barand Thank's for your reply I'm having issues Call to undefined method mysqli_stmt::get_result(); But the strange is i have this method in another function and i don't have this error. This is the function and this one works public function storeUser($name, $email, $password) { $uuid = uniqid('', true); $hash = $this->hashSSHA($password); $encrypted_password = $hash["encrypted"]; // encrypted password $salt = $hash["salt"]; // salt $stmt = $this->conn->prepare("INSERT INTO users(unique_id, name, email, encrypted_password, salt, created_at) VALUES(?, ?, ?, ?, ?, NOW())"); $stmt->bind_param("sssss", $uuid, $name, $email, $encrypted_password, $salt); $result = $stmt->execute(); $stmt->close(); // check for successful store if ($result) { $stmt = $this->conn->prepare("SELECT * FROM users WHERE email = ?"); $stmt->bind_param("s", $email); $stmt->execute(); $user = $stmt->get_result()->fetch_assoc(); $stmt->close(); return $user; } else { return false; } } Strange....
  23. Hi I'm having problems with this function, it doesn't bind_result() any variables. So my "While" doesn't work either public function getUserByEmailAndPassword($email, $password) { $stmt = $this->conn->prepare("SELECT unique_id,name,email,created_at,updated_at, encrypted_password , salt FROM users WHERE email = ?"); $stmt->bind_param("s", $email); if ($stmt->execute()) { $stmt->store_result(); $num_of_rows = $stmt->num_rows; $stmt->bind_result($aid, $aname, $aemail, $acreated_at, $aupdated_at , $aencrypted_password , $asalt); echo $aemail; //no echo while ($user=$stmt->fetch()) { echo "inside while"; // no echo $user[0] = $aid; $user[1] = $aname; $user[2] = $aemail; $user[3] = $acreated_at; $user[4] = $aupdated_at; $user[5] = $aencrypted_password; $user[6]= $asalt; $user[7] = $password; } $stmt->free_result(); $stmt->close(); return $user; } else { echo "no $stmt->execute()"; //no echo return NULL; } } Any error in this code? Thanks
  24. Hi Ch0cu3r Thanks for helping me. I have modified this and now it is working. Thank you
  25. Hi hansford Thank you for your apport. I have tested your code but nothing happen This is my ajax <script> $(function () { $('#myFormSubmit').click(function (e) { e.preventDefault(); var item = $('#id_itens').val(); $.ajax({ url: 'class.user.php', type: 'POST', data: {action: 'delItem',item: item}, success: function (response) { if (response.status === 'success') { console.log("success"); $("#myModal").modal('hide'); $('#respostas .modal-title').html('Sucesso'); $('#respostas .modal-body').html('Informação: ' + response.message); $('#respostas').modal('show'); $('#respostas').on('hidden.bs.modal', function () { window.location.reload(true); }); } } }); }); }); </script> and this is my class.user.php function public function delItem(){ $id_itens = filter_input(INPUT_POST, 'item'); try { $sql = 'DELETE FROM `esmaior_biblioteca`.`item` WHERE `id_itens` = :me'; $stmt = $this->db->prepare($sql); $stmt->bindValue(':me', $id_itens, PDO::PARAM_INT); if (!$stmt->execute()) { print_r($stmt->errorInfo()); return array('status' => 'error', 'message' => 'Problema ao remover este item...'); } else { return array('status' => 'success', 'message' => 'O registo foi removido com sucesso...'); } } catch (PDOException $e) { echo $e->getMessage(); } } and i don't have any response....
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.