Re: define variable by querying MySQL
| From: | Dobromir Velev | Date: | Mon, 02 Jul 2001 08:34:14 +0000 |
| Subject: | Re: define variable by querying MySQL | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-10012@lists.php.net to get a copy of this message | ||
Hi,
I'm not sure what were you trying to do but there are some very obvious
errors
1. You cannot embed one php openning tag (<?) in another
2. mysql_numrows() is not a valid mysql function - may be you were trying to
use mysql_num_rows()
If you are trying to put all fields my_name into the $WELCOME variable (I
can't think of a reason to do this) and then echo it may be you could use
this code
#start code
<?
$link = mysql_connect("localhost","username","password") or die
("Could not
connect to MySQL!");
mysql_select_db("database",$link);
$result = mysql_query("select * from table_name);
while ($row=mysql_fetch_array($result)){
$WELCOME.=$row["my_name"];
}
echo $WELCOME;
?>
#end code
Dobromir Velev
-----Original Message-----
From: Matt Nigh <matt@mattnigh.com>
To: php-db@lists.php.net <php-db@lists.php.net>
Date: Monday, July 02, 2001 1:01 AM
Subject: [PHP-DB] define variable by querying MySQL
hello list. i have a problem that is relatively simple, but I can't seem to
figure it out.
is there any way to define a variable by querying a MySQL database?
here's an example of code I tried using:
----------------------------------------------------------------
<?
$WELCOME = "
echo "<?php
$link = mysql_connect("localhost","username","password");
if(!$link) die ("Could not connect to MySQL!");
mysql_select_db("database",$link);
$result = mysql_query("select * from table_name);
$num=mysql_numrows($result);
for($x=0;$x<$num;$x++) {
$row=mysql_fetch_object($result);
print "$row->my_name";
}
mysql_close($link);
?>
";
";
?>
<? echo($WELCOME); ?>
----------------------------------------------------------------
it kept coming up with the following :
----------------------------------------------------------------
Parse error: parse error, expecting
T_STRING' or T_VARIABLE' or
`T_NUM_STRING' in c:\apache group\apache\htdocs\page.php on line 5
----------------------------------------------------------------
i can't figure out what to do, so if anyone can assist me, i'd be greatful.
I have a feeling it's something with some quotes but i can't figure out
which ones.
Thanks a lot,
Matt Nigh
matt@mattnigh.com