Barand Posted February 5, 2015 Share Posted February 5, 2015 $POST should be $.post (call jquery $.post function) "Hva skjer her?" should be "text" (tell the function the response is plain text) Quote Link to comment https://forums.phpfreaks.com/topic/294097-data-from-a-table/page/3/#findComment-1504987 Share on other sites More sharing options...
asai Posted February 5, 2015 Author Share Posted February 5, 2015 Ok, now we are getting closer. When I click the link, theres a empty popup box. When I click OK the movie is shown. But theres nothing updating... The function(data). What is? Should't this be defined somewhere? I know, I am a bit slow... Quote Link to comment https://forums.phpfreaks.com/topic/294097-data-from-a-table/page/3/#findComment-1504996 Share on other sites More sharing options...
CroNiX Posted February 5, 2015 Share Posted February 5, 2015 (edited) The function(data). What is? Should't this be defined somewhere? No, see the documentation for jQuery's $post function. It's the "success" callback function and is already defined as part of $post. Edited February 5, 2015 by CroNiX Quote Link to comment https://forums.phpfreaks.com/topic/294097-data-from-a-table/page/3/#findComment-1505001 Share on other sites More sharing options...
asai Posted February 6, 2015 Author Share Posted February 6, 2015 Ok, now I am starting to understand this. One small thing: I suspect that the update.php file never runs or the filename parameter isn't correct. Is this line correct: $filename = $_POST['filename']; ?? Quote Link to comment https://forums.phpfreaks.com/topic/294097-data-from-a-table/page/3/#findComment-1505066 Share on other sites More sharing options...
Barand Posted February 6, 2015 Share Posted February 6, 2015 That line should be OK, the filename is being sentin $_POST['filename']. You could test it by putting exit ($filename); directly after that line. The filename should appear in the alert() box. Quote Link to comment https://forums.phpfreaks.com/topic/294097-data-from-a-table/page/3/#findComment-1505067 Share on other sites More sharing options...
asai Posted February 6, 2015 Author Share Posted February 6, 2015 Something is still missing here: I have tried this: function playVideo(url, filename) { $.post( "update.php", {filename: "filename"}) .done(function( data ) { alert( "Data loaded: " + data ); }); } The output from the alert is "filename" Not the actual filename i want. Quote Link to comment https://forums.phpfreaks.com/topic/294097-data-from-a-table/page/3/#findComment-1505082 Share on other sites More sharing options...
Barand Posted February 6, 2015 Share Posted February 6, 2015 You are passing the string "filename" instead of the variable filename Quote Link to comment https://forums.phpfreaks.com/topic/294097-data-from-a-table/page/3/#findComment-1505091 Share on other sites More sharing options...
CroNiX Posted February 6, 2015 Share Posted February 6, 2015 {filename: "filename"} is the opposite of what it should be, as Barand pointed out. Compare his original code to what you have. Quote Link to comment https://forums.phpfreaks.com/topic/294097-data-from-a-table/page/3/#findComment-1505093 Share on other sites More sharing options...
asai Posted February 7, 2015 Author Share Posted February 7, 2015 Theres something not going right here... I have placed the script inside the movies.php file. Is the place inside the file important? The update.php file is never run. The link opens the file, but not from within the script. Quote Link to comment https://forums.phpfreaks.com/topic/294097-data-from-a-table/page/3/#findComment-1505139 Share on other sites More sharing options...
asai Posted February 9, 2015 Author Share Posted February 9, 2015 Hi again, I have come a little further with my project. A small change from earlier, but now the update works. Then change is that I haven't a link, but instead uses a button. One small thing that doesn't work, that is the movie is not run. I am not sure how and where to put it. Heres my movies.php file: <html> <head> <link href="css/style.css" rel="stylesheet" type="text/css" media="screen" /> </head> <?php include 'combo.php'; include 'config.php'; include 'opendb.php'; $ndate = $_POST['ndate']; $result = mysql_query("SELECT * FROM DayMovie WHERE FileDate LIKE '$ndate%' ORDER BY FileDate DESC") or die(mysql_error()); echo "<table border='0'>"; echo "<tr> <th>Dato</th><th>Visninger</th><th>Handling</th></tr>"; while($row = mysql_fetch_array( $result )) { echo "<tr><td>"; echo date('d.m.Y', strtotime($row['FileDate'])); echo "</td><td>"; echo $row['Counter']; echo "</td><td>"; ?> <form name="form" method="POST" action="update.php"> <input name='filename' type='hidden' value=<?php echo $row['FileName'];?>> <input name='url' type='hidden' value=<?php echo "alldaymovies/{$row['FileName']}"?>> <input type="submit" value="Se film"> </form> <?php } echo "</td></tr>"; echo "</table>"; include 'closedb.php'; ?> </html> From here I post both filename and url to update.php update.php looks like this: <html> <head> <link href="css/style.css" rel="stylesheet" type="text/css" media="screen" /> </head> <?php include 'config.php'; include 'opendb.php'; $filename = $_POST['filename']; $url = $_POST['url']; $result2 = mysql_query("UPDATE DayMovie SET Counter=Counter+1 WHERE FileName='$filename'") or die(mysql_error()); include 'closedb.php'; ?> Right now I am not using the url. Theres 2 things I would like to happen from here: 1. The movie opens from the url in a new window. 2. The update.php returns to movies.php Is this possible and how? Quote Link to comment https://forums.phpfreaks.com/topic/294097-data-from-a-table/page/3/#findComment-1505272 Share on other sites More sharing options...
asai Posted February 10, 2015 Author Share Posted February 10, 2015 One simple question: How can i make $url be a combination of the variable $filename and the text "/alldaymovies/" ? Have tried this but it doesn't work: $url = "/alldaymovies/" $filename; Quote Link to comment https://forums.phpfreaks.com/topic/294097-data-from-a-table/page/3/#findComment-1505370 Share on other sites More sharing options...
CroNiX Posted February 10, 2015 Share Posted February 10, 2015 (edited) $url = "/alldaymovies/" . $filename; //you need to concatenate the variable $url = "/alldaymovies/$filename"; //or put it in the quotes Edited February 10, 2015 by CroNiX Quote Link to comment https://forums.phpfreaks.com/topic/294097-data-from-a-table/page/3/#findComment-1505373 Share on other sites More sharing options...
asai Posted February 10, 2015 Author Share Posted February 10, 2015 Fantastic! Thanks for quick reply. One final question: Is there a way to open this url in a new window from within the php file without having to click a link or button? Something like this: window.open($url); ?? Quote Link to comment https://forums.phpfreaks.com/topic/294097-data-from-a-table/page/3/#findComment-1505375 Share on other sites More sharing options...
asai Posted February 11, 2015 Author Share Posted February 11, 2015 This is now my update.php <html> <head> <link href="css/style.css" rel="stylesheet" type="text/css" media="screen" /> </head> <?php include 'config.php'; include 'opendb.php'; $filename = $_POST['filename']; $result2 = mysql_query("UPDATE DayMovie SET Counter=Counter+1 WHERE FileName='$filename'") or die(mysql_error()); include 'closedb.php'; $url = "http://81.166.2.19/alldaymovies/$filename"; window.open($url); ?> </html> The data is database is updated, but no window opens with the url. What's missing? Quote Link to comment https://forums.phpfreaks.com/topic/294097-data-from-a-table/page/3/#findComment-1505427 Share on other sites More sharing options...
asai Posted February 12, 2015 Author Share Posted February 12, 2015 No suggestions on my last question? Quote Link to comment https://forums.phpfreaks.com/topic/294097-data-from-a-table/page/3/#findComment-1505518 Share on other sites More sharing options...
Barand Posted February 12, 2015 Share Posted February 12, 2015 window.open($url); That is javascript. Repeat to yourself several hundred times, or until it sinks in, "PHP runs on the server, javascript runs on the client" 1 Quote Link to comment https://forums.phpfreaks.com/topic/294097-data-from-a-table/page/3/#findComment-1505543 Share on other sites More sharing options...
asai Posted February 13, 2015 Author Share Posted February 13, 2015 Sorry if I am a little slow... From this button is there a way to call a javascript function to open a new window from the url? : <form name="form" method="POST" action="update.php"> <input name='filename' type='hidden' value=<?php echo $row['FileName'];?>> <input type="submit" value="Se film"> </form> Quote Link to comment https://forums.phpfreaks.com/topic/294097-data-from-a-table/page/3/#findComment-1505593 Share on other sites More sharing options...
paddy_fields Posted February 13, 2015 Share Posted February 13, 2015 I haven't read back through all of the pages of posts so sorry if this has been coverered - but it seems more sensible to not use forms, and just put your viewing counter processing code on the page of wherever you're hosting the movie itself Just loop out a set of url's instead of submit buttons <?php while($row = mysql_fetch_array( $result )) { $output.= "<a href='alldaymovies.php?filename=$row[filename]' target='_blank'>$row['filename']</a>"; $output.= "<br>"; } echo $output; The use of '_blank' forces a new window to be opened in the browser. Then at the top of the actual movie page... $filename = $_GET['filename']; $result2 = mysql_query("UPDATE DayMovie SET Counter=Counter+1 WHERE FileName='$filename'") or die(mysql_error()); you need to escape $filename as it's open to SQL injection Quote Link to comment https://forums.phpfreaks.com/topic/294097-data-from-a-table/page/3/#findComment-1505605 Share on other sites More sharing options...
Barand Posted February 13, 2015 Share Posted February 13, 2015 Sorry if I am a little slow... From this button is there a way to call a javascript function to open a new window from the url? : <form name="form" method="POST" action="update.php"> <input name='filename' type='hidden' value=<?php echo $row['FileName'];?>> <input type="submit" value="Se film"> </form> You would do it in the function on return of the ajax response as you have been shown in reply #49 http://forums.phpfreaks.com/topic/294097-data-from-a-table/page-3?do=findComment&comment=1504950 Quote Link to comment https://forums.phpfreaks.com/topic/294097-data-from-a-table/page/3/#findComment-1505617 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.