Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > MySQL
MySQL General discussion about the MySQL database.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the MySQL section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old February 13th, 2006, 09:47 AM
Registered User
Join Date: Feb 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Mysql,PHP and arrays

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) )

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..?

Old February 15th, 2006, 07:55 AM
Friend of Wrox
Join Date: Mar 2004
Posts: 357
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to anshul

You're doing too much wrong ..:D:D
$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:

mediasworks.com project

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP array_push() for associative arrays mcmahonc Beginning PHP 1 January 9th, 2010 01:13 PM
HOW TO USE STRINGS,ARRAYS AND VARIABLES IN PHP jhan316 Beginning PHP 1 July 25th, 2006 07:17 PM
sendAndLoad Arrays to MySQL harpua Flash (all versions) 1 May 11th, 2006 07:40 PM
php compare 2 arrays lucian PHP How-To 0 February 23rd, 2006 12:53 PM
Converting mysql arrays to strings robertjshillito Beginning PHP 3 February 25th, 2005 04:11 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.