Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP How-To
| Search | Today's Posts | Mark Forums Read
PHP How-To Post your "How do I do this with PHP?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP How-To 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 September 29th, 2007, 11:24 AM
Registered User
 
Join Date: Sep 2007
Location: , , Mozambique.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Bringing data from MYSQL to two-dimensional array

How would I bring data out of a mysql database table into a two-dimensional array to look like the following?

$nodes = array(array(1,2,120),array(2,1,120),array(2,3,545) ,array(3,2,545));

So that I can use the same array in one function where is manipulated. The database table looks like:

CREATE TABLE `nodes` (
  `NodeFrom` int(7) default NULL,
  `NodeTo` int(7) default NULL,
  `Distance` float default NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;


ssjp
 
Old September 29th, 2007, 02:02 PM
Registered User
 
Join Date: Sep 2007
Location: , , Mozambique.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have found a solution that works just fine. Here it goes:

$sqlQuery = "SELECT * FROM `db`";

$res = mysql_query($sqlQuery);
$rows = mysql_num_rows($res);
for($k=0;$k<$rows;$k++){
$rs=mysql_fetch_array($res);
$points[$k][0]=$rs['NodeFrom'];
$points[$k][1]=$rs['NodeTo'];
$points[$k][2]=$rs['Distance'];
}

ssjp




Similar Threads
Thread Thread Starter Forum Replies Last Post
using 2 dimensional array Abraham EJB 0 July 17th, 2007 09:27 AM
two-dimensional array Lizane Java Basics 4 May 23rd, 2007 09:35 AM
Display of 2 dimensional array numeric data oldrocketdog Visual Basic 2005 Basics 0 December 6th, 2005 10:39 AM
2 dimensional array trangd Beginning PHP 0 August 18th, 2005 12:37 AM
2 dimensional array venterjo General .NET 2 January 23rd, 2005 09:04 AM





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