I am using PHP to access a PostgreSQL database for an online banking application. I am having some problems with arrays.
//assume database connectivity
$sql = "some SQL statement"
$result = pg_query ($dbconn, $sql);
$data = pg_fetch_row ($result);
$ans = Array ();
//in this while loop I want to put the rows that satisfied a condition into the array $ans
while ($data != false) {
if cond {
$ans[] = $data;
$data = pg_fetch_row ($result);
}
}
I am really not familiar with the array syntax and could not find any relevant examples. Can someone tell me how to store an array $data into another array $ans and later to retrieve the values? Further, is there a way to create the array $ans = Array () with a give array size like $size?
Thank you so much!!!
Store an array in an array? PostgreSQL and PHP
Moderator: General Moderators
-
catherine878
- Forum Newbie
- Posts: 6
- Joined: Wed Jun 26, 2002 7:04 pm
your code should be working. A slightly shorter versionis there no way of putting the condition in the sql-statement?
you can iterate the array i.e. with foreach
Code: Select all
//assume database connectivity
$sql = "some SQL statement"
$result = pg_query ($dbconn, $sql);
$ans = Array ();
//in this while loop I want to put the rows that satisfied a condition into the array $ans
while ($data=pg_fetch_row ($result); )
{
if (cond)
$ansї] = $data;
}you can iterate the array i.e. with foreach