XLOSS Posted February 20, 2019 Share Posted February 20, 2019 I AM WORKING ON A PROJECT , I NEED YOUR HELP. I WANT TO USE EXISTING SRC OF IFRAME + RETRIVED VALUE FROM DATABASE INTO IFRAME This is my data.php to retrive values from database into iframe without refresh web page. <?php $conn = new mysqli('localhost', 'root', '', 'x'); if ($conn->connect_error) { die("Connection error: " . $conn->connect_error); } $result = $conn->query("SELECT number1 FROM users"); if ($result->num_rows > 0) { while ($row = $result->fetch_assoc()) { echo $row['number1'] . '<br>'; } } ?> FOLLOWING IS INDEX FILE <?php include('data.php') ?> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> </head> <body> <div id="show"></div> <script type="text/javascript" src="jquery-3.1.1.min.js"></script> <script type="text/javascript"> $(document).ready(function() { setInterval(function () { $('#show').load('data.php') }, 1000); }); </script> <iframe id="w3" src="DATABASE RETRIVED VALUE" height="80px" width="300px" frameborder="0" style="border: 0; width:300px; height:80px; background-color: #FFF;"></iframe> </body> </html> INDEX FILE CODES CAN SUCCESSFULLY RETRIVE VALUES FROM DATABASE BUT, I WANT TO STORE IT IN IFRAME SRC . VAR= URLS = 'HTTP://WWW.GOOGLE.COM' IFRAME SRC WILL BE VAR URLS + RETRIEVED VALUE FROM DATABASE Quote Link to comment https://forums.phpfreaks.com/topic/308356-help-retrieve-database-values-into-iframe-src/ Share on other sites More sharing options...
XLOSS Posted February 20, 2019 Author Share Posted February 20, 2019 data.php : <?php $ch = curl_init('example.com/'); // set curl option to fetch (get) $result = curl_exec($ch); echo $result; $conn = new mysqli('localhost', 'root', '', 'shoutout'); if ($conn->connect_error) { die("Connection error: " . $conn->connect_error); } $result = $conn->query("SELECT channel1 FROM users"); if ($result->num_rows > 0) { while ($row = $result->fetch_assoc()) { echo $row['channel1']. '<br>'; } } ?> index.php : <?php include('data.php') <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> </head> <body> <iframe id="w2" src="data.php" height="80px" width="300px" frameborder="0" style="border: 0; width:300px; height:80px; background-color: #FFF;"></iframe> </body> </html> i made some changes ,, i can retrive values but it is not appending , please help. i want to make url by using variable and database value . and want to load in iframe. thank you Quote Link to comment https://forums.phpfreaks.com/topic/308356-help-retrieve-database-values-into-iframe-src/#findComment-1564639 Share on other sites More sharing options...
cyberRobot Posted February 20, 2019 Share Posted February 20, 2019 For your data.php file, you could return the value you want to use for the "src" attribute...instead of echoing. An example of using a return in an include file can be found here:http://php.net/manual/en/function.include.php#example-127 Note that you'll want to read the text below the example, which talks about what will be returned if PHP is unable to include the file. Quote Link to comment https://forums.phpfreaks.com/topic/308356-help-retrieve-database-values-into-iframe-src/#findComment-1564645 Share on other sites More sharing options...
taquitosensei Posted February 20, 2019 Share Posted February 20, 2019 Your iframe id is different than the id you're using in your jquery to load the data. <script type="text/javascript"> $(document).ready(function() { setInterval(function () { $('#show').load('data.php') }, 1000); }); </script> should probably be <script type="text/javascript"> $(document).ready(function() { setInterval(function () { $('#w2').load('data.php') }, 1000); }); </script> Quote Link to comment https://forums.phpfreaks.com/topic/308356-help-retrieve-database-values-into-iframe-src/#findComment-1564647 Share on other sites More sharing options...
taquitosensei Posted February 20, 2019 Share Posted February 20, 2019 sorry w3 not w2 taxes on the brain Quote Link to comment https://forums.phpfreaks.com/topic/308356-help-retrieve-database-values-into-iframe-src/#findComment-1564648 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.