Re: Storing iterated results into various variables
| From: | Adam Voigt | Date: | Tue, 04 Feb 2003 13:49:45 +0000 |
| Subject: | Re: Storing iterated results into various variables | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-25416@lists.php.net to get a copy of this message | ||
$counter = 1;
$query = mysql_query("SELECT image,caption FROM tablename ORDER BY
id;");
while($row = mysql_fetch_array($query))
{
$imagevar = "image" . $counter;
$captionvar = "caption" . $counter;
$$imagevar = $row[image];
$$captionvar = $row[caption];
$counter++;
}
Change the query to match what you need, and that should work, if
your interested, check out the manual page on "Variable Variables" at:
http://www.php.net/manual/en/language.variables.variable.php
Enjoy.
On Tue, 2003-02-04 at 07:02, Geckodeep wrote:
May be some one could help me here, I am trying to retrieve results
from a
table that gives 9 rows, from each row I am trying to pull out two
fields
and assign the two values of those column fields to a variable
$image1 and
$caption1, and now I want to go to the next row and pick up the
values of
the corresponding fields and store it in the next variable $image2
and
$caption2 and to continue until I reach 9 rows.
The reason for this technique is I am trying to inject the dynamic
data
inside a page which is already formatted with HTMLs (kind of
template) and
by means of Php tags I can echo these variables where needed.
Thanks for your time and help in advance I'd appreciate it.
GD
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
Adam Voigt (adam@cryptocomm.com)
The Cryptocomm Group
My GPG Key: http://64.238.252.49:8080/adam_at_cryptocomm.asc
Attachment: [application/pgp-signature] This is a digitally signed message part signature.asc
Attachment: [application/pgp-signature] This is a digitally signed message part signature.asc