some simple tasks

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
jaymoore_299
Forum Contributor
Posts: 128
Joined: Wed May 11, 2005 6:40 pm
Contact:

some simple tasks

Post by jaymoore_299 »

I am completely new to working with mysql databases and php and would appreciate just some pointers on how to do these simple tasks.

Given a database and a table in that database, with the name 'incoming'', fields field1, field2, field3, etc, like the table below, how do I insert a new row of data like row 1 below (what is the exact php code required)

'incoming'
| field1 | field2 | field3 | field4 | field5 |
row 1 a 45 24 11 30
row 2 b 41 11 39 61
row 3 c 11 46 64 26
row 4 d 21 31 29 37

And given the entire set of data, how do I get all the rows and column data and then print out all the data, print out only row 2 data, print out only the data from field 2, etc? Would we first put all the data in a multidimensional array then go from there?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

your certainly are asking for a LOT of these "simple tasks" :roll:


here's a start (you can figure out the others)

Code: Select all

$host = 'your MySQL host name';
$user = 'your MySQL username';
$pass = 'your MySQL password';
$db = 'your MySQL database name';
mysql_connect($host,$user,$pass) or die(mysql_error());
mysql_select_db($db) or die(mysql_error());
the above (or similar) is used with all of the following...
jaymoore_299 wrote:how do I insert a new row of data like row 1

Code: Select all

$result = mysql_query("INSERT INTO `incoming` VALUES ( 'a', '45', '24', '11', '30' )") or die(mysql_error());
jaymoore_299 wrote:how do I get all the rows and column data and then print out all the data

Code: Select all

$result = mysql_query("SELECT * FROM `incoming`") or die(mysql_error());
while($row = mysql_fetch_assoc($result)) print_r($row);
for the rest, read the manual (http://dev.mysql.com/doc/mysql/en/select.html) or read through the many many many posts we have here talking about such things....
Post Reply