Jump to content

etsted

Members
  • Posts

    274
  • Joined

  • Last visited

Everything posted by etsted

  1. that is the first time you vote on a content
  2. $sql = "SELECT vote FROM rate WHERE username = '$username' && file_name = '$file_name'"; $query = mysqli_query($con,$sql) or die(mysqli_error()); $row = mysqli_fetch_array($sql); $DB_vote = $row['vote']; //var_dump($DB_vote); //check to see if the user has voted on this file before if($rate_type === "good" && $DB_vote === 1) { $vote = 1; } else if($rate_type === "good" && ($DB_vote === 0 OR $DB_vote == NULL) ) { $vote = 1; } else if($rate_type === "good" && $DB_vote === -1) { $vote = 0; } else if($rate_type === "bad" && $DB_vote === 1) { $vote = 0; } else if($rate_type === "bad" && ($DB_vote === 0 OR $DB_vote == NULL) ) { $vote = -1; } else if($rate_type === "bad" && $DB_vote === -1){ $vote = -1; } $numrows = mysqli_num_rows($query); if($numrows === 0){ $sql = "INSERT INTO rate VALUES('','$file_name','$username','$vote')"; $query = mysqli_query($con,$sql) or die(mysqli_error()); } else if($numrows === 1){ $sql = "UPDATE rate SET vote = '$vote' "; $query = mysqli_query($con,$sql) or die(mysqli_error()); } I am trying to make a rate system that rate a file according to what he rated before. So when i press "bad" i get a value of -1 as expected, but then when i press "good" i get a value of 1 (stored in the DB), But it should have the value 0 as you can see in my code.
  3. why wont onmouseover work? I am trying to make a function so that when a specific titel is hovered over that titels name wil be put inside another div function pick_this(to_pick){ document.getElementById("suggested_query").innerHTML = to_pick; } var ajax = ajaxObj("GET", "suggested_query.php?q="+str+"&type="+type); ajax.onreadystatechange = function() { if(ajaxReturn(ajax) == true) { document.getElementById("suggested_query").style.height = "145px"; var suggested_titels = ajax.responseText.split("S_E_C_R_E_T__S_I_G_N__!_|_!_|"); //document.getElementById("suggested_query").innerHTML= suggested_titels[0]; for(var i =0; i< suggested_titels.length; i++) { document.getElementById("suggested_query").innerHTML+= "<span onmouseover='pick_this(this)'>" + suggested_titels[i] + "</span>"; } } }
  4. i have a search engine at my website but when i type something in i notice that the browser shows keyword that i have typed in before, and i dont like it, bcz i have my own "recommender".
  5. etsted

    AJAX AND PHP

    why dont i put the % at the front?
  6. etsted

    AJAX AND PHP

    i noticed something else, it doesnt show titel that does have a match.
  7. etsted

    AJAX AND PHP

    shoudnt this work? if ($q !== "") { $q=strtolower($q); $len=strlen($q); foreach($a as $name) { if ( (strcmp(substr($name,0,$len), substr($q,0,$len)) ) == true) { if ($hint==="") { $hint=$name; } else { $hint .= "<br> $name"; } } } } Because it dont In the DB i have 4 titels "6", "d", "green" and "nature" and if i type "n" then 6,d and green shows up then i try to type in "nature " (notice the space i put after nature) and then nature shows up at the end
  8. etsted

    AJAX and PHP

    whats the difference? show me an example
  9. etsted

    AJAX AND PHP

    ive tried to update it, and it almost work as i want i to but there are some small problems. if ($q !== "") { $q=strtolower($q); $len=strlen($q); foreach($a as $name) { if (strcmp(substr($name,$len), substr($q,0,$len))) { if ($hint==="") { $hint=$name; } else { $hint .= "<br> $name"; } } } } this script will shows you only what you search for, but if you search for "n" and i have: "green" "nice tv" then both of them will show, basically i want to make sure that when someone search for something the only matches should have what the user searched for at the beginning of the name, Not in the middle or the end or something like that.
  10. etsted

    AJAX AND PHP

    why does that matter? its actually right above where i call it like include_once("connect.php");
  11. etsted

    AJAX AND PHP

    $type = $_REQUEST['type']; $sql = "SELECT tittel FROM $type GROUP BY titel"; $query = mysqli_query($con,$sql); while($row = mysql_fetch_array($query)) { $a[] = $row['titel']; } // get the q parameter from URL $q=$_REQUEST["q"]; $hint=""; // lookup all hints from array if $q is different from "" if ($q !== "") { $q=strtolower($q); $len=strlen($q); foreach($a as $name) { if (stristr($q, substr($name,0,$len))) { if ($hint==="") { $hint=$name; } else { $hint .= "<br> $name"; } } } } // Output "no suggestion" if no hint were found // or output the correct values echo $hint==="" ? "no suggestions" : $hint;exit(); this script is supposed to show suggested titels according to what the user is typing in. But if i have several titel in the DB like this: "my new name" "name" "new" and i were to search "my new name" then all of the above titels will show, when only the first should.
  12. etsted

    AJAX and PHP

    i can see from here that the $_POST variables are not set, any clue? function rate(username,rate_type,file_name){ var ajax = ajaxObj("POST", "watch.php"); ajax.onreadystatechange() = function(){ if(ajaxReturn(ajax) == true){ document.getElementById("rate_Box").innerHTML = ajax.responseText; } } ajax.send("rate_type="+rate_type+"&username="+username+"&file_name="+file_name); } this is my AJAX and this is my new PHP if(isset($_POST['username'])) { $username = $_POST['username']; $file_name = $_POST['file_name']; $rate_type = $_POST['rate_type']; //check to see if the user has voted on this file before $sql = "SELECT rate_type,good_rate,bad_rate FROM rate WHERE username = '$username' && file_name = '$file_name'"; $query = mysqli_query($con, $sql) or die(mysqli_error($con)); $numrows = mysqli_num_rows($query); if($numrows != 1)//this means the user has not voted for this file before { $sql = "INSERT INTO rate VALUES('','$file_name','$username','$rate_type','','')"; $query = mysqli_query($con,$sql) or die(mysqli_error($con)); }// if else //this means it has voted before { //check to see what the user voted before $row = mysqli_fetch_array($sql); $DB_rate_type = $row['rate_type']; $DB_good_rate = $row['good_rate']; $DB_bad_rate = $row['bad_rate']; //if what the user wants to vote is not equal to what he voted before, continue... if($DB_rate_type != $rate_type) { if($rate_type === "good") { $DB_good_rate++; } else { $DB_bad_rate--; } $sql = "UPATE rate SET rate_type = '$rate_type' && good_rate = '$DB_good_rate' && bad_rate = '$DB_bad_rate' "; $query = mysqli_query($sql) or die(mysqli_error($con)); } else //else dont do nothing... { } } }
  13. etsted

    AJAX and PHP

    I am trying to make a rating system.
  14. etsted

    AJAX and PHP

    <span onclick="rate('<?php echo $log_username;?>','good','<?php echo $file_url;?>')" onmouseout="normal(this)" onmouseover="green(this)"> Good </span> | <span onclick="rate('<?php echo $log_username;?>','bad','<?php echo $file_url;?>')" onmouseover="red(this)" onmouseout="normal(this)"> Bad </span> <span id="rate_Box"></span> these are three divs. The two at the top are buttons. When you click on on of them they are supposed to trigger an AJAX function, but it doesnt work. function rate(username,rate_type,file_name){ var ajax = ajaxObj("POST", "watch.php"); ajax.onreadystatechange() = function(){ if(ajaxReturn(ajax) == true){ document.getElementById("rate_Box").innerHTML = ajax.responseText; } } ajax.send("rate_type="+rate_type+"&username="+username+"&file_name="+file_name); } i tried to use console.log on ajax.responseText, but nothing happened until i pressed one of the buttons, then it outputted "object is not a function". here is the PHP it is supposed to communicative with, and all of there are in the same file. if(isset($_POST['rate_type'])) { $username = $_POST['username']; $file_name = $_POST['file_name']; $rate_type = $_POST['rate_type']; //check to see if the user has voted on this file before $sql = "SELECT rate_type,good_rate,bad_rate FROM rate WHERE username = $username && file_name = $file_name"; $query = mysql_query($sql); $numrows = mysql_num_rows($query); if($numrows != 1)//this means the user has not voted for this file before { $sql = "INSERT INTO rate VALUES('','$file_name','$username','$rate_type')"; $query = mysql_query($sql); }// if else //this means it has voted before { //check to see what the user voted before $row = mysql_fetch_array($sql); $DB_rate_type = $row['rate_type']; $DB_good_rate = $row['good_rate']; $DB_bad_rate = $row['bad_rate']; echo "bra"; //if what the user wants to vote is not equal to what he voted before, continue... if($DB_rate_type != $rate_type) { if($rate_type === "good") { $DB_good_rate++; } else { $DB_bad_rate--; } $sql = "UPATE rate SET rate_type = $rate_type && good_rate = $DB_good_rate && bad_rate = $DB_bad_rate"; $query = mysql_query($sql); exit; } else//else dont do nothing... { exit; } } }
  15. etsted

    % difference

    Is there a function that allows me to compare two numbers, then give me the difference in %?
  16. can somebody look at this link http://widegrass.com/watch.php?f=2014090332451907354600000047014883 then click on "about" under the picture and you will see that the "Titel" has to much margin-top even though i have not specified it
  17. when i use this code for more usable code the facebook share and like buttons at the bottom disapear while the twitter share button statys function random_files($name,$table) { //include a function used to get random files from the database echo "<h2>Random $name:</h2> "; include_once("functions.php"); echo get_random_files("$table"); echo "<br><br><br><br><br><br><br><br><br>"; } random_files("images","images"); random_files("audios","mp3"); random_files("videos","videos");
  18. etsted

    live chat

    what functions would i use to create a live chat AJAX? or do i initiative echo functions in PHP? i can think of several ways to get there, but i dont have 2 computers so i woudnt be able to actually test it.
  19. you could use cookies, where the timerfor the cookie is inside the DB, then change the value to a negative number
  20. when i add <br> tags before any <h2> tag the <br> tag doesnt have any effect
  21. etsted

    changing the ext

    if i change the ext of a file for example a wmv file to mp4 will it run as a mp4 file? i tried it with HTML 5 but it didnt work, did i do something wrong?
  22. when i try to add <br> before the h2 tags it doesnt have any effect.
  23. at my website widegrass.com you can see that <h2> tags are not stacking properly. what wrong? i have tried to wrap all of the media file inside divs. i even used <br>
  24. etsted

    different heights

    here is a link to my webpage widegrass.com
×
×
  • Create New...