displaying data from a MySQL table

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
shadow_blade47
Forum Newbie
Posts: 12
Joined: Fri Nov 07, 2003 3:41 am

displaying data from a MySQL table

Post by shadow_blade47 »

hi there,

I'm quite new to php/MySQl and I was wondering if anyone could help me out. I've basically got a MySQL database with a table called 'Ultra'. In this table i have three fields; 'webspace, database and email' Each of these fields is eaither going to contain a number (from 1 up to about 500000, or is going to say Unlimited) I have two questions, what properties should I set for the fields? should they be set as text or as varchars, what length and null or not null? My second question is i would like to be able to display in plain text on my webpage the data contained in one of the cells. For example I would like to be able to display the data contained in the webspace column as 'unlimited' or as say '100'. Could somebody please write me a small, simle script that I could use for this purpose. i should be able to edit it myself, I just need something that will work for now. My database is at localhost, user = root and has no password. Thank you for any help in advance,
-james moore
User avatar
Lord Sauron
Forum Commoner
Posts: 85
Joined: Tue Apr 20, 2004 5:53 am
Location: Tilburg, NL

Post by Lord Sauron »

Just read some tutorials, practise a little and when you still encounter problems, you can always come back with specific questions. If you want someone to write your scripts, then were is the fun in programming it yourself?
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Post by Joe »

You should set the fields to text. As for the code try something like:

Code: Select all

<?php
$link = mysql_connect("localost","root","");
mysql_select_db(dbname) or die(mysql_error());
$query = "SELECT * FROM Ultra";
$result = mysql_query($query) or die(mysql_error());

while (true)
{
 $row = mysql_fetch_assoc($result);
 if ($row == false) break;
 $email = $row['email'];
 
 print($email);
}
mysql_close($link);
?>
That will display all of the emails in the table ultra. You should seriously consider buying a book or at least reading some tutorials.
Draco_03
Forum Regular
Posts: 577
Joined: Fri Aug 15, 2003 12:25 pm
Location: Montreal, Canada

Post by Draco_03 »

Try out the tutorial I made..
They'r in my signature
Post Reply