First time poster here...
Just wondering if anyone can help me turn my function's results into a global variable that I can use in another php page...
$sql = "SELECT title FROM table_1 WHERE id >= '1' and id <='10'";
function dbCall($servername, $username, $password, $dbname, $sql) {
global $item;
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_array($result)) {
$item=("'". $row[0]."', ");
echo $item;
}
} else {
echo "0 results";
}
return $list;
$conn->close();
}
Currently it returns a list of the results:
'tom', 'mary', 'joseph', 'jim', 'kathy', 'bob', 'luke', 'sam', 'heidi', 'tiffany',
But I can't call this as a global variable in my other php page...
Could anyone help?
Edit:
Actually when I call the fucntion I get this one the other page:
include ("C:\inetpub\wwwroot\db-call.php");
$varList = array(dbCall($servername, $username, $password, $dbname));
echo $varList;
And I get this result back:
'tom', 'mary', 'joseph', 'jim', 'kathy', 'bob', 'luke', 'sam', 'heidi', 'tiffany',Array
Thanks again!---
Thanks,