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.
SpikeZ
November 7, 2010, 10:05pm
2
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'];
?>
dotJoon
November 7, 2010, 11:01pm
3
spikeZ:
You need to use a result hander such as mysql_fetch_assoc
<!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";
$rows = mysql_fetch_assoc($query);
echo $rows['say'];
?>
</body>
</html>
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
SpikeZ
November 7, 2010, 11:29pm
4
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'];
?>
dotJoon
November 7, 2010, 11:38pm
5
Thank you, spikeZ. It works fine.