How can I output the value from database

temeral URL http://dot.kr/x-test/05.php

<!doctype html>
<html>
 
  <head>
    <meta charset="UTF-8">
    <title>test05</title>
  </head>

<body>
<?php
$connect=mysql_connect("localhost","root","*******");

$mysql=mysql_select_db("php02",$connect);

$query="select say from adText where n=2";

?>

</body>
</html>

The code above doesn’ cause any php errors.
So I guess it correctly calls the value from the database.
Now I like to print the value.

The following code seems doesn’t work correctly.

temeral URL http://dot.kr/x-test/07.php

<!doctype html>
<html>
 
  <head>
    <meta charset="UTF-8">
    <title>test05</title>
  </head>

<body>
<?php
$connect=mysql_connect("localhost","root","*******");

$mysql=mysql_select_db("php02",$connect);

$query="select say from adText where n=2";

[COLOR="Red"]echo $say[/COLOR]

?>

</body>
</html>

I want it outputs the value of it “myText2”, but it doesn’t print anything.

You need to use a result hander such as mysql_fetch_assoc


<?php
$connect=mysql_connect("localhost","root","*******");

$mysql=mysql_select_db("php02",$connect);

$query="select say from adText where n=2";
$rows = mysql_fetch_assoc($query);

echo $rows['say'];

?>

As I apply your code at http://dot.kr\x-test\07-01.php ,
it says mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource

oops didnt notice that you werent actually running the query


<?php
$connect=mysql_connect("localhost","root","*******");

$mysql=mysql_select_db("php02",$connect);

$query="select say from adText where n=2";
$sql = mysql_query($query);

$rows = mysql_fetch_assoc($sql);

echo $rows['say'];

?>

Thank you, spikeZ. It works fine.