Jump to content

shadd

Members
  • Posts

    55
  • Joined

  • Last visited

Everything posted by shadd

  1. SOLVED IT BY ADDING IF INSEX<>''THEN DO INSERT WITH THE ENUM FIELD ELSE DO INSERT WITHOUT THE ENUM FIELD IN QUERY END IF;
  2. what if i need to account for null entries to this field
  3. i have this procedure: DELIMITER $$ CREATE PROCEDURE sp_add_user(IN inname text,IN insex tinytext) MODIFIES SQL DATA BEGIN set @newEanswer_sql=CONCAT('INSERT INTO user(fname,sex)values("',inname,'","',insex,'")' ); PREPARE snewEans_insert FROM @newEanswer_sql; EXECUTE snewEans_insert; DEALLOCATE PREPARE snewEans_insert; END$$ DELIMITER ; when i run it like so: call sp_add_user('pierre',''); it gives me the following error: RETURNED_SQLSTATE MESSAGE_TEXT 01000 Data truncated for column 'sex' at row 1 here is table: create table user ( userid int unsigned not null auto_increment, fname text , sex enum('male','female'), Primary key(userd) ); how can i solve this??
  4. i have these tables: create table tblQuestions ( QueId varchar(255), instruction text , question text , Primary key(Que_Id) ); create table tblAnswers ( QueAns_Id int unsigned not null auto_increment, Answer text Primary key(QueAns_Id) )ENGINE=InnoDB DEFAULT CHARSET=UTF8; create table tblScore ( Ans_Id varchar(255), QueAns_Id int unsigned not null , User_id int unsigned , Answer_score float not null default 0.0,/*0.0 or 1.0*/ Primary key(Ans_Id,User_id), foreign key(QueAns_Id) references tblAnswers(QueAns_Id) on delete cascade on update cascade, foreign key(User_id) references tblUsers(sUser_id) on delete cascade on update cascade )ENGINE=InnoDB DEFAULT CHARSET=UTF8; create table tblUsers ( sUser_Id mediumint unsigned not null auto_increment, First_name varchar(50) not null, Primary key(sUser_Id), unique key(S_UPassword) )ENGINE=InnoDB DEFAULT CHARSET=UTF8; INSERT INTO tblUsers(First_name) VALUES('Apple); INSERT INTO tblQuestions(QueId,instruction ,question )VALUES('1.1.49','','Hard work may lead to success.(rewrite using:.....could.........)') ('1.1.49','','Hard work may lead to success.(rewrite using:.....could.........)'); ('1.1.50','','Jessy can speak English yet she has never been to school.(Rewrit using:......inspite of ......)'); ('1.1.51',' Read the passage below and then answer in full sentences the questions that follow.','What is the passage about?'); ('1.1.51.10','','why am i not in order?'); ('1.1.51.2','','Why is it iam not in place above 1.1.51.10'); ('1.1.51.3','','Yeah part b,he should be below us!'); iam using the select query below to get the data,but the questions are not in order i like to have: 1.1.49 1.1.50 1.1.51 1.1.51.2 1.1.51.3 1.1.51.10 SELECT q.QueId AS Q_id, CASE when ROUND((LENGTH(q.QueId)-LENGTH(replace(q.QueId,'.',''))) / LENGTH('.') )>2 then concat(q.Que_Id,CHAR(CAST(SUBSTRING_INDEX(q.QueId,'.',-1) AS INTEGER)+96))END as QueNo, CASE when ROUND((LENGTH(q.QueId)-LENGTH(replace(q.QueId,'.',''))) / LENGTH('.') )>2 then CAST(SUBSTRING_INDEX(SUBSTRING_INDEX(q.QueId,'.',-2),'.',1) AS INTEGER) ELSE CAST(SUBSTRING_INDEX(q.QueId,'.',-1) AS INTEGER)end as qNo, q.instruction, q.question, Z.QueAns_Id, Z.Answer, Z.User_id,Z.Answer_score FROM tblQuestions q LEFT JOIN (select B.QueAns_Id, B.Answer, C.Ans_Id,C.User_id,C.Answer_score from tblAnswers B LEFT JOIN tblScore C ON B.QueAns_Id=C.QueAns_Id AND C.User_id=1)AS Z ON q.QueId=Z.Ans_Id and SUBSTRING_INDEX(q.QueId,'.',2)='1.1' order by qNo asc;
  5. correct and simple but,is it possible to add a key to the results array like so: foreach ($results as $lvl => $arr) { echo "$lvl <UL>"; foreach ($arr as $sub) { $results['go_to_exam'] ="dear";echo "<li>$sub</li>"; } echo "</ul>"; } in a for loop this could work: for ($i = 0; $i < count($results); $i++) { $results[$i]['go_to_exam'] = "dear".$i; } if i had used fetch:assoc
  6. can you please, show your concept on that array using php
  7. here is the array that i need to print out in a <ul> : array ( 0 => array ( 'pId' => '1.1', 'Duration' => NULL, 'emdate' => NULL, 'Sub' => 'BASIC lug', 'SubId' => 1, 'Lvl' => ' ULE', 'LvId' => 1, ), 1 => array ( 'pId' => '1.2', 'Duration' => NULL, 'emdate' => NULL, 'Sub' => 'BASIC lug', 'SubId' => 1, 'Lvl' => ' ULE', 'LvId' => 1, ), 2 => array ( 'pId' => '1.3', 'Duration' => NULL, 'emdate' => NULL, 'Sub' => 'ger', 'SubId' => 1, 'Lvl' => ' ACE', 'LvId' => 2, ) ) iam expecting to get this result; ULE BASIC LUG BASIC LUG ACE ger
  8. I have this resultset : pId Duration emdate Sub SubId Lvl LvId 1.1 null null basic lug 1 ule 1 1.2 null null basic lug 1 ule 1 1.2 null null ger 2 ace 1 I would like to have it display like so in a <ul>: ULE BASIC LUG BASIC LUG ACE ger how can I achieve that if each is a row from database resultset. I have tried ; foreach($ScheduledExamlist as $Scheduledexam) { echo '<li class="current"><a href="#">'.$Scheduledexam['Lvl'].'</a></li>' ; echo '<li>'.$Scheduledexam.'</li>'; } but heading appears twice
  9. won't there be too much overload to the database and effectiveness of performance due to too many calls??
  10. thanks for the job butit still resets the timer to 3 seconds on page refresh which is not required.it is supposed to count down continuously
  11. 180 is 3hours and not 3minutes. And after hard coding the 180 in, the timer does not count down it simply displays for aroun 3 sec and shows expired
  12. i have tried this by putting the end time <!DOCTYPE HTML> <html> <body> <p id="demo"></p> <!--button onclick="countdownTimeStart()">Start Timer</button--> <script> // Set the date we're counting down to function strToMins(t) { var s = t.split(":"); return Number(s[0]) * 60 + Number(s[1]); } function countdownTimeStart(){ let currentTime = new Date().getTime(); let countDownTime = new Date(currentTime + 2 * 60 * 60 * 1000); //var countDownTime = strToMins(" 06:45:00"); // Update the count down every 1 second var x = setInterval(function() { // Get todays date and time var now = new Date().getTime(); // Find the distance between now an the count down date var distance = countDownTime - now; // Time calculations for days, hours, minutes and seconds var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)); var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60)); var seconds = Math.floor((distance % (1000 * 60)) / 1000); // Output the result in an element with id="demo" document.getElementById("demo").innerHTML = hours + "h " + minutes + "m " + seconds + "s "; // If the count down is over, write some text if (distance < 0) { clearInterval(x); document.getElementById("demo").innerHTML = "EXPIRED"; } }, 1000); } window.onload = function () { //var timeLeft = 3600*1, // display = document.querySelector('#time'); countdownTimeStart() }; </script> </body> </html> but still i get the page refreshing the timer to start
  13. an example of this will be great thanks
  14. i have this timer: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Countdown</title> <script type="text/javascript"> var hours; var mins var secs; function cd() { // below count down for 2 hours and 10 mins and 10 seconds // Or you could provide a string such as => [var time = "10:10:10";] // And construct a function to fetch values from correct parts hours = 2; mins = 10; secs = 10; progr_ess=130; //document.getElementById("progressBar").setAttribute('max','130'); redo(); } function dis(hours, mins, secs) { var disp; if (hours <= 9) { disp = " 0"; } else { disp = " "; } disp += hours + ":"; if (mins <= 9) { disp += " 0"; } else { disp += " "; } disp += mins + ":"; if (secs <= 9) { disp += "0" + secs; } else { disp += secs; } return (disp); } function redo() { secs--; if (secs == -1) { secs = 59; mins--; document.getElementById("progressBar").value = 130-progr_ess ; progr_ess -= 1; } if (mins == -1) { mins = 59; hours--; } document.getElementById("txt").value = dis(hours, mins, secs); if ((mins == 0) && (secs == 0) && (hours == 0)) { window.alert("Time is up. Press OK to continue."); // window.open("module.aspx", "_parent ") } else { cd = setTimeout("redo()", 1000); } } function init() { cd(); } window.onload = init; </script> <style> #txt { border: none; font-family: verdana; font-size: 16pt; font-weight: bold; border-right-color: #FFFFFF } </style> </head> <body> <form id="form1" > <div> <div> <input id="txt" type="text" value="00:00:00" name="disp" /> </div> <progress value="0" max="130" id="progressBar"></progress> </div> </form> </body> </html> how can i make sure it does not go back to start time duration on page refresh? how can i accustom it to recieve the count down duration using php variable?
  15. i have this code: $data={"egg","york","pork"} ; $total=count($data);//$j=0; for ($i = 0; $i < $total; $i++){//$j++; echo 'SECTION '; echo ($j <= 2) ? "A" : "B" ;break; echo $data[$i]; } i would like to print: SECTION A eggg york Section B pork .... how can i do that inside the for loop??How can I do a groupby section ??
  16. i would like to map the values of array(2) in key 0 to those of array(11) from 1.1.51 to 1.1.51.10 so that i print out: 1.1.51,a 1.1.51.1,b . . . 1.1.51.10,j 1.1.52,a
  17. i have these two arrays: array(2) { [0]=> array(10) { [0]=> string(1) "a" [1]=> string(1) "b" [2]=> string(1) "c" [3]=> string(1) "d" [4]=> string(1) "e" [5]=> string(1) "f" [6]=> string(1) "g" [7]=> string(1) "h" [8]=> string(1) "i" [9]=> string(1) "j" } [1]=> array(2) { [0]=> string(1) "a" [1]=> string(0) "" } } array(11) { [0]=> string(6) "1.1.51" [2]=> string(8) "1.1.51.2" [3]=> string(8) "1.1.51.3" [4]=> string(8) "1.1.51.4" [5]=> string(8) "1.1.51.5" [6]=> string(8) "1.1.51.6" [7]=> string(8) "1.1.51.7" [8]=> string(8) "1.1.51.8" [9]=> string(8) "1.1.51.9" [1]=> string(9) "1.1.51.10" [10]=> string(6) "1.1.52" } how can merge the corresponding values of array(11) to those of array(2).keeping in mind that 1.1.51-1.1.51.10 are for the first sub array in array(2) and 1.1.52 corresponds to the values of key 1 in array(2).And how can i display them?
  18. What if you do not know the next id i.e it is auto generated and you just have to loop through.i.e you do not know 1.1.52 is the next,what comparison would you use here to return to $j=0 for ($i = 0; $i < $m; $i++) { if ($Q_Id[$i] === '1.1.52') { $j = 0; } echo $Q_Id[$i] . ': ' . $sub[$j] . '<br>'; $j++; }
  19. $theme='b|||c|||d|||e|||f|||g|||h|||i|||j,b|||c|||d|||e|||f|||g|||h|||i|||j'; the first string:b|||c|||d|||e|||f|||g|||h|||i|||j is for the id 1.1.51.......1.1.51.10 and the second string:b|||c|||d|||e|||f|||g|||h|||i|||j is for the next id 1.1.52.........1.1.52.10 so $p_id = "1.1.51|||1.1.51.2|||1.1.51.3|||1.1.51.4|||1.1.51.5|||1.1.51.6|||1.1.51.7|||1.1.51.8|||1.1.51.9|||1.1.52|||1.1.52.2|||1.1.52.3|||1.1.52.4|||1.1.52.5|||1.1.52.6|||1.1.52.7|||1.1.52.8|||1.1.52.9"; But some Ids may not have a theme that is it may be empty
  20. i have this string of ids: $p_id=1.1.51|||1.1.51.2|||1.1.51.3|||1.1.51.4|||1.1.51.5|||1.1.51.6|||1.1.51.7|||1.1.51.8|||1.1.51.9|||1.1.52|||1.1.51.10, 1.1.52|||, i explode it like so: $Q_Id=explode('|||',p_id); i have another string of themes like so: $theme='b|||c|||d|||e|||f|||g|||h|||i|||j,' which i explode like so: $sub=explode(',',$theme); each element in theme string corresponds to an id in the string above delimited by a comma. therefore i add a to the array for($s=0;$s<count($sub);$s++){ $DisplaySub[$s]=explode('|||',$sub[$s]); //add a to startnof array array_unshift($DisplaySub ,'a'); } how can I loop through the ids and display their corresponding list of themes using for/foreach loop? for ($i = 0; $i < count($Q_Id); $i++){ for($s=0;$s<count($sub);$s++){ $DisplaySub[$s]=explode('|||',$sub[$s]); //add a to startnof array array_unshift($DisplaySub ,'a'); } } how can i merge the corresponding $sub theme to a specific id say 1.1.51: a 1.1.51.2:b . . 1.1.52:a 1.1.52.2:b etc...
  21. i have a set of numbers that i need to arrange in ascending order: 1.1.51,1.1.51.10,1.1.51.2,1.1.51.3,1.1.51.4,..........,A,1.1.52 my problem is that 1.1.51.10 is not coming at position A where it should. how can i achieve this??
  22. iam trying to set up a variable in a loop using concat like so: set p=1; loop2: WHILE p<=4 DO SET concat('Opt_',p)='one'; SET p=p+1; END WHILE loop2; but i get an error: #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '('Opt_',p)='one'; the variables declared are Opt_1 to Opt_4
  23. this is what i did to get it var str= data ; let removedSpacesText = str.split(" ").join(""); alert(removedSpacesText); alert(removedSpacesText[0]); and it worked
  24. it contains "Osucess" but the if tatements do not work out And when i try console.log(data[0]); it shows nothing at all.
  25. i have this php script: $result='Osucess' echo $result; i have this jquery ajax: $("#add_sub").submit(function (e) { e.preventDefault(); var formDatax = new FormData($('#add_sub')[0]); $.ajax({ type: "POST", url: 'answers.php', data: formDatax, //Options to tell jQuery not to process data or worry about content-type. cache: false, contentType: false, processData: false, success: function(data){ if(data.charAt(0) ==="O"){ alert(data); }else{ alert("failed"); } } }); }); but it does not work at all.what is the problem??
×
×
  • 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.