Jump to content

Jaswinder

Members
  • Posts

    124
  • Joined

  • Last visited

Everything posted by Jaswinder

  1. hi I am having a multidimensional array in $a. i get this result after using print_f Array ( [0] => Array ( [sno] => 4 [num1] => 45 [num2] => 45 [result] => 2025 ) [1] => Array ( [sno] => 17 [num1] => 34 [num2] => 36 [result] => 1224 ) [2] => Array ( [sno] => 2 [num1] => 78 [num2] => 5 [result] => 390 ) ) using foreach and converting into individual arrays foreach($a as $key => $value) { print_r($key = $value); echo "<br/>"; } and the result is Array ( [sno] => 4 [num1] => 45 [num2] => 45 [result] => 2025 ) Array ( [sno] => 17 [num1] => 34 [num2] => 36 [result] => 1224 ) Array ( [sno] => 2 [num1] => 78 [num2] => 5 [result] => 390 ) now i want to remove num1 and num2 elements from each array.. so that the resulting array contains 2 elements sno and result i tried unset() but not getting result. any help
  2. thanks for this nice function, array_chunk() .. its new to me Did it in this way <?php $fetch=$check->gettest("level1",$cn); $group=array_chunk($fetch,3); foreach($group as $currentRow) { ?> <tr> <?php foreach($currentRow as $key => $value) { ?> <td><strong><?php echo $value['num1'] ?> x <?php echo $value['num2']; ?> </strong></td> <td><input type="text" name="q<?php echo $value['sno'];?>" required="required" value="<?php if (isset($answer)) echo $q1; ?>"></td> <?php } ?> </tr> <?php } ?>
  3. i fetched 6 rows from database in a varible $fetch,.. when i applies var_dump(). it shows the result like this Array ( [0] => Array ( [sno] => 1 [num1] => 5 [num2] => 5 ) [1] => Array ( [sno] => 2 [num1] => 5 [num2] => 10 ) [2] => Array ( [sno] => 3 [num1] => 10 [num2] => 4 ) [3] => Array ( [sno] => 4 [num1] => 7 [num2] => 6 ) [4] => Array ( [sno] => 5 [num1] => 9 [num2] => 4 ) [5] => Array ( [sno] => 6 [num1] => 40 [num2] => 5 ) ) now i want to show this in a table like 1st three key values in first row, then next three key values in next row and so on .. like this <tr> <td>5 x5 =</td><td>input text field</td> <td>5 x 10 =</td><td>input text field</td> <td>10 x 4 =</td><td>input text field</td> <tr> <tr> <td>7 x 6 =</td><td>input text field</td> <td>9 x 4 =</td><td>input text field</td> <td>40 x 5 =</td><td>input text field</td> <tr> hope you get , what i want to achieve.. now i tried this <?php foreach($fetch as $key => $value) { ?> <tr> <?php for($i=0;$i<3;$i++) { ?> <td><strong><?php echo $value['num1'] ?> x <?php echo $value['num2']; ?> </strong></td> <td><input type="text" name="q<?php echo $value['sno'];?>" required="required" value="<?php if(isset($answer)){echo $q1;} ?>"></td> <?php } ?> </tr> <?php } ?> and the output is 5 x 5 = input field 5 x 5 = input field 5 x 5= input field 5 x 10 = input field 5 x 10 = input field 5 x 10 = input field 10 x 4 = input field 10 x 4 = input field 10 x 4 = input field and so on ... i.e each key array get repeat 3 times.. any help to print 3 key values per <tr> then next 3 in next <tr> I have to make 10 rows like this i.e 30 <td>
  4. Thanx for reply guys.. i got my problem solved by some other method... your answers help me in doing that
  5. it properly makes sense.. i just want to use the array $answer inside a function.. how can i use it ?
  6. hi everyone. i want to use an array ( already created outside the function ) in a function . here is the code page1.php <form action="page2.php" method="post"> Marks1 = <input type="text" name="marks1" /> Marks2 = <input type="text" name="marks2" /> <input type="submit"> page2.php extract($_POST); $answer=array("$marks1","$marks2"); function numcheck($val,$answer) { if(is_numeric($val)) { return $val; } else { $newanswer=serialize($answer); $encode=urlencode($newanswer); header('location:level1test?num=numerror&encode=$encode'); } } $result=array_filter($answer,"numcheck"); i am getting this error :- Missing argument 2 for numcheck() i tried to use array inside the function also like this function numcheck($val,$answer) { if(is_numeric($val)) { return $val; } else { $answer=array("$marks1","$marks2"); $newanswer=serialize($answer); $encode=urlencode($newanswer); header('location:level1test?num=numerror&encode=$encode'); } } But now the error is undefined varible marks1 and marks2 How to get the $answer array inside the function ??
  7. Thanks for reply .. but i get it solved, there is a css issue, which stopping me from doing it. what i want to achieve was.. when i click on my mid div, the first and mid both divs get hide and end div shows up
  8. hi everyone. i have three divs. what i want to achieve is on clinking the 2nd div , hide the 1st and 2nd both divs and show the 3rd.. what i did still now is . <div class="first"> some text </div> <div class="mid">button</div> <div class="end"> some text </div> <script> $('.mid').click(function() { var $group = $(this); $group.prev('.first').toggle('slow'); $group.hide(); $group.next('.end').toggle('slow'); }); i am not able to hide the mid div, Toggle effect is working perfectly on both other divs
  9. thanks for reply you have enclosed the trick class inside the tricks_head class, but i need them both seprate, like this <div class="tricks_head">First</div> <div class="trick"></div> Is it possible or any other alternative ?
  10. Hello everyone.. I am using a toggle effect on divs, what i want is a single code for all divs .. right now i have to write the code multiple times i.e for every div individually . I know it can be achieved by $(this) , but i dont know how, as i am new to jquery. here is my code and its working fine, <div class="tricks_head">First</div> <div id="trick1"></div> <div class="tricks_head2">second</div> <div id="trick2"></div> <div class="tricks_head3">third</div> <div id="trick3"></div> <script type="text/javascript"> $( ".tricks_head" ).click(function() { $( "#trick1" ).toggle('slow'); }); $( ".tricks_head2" ).click(function() { $( "#trick2" ).toggle('slow'); }); $( ".tricks_head3" ).click(function() { $( "#trick3" ).toggle('slow'); }); </div> In my project i have 50 div , so can't write it 50 times.. so any help please ?
  11. Thanks denno020 for such quick and lovely support.. Keep on helping people.. Stay Blessed
  12. Finally Its working here is the script <li><strong><span class="num1">16</span> x <span class="num2">11</span> = </strong><input type="text" ><button class="check">Check</button><span class="display"></span></li> <li><strong><span class="num1">62</span> x <span class="num2">11</span> = </strong><input type="text" name="p2"><button class="check">Check</button><span class="display"></span></li> <script> $(".check").click(function() { var button = $(this); //This is the button that was clicked on var parentLi = button.closest("li"); //Find the closest li parent, starting from the button, working up the DOM var value = parentLi.find("input").val(); //From the li, work back down the DOM until an input field is found, and get the value of it var num1 = parentLi.find(".num1").text(); var num1Int = parseInt(num1); var num2 = parentLi.find(".num2").text(); var num2Int = parseInt(num2); var answer = num1Int * num2Int; var displayField = parentLi.find(".display"); //Starting from the parent li again, search down the DOM until an element with a class display is found if(value == answer) { displayField.html(value+"<i class='fa fa-check'></i>"); //Set the value of the element that has the display class } else { displayField.html(value+"<i class='fa fa-times'></i>"); } }); </script>
  13. But num1 and num2 don't have input fields, so how variables get value ? I did this - <script> $(".check").click(function() { var button = $(this); //This is the button that was clicked on var parentLi = button.closest("li"); //Find the closest li parent, starting from the button, working up the DOM var value = parentLi.find("input").val(); //From the li, work back down the DOM until an input field is found, and get the value of it var num1 = parentLi.find(".num1").val(); var num2 = parentLi.find(".num2").val(); var result = num1*num2; var displayField = parentLi.find(".display"); //Starting from the parent li again, search down the DOM until an element with a class display is found if(value == result) { displayField.html(value+"<i class='fa fa-check'></i>"); //Set the value of the element that has the display class } else { displayField.html(value+"<i class='fa fa-times'></i>"); } }); </script> Is it the right way to do calculations ? i am not getting the multiplication value in result variable, may be num1 and num2 variables are empty
  14. Thanks for such great code.. its working for all ten now.. Just a conditional part left. i am using it like this now <li><strong>16 x 11 = </strong><input type="text" name="p1" id="p1"><button class="check">Check</button><span class="display"></span></li> <li><strong>62 x 11 = </strong><input type="text" name="p2" id="p2"><button class="check">Check</button><span class="display"></span></li> <li><strong>43 x 11 = </strong><input type="text" name="p3" id="p3"><button class="check">Check</button><span class="display"></span></li> $(".check").click(function() { var button = $(this); //This is the button that was clicked on var parentLi = button.closest("li"); //Find the closest li parent, starting from the button, working up the DOM var value = parentLi.find("input").val(); //From the li, work back down the DOM until an input field is found, and get the value of it var displayField = parentLi.find(".display"); //Starting from the parent li again, search down the DOM until an element with a class display is found if(value == 176) { displayField.html(value+"<i class='fa fa-check'></i>"); //Set the value of the element that has the display class } else { displayField.html(value+"<i class='fa fa-times'></i>"); } }); </script> Now how to check for other two also like 682 ( 62 x 11 ) and 473 ( 43 x 11) ? As the above code is checking for 176 for all the fields, and user will use all the fields and check it individually I put id's in input field , Are they useful anyhow ? or i just remove them ?
  15. i tried this and its working, but have one question <li>16 x 11 =<input type="text" name="p1" id="p1"><button id="check">Check</button><span id="display"></span> <script type="text/javascript"> var p1 = $("#p1"); $("#check").click(function(){ var getval = ($("#p1").val()?$("#p1").val():alert('please fill the text field')); if(getval != 171) { $('#display').html(getval+" <i class='fa fa-times'></i>"); } else { $('#display').html(getval+" <i class='fa fa-check'></i>"); } }); </script></li> I have 10 list items with different id's like p1,p2,p3,..... so on .. so i have to write the code 10times ? or there is any other way ?? and also can this this code be more simplified ? or how to write it in venilla javascript ? any help ?
  16. Thanks for useful info.. i will give it a shot and come back
  17. I didn't write any script yet.. I need one.. I dont know javascript Will u help me , how to move on or how to achieve this ?
  18. What i want to achieve is... On clicking the button, i want to check the answer and print the result correct or incorrect after the button inside the <li>.. Is it possible ?? What i have done still now is <div id="view2"> <ol> <li><strong>16 x 11 = </strong><input type="text" name="p1"><button>Check</button></li> <li><strong>20 x 11 = </strong><input type="text" name="p2"><button>Check</button></li> </ol> </div><!--view2 end--> I dont know how to move further
  19. Thanks , that hidden trick works
  20. Thanks for reply Quickoldcar.
  21. Hello everyone I learned core PHP, and some OOPs also and i want to move to next level. I am a web developer right now and if i am not wrong, the following are part of software development and PHP frameworks. So which course you prefer :- 1. CakePHP 2. Zend 3. Perl 4. Python 5. Symfony Any suggestions please and tell me an IDE for your suggestion.. right now i am using Dreamweaver cs6 , sublime 2 and notepad++ Thanks
  22. Thanks for reply That was a silly mistake on my part Now, I changed it to if(isset($_POST['send'])) Still blank page, but i tried this if(!isset($_POST['send'])) Now it showing , so the question is, why script is not setting it ?
×
×
  • 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.