Jump to content

Recommended Posts

I have these selections in 1 file that the user is able to configure themselves via a form in their control panel....I've got it all working but I was wondering if this is a good way of doing it or not...

 

 

$bandnamesql = mysql_query("SELECT * FROM config WHERE config_name = 'bandname'");
while($row = mysql_fetch_array($bandnamesql))
{
 $bandname = $row['config_value'];  
}

$copyrightsql = mysql_query("SELECT * FROM config WHERE config_name = 'copyright'");
while($row = mysql_fetch_array($copyrightsql))
{
 $copyright = $row['config_value'];  
}

 

 

I posted this in the PHP help forum by accident and someone said something about using "OR" for the last 2 selections to increase performance...any help would be appreciated.

Link to comment
https://forums.phpfreaks.com/topic/58425-solved-is-this-a-valid-mysql-selection/
Share on other sites

I started messing around a bit, and am now using this:

 

$configsql = mysql_query("SELECT * FROM config 
                          WHERE config_name = 'bandname'
                          OR config_name = 'copyright'
                          ");
while($row = mysql_fetch_array($configsql))
{
  if ($row['config_name'] == 'bandname')
  {
  $bandname = $row['config_value'];
  }
  
  if ($row['config_name'] == 'copyright')
  {
  $copyright = $row['config_value'];
  }
}

 

This look better?

I'm confused... where is the column that indicates which band these settings are pertinent to, or is this a cms application where the assumption is that someone will run this application on their website?

 

The answer to your specific question is that I would probably just select all settings, and I would write a routine that would read all these settings into an array.  With that said, if you want to stay with what you have, the 2nd approach is definately an improvement (one query vs. 2) .

I'm confused... where is the column that indicates which band these settings are pertinent to, or is this a cms application where the assumption is that someone will run this application on their website?

 

The answer to your specific question is that I would probably just select all settings, and I would write a routine that would read all these settings into an array.  With that said, if you want to stay with what you have, the 2nd approach is definately an improvement (one query vs. 2) .

 

Well I am really new to PHP and MySQL, so I have made it so this would be run as a bands web site. I will look into arrays and MySQL selections to improve my code, thanks for the input.

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.