Jump to content

HELP-- RETRIEVE DATABASE VALUES INTO IFRAME SRC


XLOSS

Recommended Posts

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

 

 

 

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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>

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.