Jump to content

etsted

Members
  • Posts

    274
  • Joined

  • Last visited

Posts posted by etsted

  1. 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

  2. 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.

  3. $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.

  4. 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...                    {                                            }                }           }
  5. <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;                    }                }            }    
  6. 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");
  7. 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.

  8. here i have a script that i run several times with a while loop bu every time the loop runs the next div has a higher margin-top than the next div

    $videos .= "<div class='files' style='float:left; background:#eaeaea; width:150px; color: black;' id='file_".$id."'>n                     <a href='watch.php?f=".$file_url[0]."'><img src='$avatar' height='60' width='60' alt='$titel'> Click here</a>                                 <br>                                 <span style='float:left; text-overflow:ellipsis;'>Titel: $titel</span>n                                 <br>                                 <span>Uploaded by: <a href='user.php?u=$username'>$username</a></span>                                 <br>                                 <br>                               </div>n <br> <br>n";
  9. // this makes every file name unique	$fileName = $_FILES['Filedata']['name'];	$kaboom = explode(".",$fileName);	$ext = "";	$ext = end($kaboom);	$ext = strtolower($ext);        $fileName = date("YmdjzHhisu") . rand(10000000,99999999) . ".$ext";				// defines what the ext can be	$imageTypes = array('jpg','jpeg','gif','png');	$videoTypes = array('mp4','webm','ogg','wmv');	$audioTypes = array('mp3','ogg','wav');			$title = $_POST['title'];	$description = $_POST['description'];	$username = $_POST['username'];		// include DB connection	include_once ("../connect.php");			// use the pathinfo to match the ext of the uploaded file	$fileParts = pathinfo($_FILES['Filedata']['name']);	$fileParts = $fileParts['extension'];	$fileParts = strtolower($fileParts);		if (in_array($fileParts,$imageTypes)) { // this is for images	// insert into DB		$sql = "INSERT INTO images VALUES('', '$title', '$description', '$username', '$fileName'  , NOW(), '')";		$query = mysqli_query($con, $sql);		move_uploaded_file($tempFile, "../u_image/" . $fileName);		echo '1';	} else if(in_array($fileParts, $videoTypes)){ // this is for videos	// insert into DB		$sql = "INSERT INTO videos VALUES('', '$title', '$description', '$username', '$fileName'  , NOW(), '')";		$query = mysqli_query($con, $sql);		move_uploaded_file($tempFile, "../videos/" . $fileName);		echo '1';	} else if(in_array($fileParts,$audioTypes)){ // this is for audios	// insert into DB		$sql = "INSERT INTO mp3 VALUES('', '$title', '$description', '$username', '$fileName'  , NOW(), '')";		$query = mysqli_query($con, $sql);		move_uploaded_file($tempFile, "../audio/" . $fileName);		echo '1';	} else {		echo "Invalid file.";	}

    this script is supposed to store images , videos and mp3. It only store images not mp3 or video file.

    I have created the map for mp3 videos and images.

  10. i dont find any functions for detecting browser type. I am trying to build an application so that depending on the users browser the HTML5 mediaplayer will use a different extension for the file being played.

  11. CREATE TABLE IF NOT EXISTS comments (                 id INT(11) NOT NULL,                osid INT[11) NOT NULL,				account_name VARCHAR(255) NOT NULL,				author VARCHAR(255) NOT NULL,				type ENUM NOT NULL,				data TEXT,				postdate DATETIME,                PRIMARY KEY (id),                )

    It says i have an error at line 3

×
×
  • Create New...