Single row selection from MYSQL Query php

I have the following query:

$result = mysql_query("SELECT option_value FROM wp_10_options WHERE option_name='homepage'");
$row = mysql_fetch_array($result);
print_r ($row);

and the output I get is:

Resource ID # 2

Ultimately, I want you to be able to display the subscription field as follows:

$row['option_value']

Without using a while loop, because since I'm only trying to get one field, I don't see the point.

I also tried using mysql_result.

Where am I going wrong?

Please do not lecture me on PDO or mysqli.

+5
source share
11 answers

Try with mysql_fetch_assoc . It will return an associative array of strings corresponding to the selected row, or FALSE if there are no more rows. In addition, you should add LIMIT 1 if you really expect a single row.

$result = mysql_query("SELECT option_value FROM wp_10_options WHERE option_name='homepage' LIMIT 1");
$row = mysql_fetch_assoc($result);
echo $row['option_value'];
+19
$result = mysql_query("SELECT option_value FROM wp_10_options WHERE option_name='homepage'");
$row = mysql_fetch_assoc($result);
echo $row['option_value'];
+4

mysql_fetch_assoc mysql_fetch_array, .

+1

:

Array ()

... , , while. , ?

0

, , :

   $row['option_value']

? .

0

mysql_fetch_array , . ,

echo $row['option_value'];
0

WordPress? , ! , get_option!

0

shoude

    <?php

require_once('connection.php');

 //fetch table rows from mysql db
$sql = "select  id,fname,lname,sms,phone from data";

    $result = mysqli_query($conn, $sql) or die("Error in Selecting " . mysqli_error($conn));

    //create an array
    $emparray = array();

for ($i = 0; $i < 1; $i++) {
   $row =mysqli_fetch_assoc($result);

} $emparray[] = $row;
         echo $emparray ;
    mysqli_close($connection);
?>
0

, .

$result = mysql_query("SELECT option_value FROM wp_10_options WHERE option_name='homepage'");
$row = mysql_fetch_array($result);
echo $row['option_value'];
0

make sure your ftp transfers are in binary mode.

0
source

It works for me ..

$show = mysql_query("SELECT data FROM wp_10_options WHERE
 option_name='homepage' limit 1"); $row = mysql_fetch_assoc($show);
 echo $row['data'];
-1
source

All Articles