Subject: Mysql,PHP and arrays
Posted By: swedge Post Date: 2/13/2006 8:47:40 AM
Hello
I'm trying to retrieve data from a mysql table using a select statement and store the data in an array. I then want to go through the array and assign certain elements of the array to variables. To try and do this, I used the following code

$get_table = mysql_query("SELECT * from $table
            where USER_ID = '5'");
                
$row_50 = array();
while ($row_50 = mysql_fetch_row( $get_table) )
    array_push($ret50,$row_50);


I assumed that the while statement used with the array push command would push each row returned into the $ret50 array.

However, when I use the following to retrieve the first eight elements of the array and display the contents of the $_SESSION variables, they print the word Array to the browser.

$_SESSION['1TG1'] = $ret50[0];
$_SESSION['1WG1'] = $ret50[1];
$_SESSION['1DG1'] = $ret50[2];
$_SESSION['1LG1'] = $ret50[3];
$_SESSION['1SG1'] = $ret50[4];
$_SESSION['1AG1'] = $ret50[5];
$_SESSION['1GD1'] = $ret50[6];
$_SESSION['1PG1'] = $ret50[7];

Any idea's of what I'm doing wrong..?        



Reply By: anshul Reply Date: 2/15/2006 6:55:35 AM
You're doing too much wrong ..
quote:

$rs_id = array();
$query = MySQL SELECT * query;
$result = mysql_query($query);
while( $row = mysql_fetch_array($result) ) {
    $rs_id[] = $row['id'];
    $rs_name[] = $row['id'];
    $rs_email[] = $row['id'];
    .
    .
}


Now use the arrays as you like:
print_r($rs_email);

`~@#\^%&*/\.<.\/-|+|_!:;..=?>
mediasworks.com project

Go to topic 40033

Return to index page 369
Return to index page 368
Return to index page 367
Return to index page 366
Return to index page 365
Return to index page 364
Return to index page 363
Return to index page 362
Return to index page 361
Return to index page 360