Jump to content

miguelfsf

Members
  • Posts

    13
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

miguelfsf's Achievements

Newbie

Newbie (1/5)

1

Reputation

  1. // player.php (popup) <?php session_start(); include("include/player-functions.php"); uniqueMixtapeListens($db,$_GET['id']); if(!isset($_GET['id'])){ header('location: index.php?p=home');exit(); } ?> <!DOCTYPE html> <html><head><title>Player</title></head> <body> // player code </body> </html> //player_functions.php <?php function uniqueAlbumListens($db,$id){ if(!isset($_COOKIE["ml".$id])){ updateListens($db,$id); } setcookie("ml".$id, "listens", time()+60*2); // 2minutes -> 60*2 ? || 6h -> 60*60*6 ? } function updateListens($db,$id){if(isset($_GET['id']) && isset($_GET['host'])){ $sql = "UPDATE mixtape SET listens = listens + 1 WHERE id=?"; $stm = $db->prepare($sql); $stm->execute(array($id)); } } ?> Code updated. Hope you can test it. What do you mean with "if you are setting is at the top of a script and then trying to read it a second later you're not going to see it." ? Can you explain better..? I cant really understand sorry..
  2. Hello, I have a song streaming website, and i want to set a cookie inside a player popup to avoid that users increment the number of times that an album was played every time they access it. I want the cookie to last at least 6h, but every time i test the code with 1,2 or 5 minutes it never ends in the time that i specify. For example i want it to last 3min and it may take 5 or 2min to end. Cant figure out why, because i used the same cookie code in a none popup window and it worked. // player.php (POPUP) <?php session_start(); include("include/player-functions.php"); uniqueAlbumListens($db,$_GET['id']); (...) ?> //player_functions.php <?php (...) function uniqueAlbumListens($db,$id){ if(!isset($_COOKIE["ml".$id])){ updateListens($db,$id); } setcookie("ml".$id, "listens", time()+60*2); // 2minutes -> 60*2 ? || 6h -> 60*60*6 ? } (...) ?>
  3. Didnt work.. It has only listed one mixtape with the sum of all rates, but i want the rate that is specific to that mixtape I tested the sql code on my phpmyadmin and for total i got 38 and it should be 6. For example, this is what i have on my vote table: The total of the id_mixtape number 4 should be 20+12=32 and the total of id_mixtape number 3 should be 6, and then it orders each mixtape by this value on DESC order.
  4. Hello, Lets if i can explain this well (sorry for bad english!) I have two differents tables on my db "Mixtapes" and "Vote" and i want to order them in DESC order by the SUM of all rate values that belong to a specific mixtape. Mixtapes: id name status (etc) Vote id_mixtape // id_mixtape = id in Mixtapes table rate This is the query that im using but its not listing in Desc order, dont know why: "SELECT id,name FROM mixtape WHERE status=1 AND id IN(SELECT id_mixtape FROM vote GROUP BY id_mixtape ORDER BY SUM(rate) DESC) LIMIT 12"
  5. First of all thanks for the help, I appreaciate it. That would work if in my db table for songs I had only one field for link but I have 3 fields(link1,link2 and link3). I have multiple songs in the form and for each song there are 3 different links. Could you understand what im saying? Sorry my bad english.. Can you explain also what implode is meant to do? Thanks. foreach($_POST['song'] as $i => $song) { $data = "'$song','" . implode("','", $_POST['link'][$i]) . "'"; //INSERT INTO table_name VALUES ($data) }
  6. Hello, This is my form: <form name="form" action="..."><div style="border:1px solid grey;"> <b>Song Name'.$i.':</b> <input type="text" name="song[]"> Link 1: <input type="text" name="link1[]"><br> Link2: <input type="text" name="link2[]"><br> Link3: <input type="text" name="link3[]"><br> </div> </form> This is my code: foreach($_POST['song'] as $item1){ //INSERT CODE for songname,link1,link2 and link3 } My for each loop is only optimized for inserting the song name. I want to get the value of the song,link1,2,3 and insert them at the same time. How can i do it?
  7. OMG, it worked thanks alot!!! I have been for 2 days trying to figure out this! Thank you
  8. Yes,you correct about that i didnt explain well. So, how should I send the array from getHost to get_link?
  9. Hello, Well, basically what this code does is grab some links from a source code of a website and send them to an mp3 player. The big problem is on the get_link function, where i want to store the urls to an array. The section where im having problems is commented. Sorry for posting all this code but the functions are connected to each others. function getHost($db,$id){ if(isset($_GET['id'])){ $sql1 = "SELECT host FROM mixtape WHERE id=?"; $stm = $db->prepare($sql1); $stm->execute(array($id)); $row1 = $stm->fetch(PDO::FETCH_ASSOC); if($row1['host']=='host1'){ $sql2 = "SELECT link1 FROM faixa WHERE id_mixtape IN(SELECT id FROM mixtape WHERE id=?)"; $stm = $db->prepare($sql2); $stm->execute(array($id)); $rows_affected = $stm->rowCount(); $array=array(); if (count($rows_affected) > 0) { for($i=1; $i <= $rows_affected; $i++) { $row2 = $stm->fetch(PDO::FETCH_ASSOC); $url=$row2['link1']; get_Link($db,$url,$i,$rows_affected,$array); } } } } } function get_Link($db,$url,$pos,$rows_affect,$array){ $find = 'url:'; $reg_exUrl = "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/"; $data = file_get_contents($url); $data = explode("\n", $data); for ($line = 0; $line < count($data); $line++) { if (strpos($data[$line], $find) !== false) { $link = preg_replace($reg_exUrl,"", $data[$line]); $v[]=$link; } } if($pos!=$rows_affect-1){ $url="mylink.com/".$link."|"; }else{ $url="mylink.com/".$link."&amp"; } $array[$pos]=$url; var_dump($array); // Here says that are 3 values in the array. True if($pos==$rows_affect-1){ var_dump($array); // Here is only showing the last value in the array. Why? player($db,$array); } } function player($db,$array){ if(isset($_GET['id'])){ foreach($array as $i=>$item){ echo $item; } } }
×
×
  • 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.