Discussion: php mysql question
Afficher un message
Vieux 25/03/2008, 19h17   #2
The Natural Philosopher
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: php mysql question

canajien@gmail.com wrote:
> is it possible to take a mysql query such as:
>
> <?php
> mysql_connect("localhost", "mysql_user", "mysql_password") or
> die("Could not connect: " . mysql_error());
> mysql_select_db("mydb");
>
> $result = mysql_query("SELECT id, name FROM mytable");
>
> while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
> printf("ID: %s Name: %s", $row[0], $row[1]);
> }
>
> mysql_free_result($result);
> ?>
>
>
> and turn it into a variable like $blah ?
>
> I know its not as simple as this:
>
> $blah = <?php
> mysql_connect("localhost", "mysql_user", "mysql_password") or
> die("Could not connect: " . mysql_error());
> mysql_select_db("mydb");
>
> $result = mysql_query("SELECT id, name FROM mytable");
>
> while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
> printf("ID: %s Name: %s", $row[0], $row[1]);
> }
>
> mysql_free_result($result);
> ?>
>
> but shouldn't I be able to replace the <?php ?> tags with something
> like brackets ( ) or braces { } if so how do I do that, or is it more
> complicated?



Just replace the printf with

$blah.=sprintf...
  Réponse avec citation
 
Page generated in 0,05342 seconds with 9 queries