Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP How-To
|
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 15th, 2006, 07:04 AM
Authorized User
 
Join Date: Aug 2005
Posts: 68
Thanks: 0
Thanked 0 Times in 0 Posts
Default generate arrays from database

How can I generate a array from database?

I have a table in a database, column call l_parameter where I have information that should go into a array.
How do I add all rows that the table contains into a array.

array example:
$language_codes = array('en','sv','fi');

 
Old September 23rd, 2006, 04:42 PM
Registered User
 
Join Date: Apr 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

// Connect to database
$dbhost = "localhost";
$dbuser = "username";
$dbpass = "password";
$dbname = "databasename";
$db = mysql_connect($dbhost, $dbuser, $dbpass);
mysql_select_db($dbname,$db);

/*
select all rows from the language table and place
the table attribute lang_abbreviation into array $langAbbreviation
*/

$sql1 = "SELECT * from language ";
$result1 = mysql_query($sql1, $db);
$langCount = mysql_num_rows($result1);
for ($i=0; $i < $langCount; $i++) {
    $row = mysql_fetch_array($result1);
    $langAbbreviation[$i] = $row["lang_abbreviation"];
}

// show the array on your page
for ($i=0; $i < $langCount; $i++) {
    echo $langAbbreviation[$i] ;
}

:)






Similar Threads
Thread Thread Starter Forum Replies Last Post
Collect database space used and generate a report lixiay99 SQL Server 2000 2 May 9th, 2006 06:14 PM
How to Auto Generate ID (Primary Key) SQL Database havering SQL Server ASP 1 December 9th, 2004 05:33 AM
How to Auto Generate ID (Primary Key) SQL database havering SQL Server 2000 9 December 1st, 2004 10:38 AM
Arrays in Database fields JeffMM Classic ASP Databases 2 March 26th, 2004 07:27 PM





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