hello i am new to JavaScript and i need help with this code of comments system, the idea is to set the page id same as the folder name which is a page id on smarty example : my pages looks like http://domain.com/video/1245/... i have this javascript which print the page id 1245 like this <SCRIPT LANGUAGE="JavaScript">pathis=location.pathname; new_array=pathis.split("/"); subdirectory=new_array[2]; // 4 is a guess, try others document.write(subdirectory);</SCRIPT> Code (markup): and my php looks like this : <?php $page_id = 1; // for example include("comments/comments_show.php"); include("comments/comments_form.php"); ?> PHP: so here i want instead of page_id=1 to use the script code above to use my folder name 1245 .. any help plz ?
your javascript: document.location.href = "myphpfile.php?id="+subdirectory; Code (markup): And your php file: <?php $page_id = $_GET["id"]; //Get the id passed in the url here include("comments/comments_show.php"); include("comments/comments_form.php"); ?> PHP:
Hi! Try This Method. <?php $id = ' <script> document.write("007"); </script> '; $page_id = $id; print $page_id; ?>
thank you very much ,worked perfectly as i wanted ,here is what i did : <SCRIPT LANGUAGE="JavaScript">document.location.href = "index.php?module=video&id="+subdirectory;</SCRIPT> <?php $page_id = $_GET["id"]; //Get the id passed in the url here include("comments/comments_show.php"); include("comments/comments_form.php"); ?> PHP: