Discussion: php mysql question
Afficher un message
Vieux 25/03/2008, 19h11   #1
canajien@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut php mysql question

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?
  Réponse avec citation
 
Page generated in 0,04586 seconds with 9 queries