Stack Exchange
I'm over-querying my MySql database. Another way to retrieve many data?
I have this Table structure, and I'm retrieving data with many querys.

https://i.stack.imgur.com/q1Zjm.png

Here's how I'm querying the DB.
$siteurl = mysql_query("SELECT option_value FROM main_conf WHERE option_name = 'siteurl' ");
$_siteurl = mysql_result($siteurl,0);


$staticurl = mysql_query("SELECT option_value FROM main_conf WHERE option_name = 'staticurl' ");
$staticurl = mysql_result($staticurl,0);


$sitetitle = mysql_query("SELECT option_value FROM main_conf WHERE option_name = 'sitetitle' ");
$_sitetitle = mysql_result($sitetitle,0);


$sitesubtitle = mysql_query("SELECT option_value FROM main_conf WHERE option_name = 'sitesubtitle' ");
$_sitesubtitle = mysql_result($sitesubtitle,0);

$logofile = mysql_query("SELECT option_value FROM main_conf WHERE option_name = 'logofile' ");
$_logofile = mysql_result($logofile,0);

$cat1 = mysql_query("SELECT option_value FROM main_conf WHERE option_name = 'cat1' ");
$_cat1 = mysql_result($cat1,0);

$cat2 = mysql_query("SELECT option_value FROM main_conf WHERE option_name = 'cat2' ");
$_cat2 = mysql_result($cat2,0);

echo $_siteurl;

echo $_staticurl;

echo $_sitetitle;

echo $_sitesubtitle;

echo $_logofile;

echo $_cat1;

echo $_cat2;

Is there another way to do that?.
Thanks!

heard of the magical OR ? or even IN

Fetch as much as you need to with OR statements and iterate over the data.

Any example code please. I'm not lazy, but even I have no idea how to search correctly.

No, no, no. Not pngs. sqlfiddles... maybe

You'll probably find it easiest to fetch the results in one row.  You can do this in SQL using aggregation:
SELECT max(case when option_name = 'siteurl' then option_value end) as siteurl,
       max(case when option_name = 'sitetitle' then option_value end) as sitetitle,
       max(case when option_name = 'sitesubtitle' then option_value end) as sitesubtitle,
       max(case when option_name = 'logofile' then option_value end) as logofile,
       max(case when option_name = 'cat1' then option_value end) as cat1,
       max(case when option_name = 'cat2' then option_value end) as cat2
FROM main_conf
WHERE option_name in ('siteurl', 'sitetitle', 'sitesubtitle', 'logofile', 'cat1', 'cat2');

The results will be one row with six columns, one for each value.

Hello Gordon,
How can I put this work together in these scenario?
" Hi, my name url is  and here's my logo <img src="<?php echo $logofile; ?>" /> "
Many thanks for your reply... I really appreciate it.

@eplazai . . . This is the SQL part of the solution.  You need to manage the php code to read the six option values.  By the way, you should not use the "mysql_" interface, it is deprecated.

Gordon, I've made the homework. :D
..this is the full code.
<?php

SELECT max(case when option_name = 'siteurl' then option_value end) as siteurl,
       max(case when option_name = 'sitetitle' then option_value end) as sitetitle,
       max(case when option_name = 'sitesubtitle' then option_value end) as sitesubtitle,
       max(case when option_name = 'logofile' then option_value end) as logofile,
       max(case when option_name = 'cat1' then option_value end) as cat1,
       max(case when option_name = 'cat2' then option_value end) as cat2
FROM main_conf
WHERE option_name in ('siteurl', 'sitetitle', 'sitesubtitle', 'logofile', 'cat1',    'cat2');

//this is my homework, the php part of the problem

$siteurl = mysql_result($query_from_main_conf, 0, 0);
$staticurl = mysql_result($query_from_main_conf, 0, 1);
$sitetitle = mysql_result($query_from_main_conf, 0, 2);
$sitesubtitle = mysql_result($query_from_main_conf, 0, 3);
$logofile = mysql_result($query_from_main_conf, 0, 4);
$cat1 = mysql_result($query_from_main_conf, 0, 5);
$cat2 = mysql_result($query_from_main_conf, 0, 6);

?>

Then, I retrieved the content just using ECHOs.
i.e.
<?php echo $cat1; ?>

THANKS!!
