December 7, 201114 yr how i can disply the video on div #video by dynamic linking in navigation menu the video store in database <?php while($row =mysql_fetch_row($query)) { $titile =$row[2]; $ids= $row[1]; ?> <p> <a href="index.php?id.=<?php echo $ids ;?>".><? print "$titile<br>"?> </a></p> <? } ?> </div>
December 7, 201114 yr The secret is to swap the innerHTML of the div that will be holding the video, this can be done using a full page reload passing the output of the navigation button as a get request or you can use javascript with a little Ajax that will change the contents without refreshing the entire page. Basic Demo: http://lovelogic.net/z_tuts/ajax1.php Video Page: <head> <title>Ajax div swapper</title> <script type="text/javascript"> function loadXMLDoc(target) { var xmlhttp; if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("myDiv").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","fetch_video.php?target="+target,true); xmlhttp.send(); } </script> </head> <body> <div id="myDiv"><h2>Let AJAX change this text</h2></div> <button type="button" onclick="loadXMLDoc(1)">First item</button> <button type="button" onclick="loadXMLDoc(2)">Second item</button> </body> </html> fetch_video.php <?php //// basic video swap without SQL $target = ($_GET["target"]); if ($target==1) $output='<iframe width="420" height="315" src="http://www.youtube.com/embed/TsevuRJz6pc" frameborder="0" allowfullscreen></iframe>' ; if ($target==2) $output='<iframe width="420" height="315" src="http://www.youtube.com/embed/b5mVELsbM_M" frameborder="0" allowfullscreen></iframe>' ; echo '<h1>'.$output.'</h1>'; ?>
December 7, 201114 yr Author thank u can u make the code with php and html code becouse i cant understand ajax code Edited December 7, 201114 yr by ehsan_cs
December 7, 201114 yr demo.php <?php //// basic video swap without SQL //// and no javascript $target = ($_GET["target"]); if ($target==1) $output='<iframe width="560" height="315" src="http://www.youtube.com/embed/DWCfRezQsWE" frameborder="0" allowfullscreen></iframe>' ; if ($target==2) $output='<iframe width="560" height="315" src="http://www.youtube.com/embed/H52DISr_OUg" frameborder="0" allowfullscreen></iframe>' ; if (!$target) $output = '<iframe width="560" height="315" src="http://www.youtube.com/embed/b5mVELsbM_M" frameborder="0" allowfullscreen></iframe> '; // if no target value set -> shows this ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>ehsan_cs - homework help</title> </head> <body> <?php echo $output; ?> <p><a href="demo.php?target=1">video one</a></p> <p><a href="demo.php?target=2">video two </a></p> </body> </html>
Create an account or sign in to comment