Jump to content

Call db table from any PHP file


CBG

Recommended Posts

Hi,

 

I want to be able to call a database table that will be setup in another file called init.php, and be able to call it from any PHP file that has init.php included.

 

Table is called abc_offline and has columns a,b,c in it.

 

What I am wanting is to be able to call it from any PHP file by:

$offline['a'] for example

 

How do I do this, I been told I need an array in init.php but I don't know how to do this.

 

At the moment the init.php has the DB conncect details and some calls to other tables.

 

 

Column a in abc_offline would have the value as offline or online

So what I want to do is, in any file be able to have

 

This code could be in any file

if ( $offline['a'] == 'online' ) { header ('location: index.php'); }

OR

if ( $offline['a'] == 'offline' ) { header ('location: offline.php'); }

 

I need the code to go in the init.php as I haven't got a clue what to put, to be able to able to call the table and assign $offline to any file.

Link to comment
https://forums.phpfreaks.com/topic/192615-call-db-table-from-any-php-file/
Share on other sites

You'd need to get the values from the database and put them in the $offline array.

 

E.g.

 

<?php
$offline = array();

// Execute query
$sql = mysql_query("SELECT a, b, c FROM some_table LIMIT 1");

// Get the key and the corresponding value and place them into the $offline array
foreach (mysql_fetch_assoc($sql) as $key => $val) {
  $offline[$key] = $val;
}
?>

 

I think that's what you're looking for.

You'd need to get the values from the database and put them in the $offline array.

 

E.g.

 

<?php
$offline = array();

// Execute query
$sql = mysql_query("SELECT a, b, c FROM some_table LIMIT 1");

// Get the key and the corresponding value and place them into the $offline array
foreach (mysql_fetch_assoc($sql) as $key => $val) {
  $offline[$key] = $val;
}
?>

 

I think that's what you're looking for.

 

Thanks, will give it a try later.

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.