CBG Posted February 19, 2010 Share Posted February 19, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/192615-call-db-table-from-any-php-file/ Share on other sites More sharing options...
Catfish Posted February 19, 2010 Share Posted February 19, 2010 Explain what "calling" a table is? I've never read this terminology before. Do you mean selecting records from a table? Quote Link to comment https://forums.phpfreaks.com/topic/192615-call-db-table-from-any-php-file/#findComment-1014772 Share on other sites More sharing options...
Wolphie Posted February 19, 2010 Share Posted February 19, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/192615-call-db-table-from-any-php-file/#findComment-1014773 Share on other sites More sharing options...
CBG Posted February 19, 2010 Author Share Posted February 19, 2010 Explain what "calling" a table is? I've never read this terminology before. Do you mean selecting records from a table? Yes that what I mean. Quote Link to comment https://forums.phpfreaks.com/topic/192615-call-db-table-from-any-php-file/#findComment-1014779 Share on other sites More sharing options...
CBG Posted February 19, 2010 Author Share Posted February 19, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/192615-call-db-table-from-any-php-file/#findComment-1014780 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.