Arrays

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
davidjwest
Forum Commoner
Posts: 67
Joined: Sat Nov 06, 2004 5:26 am
Location: Leeds, Yorkshire, England

Arrays

Post by davidjwest »

A fairly dumb question I suppose, I have read the Php and MySQL sites but the examples they give don't really make sense to me. So anyone willing to help out by posting some example code, in as simple to follow format as possible? No clever little optimisations etc.

All I want is some code to read data from a database and put it into an array, I'm not sure how arrays work with PHP, Spectrum Basic yes, PHP no!

It's for a racing game I am coding (yes really, not joking here) and it needs to read in each drivers attributes, speed etc, then process them all to work out laptimes.

Does this make sense, if not I can post more details.

Thanks!
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

http://us3.php.net/mysql_fetch_array

this is right off of the manual (that page above):

Code: Select all

<?php
mysql_connect("localhost", "mysql_user", "mysql_password") or
   die("Could not connect: " . mysql_error());
mysql_select_db("mydb");

$result = mysql_query("SELECT id, name FROM mytable");

while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
   printf("ID: %s  Name: %s", $row[0], $row[1]);  
}

mysql_free_result($result);
?>
Post Reply