Jump to content

etsted

Members
  • Posts

    274
  • Joined

  • Last visited

Everything posted by etsted

  1. etsted

    hidden type

    it says Invalid argument supplied for foreach()
  2. etsted

    hidden type

    the function at the bottom is supposed to store both the value and name of the choosen argument, but only stores the name <body> <form action="hovedrett.php" method="post"> <select name="frett"> <option>rekkeplatte</option> <option>friske reker</option> </select> <br> <input type="submit" name="knapp" value="Neste"> </form> <?php $forrett = $_POST['frett']; function bevare($mat) { foreach($mat as $indeks => $verdi) { if( !strstr($indeks, "knapp")) { echo "<input type='hidden' name='$verdi' value='$indeks'> "; } // if } // foreach } bevare($forrett); ?></body>
  3. etsted

    unexpected t_IF

    this code generates unexpecteT_IF echo " <form> <select name='mnd'> <option value='jan'>jan</option> <option value='feb'>feb</option> <option value='mar'>mar</option> <option value='Apr' " . if($dagen_mnd == 'Apr'){echo "selected='selected'";} . ">Apr</option> </select> </form>";
  4. etsted

    ajax and php

    i have a pagination script with ajax and php, but i doesnt show anything on the page, not even erros. ajax.pagination.php <?phpinclude_once("connect.php");// This first query is just to get the total count of rows$sql = "SELECT COUNT(id) FROM data";$query = mysqli_query($con, $sql) or die(mysqli_error());$row = mysqli_fetch_row($query);// Here we have the total row count$total_rows = $row[0];// Specify how many results per page$rpp = 10;// This tells us the page number of our last page$last = ceil($total_rows/$rpp);// This makes sure $last cannot be less than 1if($last < 1){ $last = 1; } // Close the database connection mysqli_close($con); ?> <!DOCTYPE html> <html> <head> <script> var rpp = <?php echo $rpp; ?>; // results per page var last = <?php echo $last; ?>; // last page number function request_page(pn) { var results_box = document.getElementById("results_box"); var pagination_controls = document.getElementById("pagination_controls"); results_box.innerHTML = "loading results ..."; var hr = new XMLHttpRequest(); hr.open("POST", "pagination_parser.php", true); hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); hr.onreadystatechange = function() { if(hr.readyState == 4 && hr.status == 200) { var dataArray = hr.responseText.split("||"); var html_output = ""; for(i = 0; i < dataArray.length - 1; i++) { var itemArray = dataArray.split("|"); html_output += "ID: "+itemArray[0]+" - Testimonial from <b>"+itemArray[1]+"</b><hr>"; } results_box.innerHTML = html_output; } } hr.send("rpp="+rpp+"&last="+last+"&pn="+pn); // Change the pagination controls var paginationCtrls = ""; // Only if there is more than 1 page worth of results give the user pagination controls if(last != 1) { if (pn > 1) { paginationCtrls += '<button onclick="request_page('+(pn-1)+')"><</button>'; } paginationCtrls += ' <b>Page '+pn+' of '+last+'</b> '; if (pn != last) { paginationCtrls += '<button onclick="request_page('+(pn+1)+')">></button>'; } } pagination_controls.innerHTML = paginationCtrls; } </script> </head> <body> <div id="pagination_controls"></div> <div id="results_box"></div> <script> request_page(1); </script> </body> </html> pagination.parser.php <?php// Make the script run only if there is a page number posted to this scriptif(isset($_POST['pn'])) { $rpp = preg_replace('#[^0-9]#', '', $_POST['rpp']); $last = preg_replace('#[^0-9]#', '', $_POST['last']); $pn = preg_replace('#[^0-9]#', '', $_POST['pn']); // This makes sure the page number isn't below 1, or more than our $last page if ($pn < 1) { $pn = 1; } else if ($pn > $last) { $pn = $last; } // Connect to our database here include_once("connect.php"); // This sets the range of rows to query for the chosen $pn $limit = 'LIMIT ' .($pn - 1) * $rpp .',' .$rpp; // This is your query again, it is for grabbing just one page worth of rows by applying $limit $sql = "SELECT id, navn FROM data ORDER BY id DESC $limit"; $query = mysqli_query($con, $sql) or die(mysqli_error($con)); $dataString = ''; while($row = mysqli_fetch_array($query, MYSQLI_ASSOC)) { $id = $row["id"]; $navn = $row["navn"]; $dataString .= $id.'|'.$navn.'||'; } // Close your database connection mysqli_close($con); // Echo the results back to Ajax echo $dataString; exit(); } ?>
  5. i was reading ajax in w3schools, and saw the example of callbacks functions, but i didnt get it. What does a callback function do. I tried searching a little but found no examples.
  6. etsted

    ajax

    what does it mean by saying "when a cached file is not an option"?
  7. etsted

    ajax

    in w3schools it says that i have to use POST when A cached file is not an option (update a file or database on the server). What does that mean?
  8. etsted

    class inside class

    targeting a class inside another class doesnt seem to work for me. .flip3D > .back{ position: absolute; color: #FC0; }
  9. etsted

    faveicon

    when u use a faveicon for your website, what is the profile attribute for? the one u place in the head element?
  10. etsted

    canvas

    why arent the dashline supported? and where isnt it supported?
  11. etsted

    canvas

    why cant i use the setlinedash function in canvas?
  12. etsted

    single quotes

    but u are supposed to use them With links
  13. because they have the same first parameter "click". thescientist, i have updated the script, so that btn2 has a referance
  14. etsted

    canvas

    what does it mean that i can back-reference the canvas element through the context object in this script? alert(ctx.canvas.id+" | "+ctx.canvas.width+" | "+ctx.canvas.height); in w3school they would only write "ctx.id".
  15. etsted

    single quotes

    But wont the double quotes keep it all together?
  16. etsted

    script

    when i use the setTimeout function why do i have to use quotes around the first parameter when it is a function? <script> function renderTime() {var time = new Date();var h = time.getHours();var m = time.getMinutes();var s = time.getSeconds();var diem = "AM"; if( h == 0){ h = 12;} else if(h > 12){ h = h - 12;diem = "PM";} if(h < 10){h = "0" + h;} if(m < 10){m = "0" + m;} if(s < 10){s = "0" + s;} var clock = document.getElementById("displayClock");clock.innerText = h + ":" + m + ":" + s + " " + diem;clock.innerText = h + ":" + m + ":" + s + " " + diem;setTimeout(renderTime(),1000); }renderTime();</script>
  17. This is my script: <!DOCTYPE html> <html> <head> <script type="text/javascript"> function addEventHandling(){ var btn1 = document.getElementById('btn1'); btn1.addEventListener('click', function(){btnClick("eggs","beef")}, true); btn2.addEventListener('click', function(){btnClick("grid","hest")}, false); function btnClick(arg1,arg2){ alert("This button click has "+arg1+" and "+arg2+" associated with it."); } } window.onload = addEventHandling; </script> </head> <body> <button id="btn1">I have food associated with me</button> <button id="btn2">I have food associated with me</button> </body> </html> and as i understod it, when i click on btn1, btn2 should trigger, but thats not the case. I have tried to use both false and true values as the third argument, but nothing special happens. They still run the same.
  18. i have noticed this functions Third parameter, useCapture, and i dont understand it. Can someone explain what it actually does? Give examples.
  19. etsted

    single quotes

    $previous = ''; $paginationCtrls .= '<a href=" ' . $_SERVER['PHP_SELF']. '?pn=$previous">Previous</a>'; $paginationCtrls .= '<a href="$_SERVER['PHP_SELF']?pn=$previous">Previous</a>'; only the second code Works, becuase i have used single quote concatination, why doesnt the third line work?
  20. etsted

    php

    i am trying to understand this code, my question is. Where does the 1 sign at the front of the output come from? When u output this, there is a number 1 at the front $myArray = array(500.00, 300.00, 200.00); $result = 2; foreach ($myArray as $key => $value) { $result = $result + $value; } $output = number_format($result, 2, '.', ','); echo "<h2>$". $output. "</h2>"; the result is: $1,000.00where does the 1 come from?
  21. etsted

    div position

    i am trying to get the chat_box to be display right under message_box. But i wont go any further up. <style type="text/css"> #mainDiv{ width: 700px; margin-top: -150px; } #mainDiv > #message_box{ width: 500px; height: 400px; background-color: green; float: left; margin-top: 200px; } #mainDiv > #player_box{ width: 200px; height: 600px; float: left; background-color: red; margin-top: 200px; display: inline; } #mainDiv > #chat_box{ width: 300px; display: inline; float: left; margin-bottom: 150px; } </style></head><body><div id="mainDiv"> <div id="message_box"></div> <div id="player_box"></div> <div id="chat_box"> <form method="POST" action="index.php"> <textarea rows="5"></textarea> <input type="submit"/> </form> </div></div>
  22. etsted

    crypt()

    what symbols does crypt() use, when it is hashing passwords?
  23. i am trying a script that wont work when i use double quotes like this: setTimeout('resetScroller("+el+")',speed); but instead i have to use thi syntax: setTimeout('resetScroller(''+el+'')',speed); whats the diffrence? Because they wont give the same result.
  24. etsted

    UNIQUE KEY

    so the line "username" after KEY just points out where mysql should look?
×
×
  • Create New...