Imtehbegginer Posted July 8, 2009 Share Posted July 8, 2009 I am working on a cms and I have finished the install script. It creates a database called (yourprefix)_config. The config table has 2 columns, setting, and value. Say I have site_title in the setting column and MyCMS in the value column. How would I be able to retrieve and print the "MyCMS" value? Link to comment https://forums.phpfreaks.com/topic/165263-mysql-help-mysql_fetch_array/ Share on other sites More sharing options...
Bendude14 Posted July 9, 2009 Share Posted July 9, 2009 have you had a go at this already? use this as your query "SELECT value FROM (yourprefix)_config WHERE setting = 'site_title'" This will return only one row containing your site title, have a go and post back what you have. well one row presuming you only have site_title in the setting column once, which you should have Link to comment https://forums.phpfreaks.com/topic/165263-mysql-help-mysql_fetch_array/#findComment-871658 Share on other sites More sharing options...
Imtehbegginer Posted July 9, 2009 Author Share Posted July 9, 2009 That doesnt work, I get message: "Resource ID #6". What else could I do? Link to comment https://forums.phpfreaks.com/topic/165263-mysql-help-mysql_fetch_array/#findComment-871695 Share on other sites More sharing options...
Bendude14 Posted July 9, 2009 Share Posted July 9, 2009 can we see all your code... that is not a problem with the query if your table structure is how you said.. Ben Link to comment https://forums.phpfreaks.com/topic/165263-mysql-help-mysql_fetch_array/#findComment-871706 Share on other sites More sharing options...
Imtehbegginer Posted July 9, 2009 Author Share Posted July 9, 2009 $use_db = mysql_select_db($system->config[dbname], $systemc); $db['site_title'] = mysql_query("SELECT value FROM wowcms_config WHERE setting = 'site_title'")or die(mysql_error()); $db['exp_rate'] = mysql_query("SELECT value FROM wowcms_config WHERE setting = 'exp_rate'"); $db['gray_rate'] = mysql_query("SELECT value FROM wowcms_config WHERE setting = 'gray_rate'"); $db['white_rate'] = mysql_query("SELECT value FROM wowcms_config WHERE setting = 'white_rate'"); $db['green_rate'] = mysql_query("SELECT value FROM wowcms_config WHERE setting = 'green_rate'"); $db['blue_rate'] = mysql_query("SELECT value FROM wowcms_config WHERE setting = 'blue_rate'"); $db['purple_rate'] = mysql_query("SELECT value FROM wowcms_config WHERE setting = 'purple_rate'"); $db['orange_rate'] = mysql_query("SELECT value FROM wowcms_config WHERE setting = 'orange_rate'"); $db['artifact_rate'] = mysql_query("SELECT value FROM wowcms_config WHERE setting = 'artifact_rate'"); $db['allow_reg'] = mysql_query("SELECT value FROM wowcms_config WHERE setting = 'allow_reg'"); $db['site_on'] = mysql_query("SELECT value FROM wowcms_config WHERE setting = 'site_on'"); $db['root_dir'] = mysql_query("SELECT value FROM wowcms_config WHERE setting = 'root_dir'"); $db['theme'] = mysql_query("SELECT value FROM wowcms_config WHERE setting = 'theme'"); $db['license'] = mysql_query("SELECT value FROM wowcms_config WHERE setting = 'license'"); Link to comment https://forums.phpfreaks.com/topic/165263-mysql-help-mysql_fetch_array/#findComment-871707 Share on other sites More sharing options...
lore_lanu Posted July 9, 2009 Share Posted July 9, 2009 What Bendude14 said is essentially correct. Try this, however: $sql = "SELECT value FROM (yourprefix)_config WHERE setting = 'site_title'"; $result = mysql_query($sql); while ($row = mysql_fetch_assoc($result)) { $site_title = $row["site_name"]; } // You can now echo the variable echo "The site name is" . $site_title; You can then add more fields that you would like retrieved to the while loop. Link to comment https://forums.phpfreaks.com/topic/165263-mysql-help-mysql_fetch_array/#findComment-871716 Share on other sites More sharing options...
Imtehbegginer Posted July 9, 2009 Author Share Posted July 9, 2009 $db = mysql_select_db('wowcms', $systemc); $sql = "SELECT value FROM wowcms_config WHERE setting = 'site_title'"; $result = mysql_query($sql) or die(mysql_error()); while ($row = mysql_fetch_assoc($result)) { $site_title = $row["site_name"]; } Im using that, i've tried it everywhere... but nothing comes up. Link to comment https://forums.phpfreaks.com/topic/165263-mysql-help-mysql_fetch_array/#findComment-871724 Share on other sites More sharing options...
lore_lanu Posted July 9, 2009 Share Posted July 9, 2009 the code actually has to be: $db = mysql_select_db('wowcms', $systemc); $sql = "SELECT value FROM wowcms_config WHERE setting = 'site_title'"; $result = mysql_query($sql) or die(mysql_error()); while ($row = mysql_fetch_assoc($result)) { $site_title = $row["site_title"]; } Link to comment https://forums.phpfreaks.com/topic/165263-mysql-help-mysql_fetch_array/#findComment-871728 Share on other sites More sharing options...
p2grace Posted July 9, 2009 Share Posted July 9, 2009 I would recommend turning on error logging and starting there. // Enable displaying of errors error_reporting(E_ALL); ini_set('display_errors','on'); Link to comment https://forums.phpfreaks.com/topic/165263-mysql-help-mysql_fetch_array/#findComment-871730 Share on other sites More sharing options...
p2grace Posted July 9, 2009 Share Posted July 9, 2009 the code actually has to be: $db = mysql_select_db('wowcms', $systemc); $sql = "SELECT value FROM wowcms_config WHERE setting = 'site_title'"; $result = mysql_query($sql) or die(mysql_error()); while ($row = mysql_fetch_assoc($result)) { $site_title = $row["site_title"]; } You'd have to update your query in order to return the field "site_title". Link to comment https://forums.phpfreaks.com/topic/165263-mysql-help-mysql_fetch_array/#findComment-871731 Share on other sites More sharing options...
Bendude14 Posted July 9, 2009 Share Posted July 9, 2009 thats because you want the value column this $row["site_name"] should be $row['value'] you might want to try the code below if you have that many settings to retrieve. im presuming you only have two columns, setting and value this will get the value of setting and make it a variable storing the correct value inside it... $sql = "SELECT * FROM (yourprefix)_config"; $result = mysql_query($sql); while ($row = mysql_fetch_row($result)) { $$row[0] = $row[1]; echo "KEY: " . $row[0] . " - Value: " . $row[1] . "<br />"; } echo $site_title; Link to comment https://forums.phpfreaks.com/topic/165263-mysql-help-mysql_fetch_array/#findComment-871733 Share on other sites More sharing options...
Imtehbegginer Posted July 9, 2009 Author Share Posted July 9, 2009 KEY: site_title - Value: Welcome to WoWCMS v1.0 KEY: exp_rate - Value: Instant 70 KEY: gray_rate - Value: 1 KEY: white_rate - Value: 1 KEY: green_rate - Value: 1 KEY: blue_rate - Value: 1 KEY: purple_rate - Value: 1 KEY: orange_rate - Value: 1 KEY: artifact_rate - Value: 1 KEY: allow_reg - Value: 1 KEY: site_on - Value: 1 KEY: root_dir - Value: C:/Program Files/xampplite/htdocs KEY: theme - Value: alliance KEY: license_code - Value: AZIT-3JH9-SDI5-H83F-23DIF echo $site_title gives me Welcome to WoWCMS v1.0 I got that, now how to i use them one at a time, say i needed to set the theme by doing require('templates/THEMEVALUE/index.tpl'); Link to comment https://forums.phpfreaks.com/topic/165263-mysql-help-mysql_fetch_array/#findComment-871742 Share on other sites More sharing options...
Bendude14 Posted July 9, 2009 Share Posted July 9, 2009 the variables will be available outside your script like so.. require('templates/$theme/index.tpl'); what ever the key value was is the name of your variable... Ben Link to comment https://forums.phpfreaks.com/topic/165263-mysql-help-mysql_fetch_array/#findComment-871745 Share on other sites More sharing options...
Imtehbegginer Posted July 9, 2009 Author Share Posted July 9, 2009 This is great. Thank you so much. Link to comment https://forums.phpfreaks.com/topic/165263-mysql-help-mysql_fetch_array/#findComment-871746 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.