Jump to content

MySQL Help (mysql_fetch_array?)


Imtehbegginer

Recommended Posts

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
Share on other sites

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
Share on other sites

$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
Share on other sites

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
Share on other sites

$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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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