database display

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
User avatar
elecktricity
Forum Contributor
Posts: 128
Joined: Sun Sep 25, 2005 8:57 pm
Location: Trapped in my own little world.
Contact:

database display

Post by elecktricity »

Hello im trying to display some data from a database, I have tried using google but didnt get much, and also tried:

Code: Select all

echo '$table[$row][$column]';
that didnt work well, how would I get this to work?

EDIT: I forgot to menchion I was using this code to connect to the database

Code: Select all

$dbh=mysql_connect ("localhost", "root", "password") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("databasename");
replacing the values 'root', 'password', 'databasename' with the actual information
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post by Charles256 »

you need to do a select statemen to get the row. SELECT * FROM TABLE WHERE COLUMN=VALUE and then perform your mysql query and whatever variable you store that query in should have access to the column name. i.e.

Code: Select all

$var=mysql_query(above mentioned query);
$blah=mysql_fetch_object($var);
echo $blah->column;
and that's very very loose example, I'm just trying to give you an example:-D
Last edited by Charles256 on Sun Oct 02, 2005 9:01 pm, edited 1 time in total.
User avatar
elecktricity
Forum Contributor
Posts: 128
Joined: Sun Sep 25, 2005 8:57 pm
Location: Trapped in my own little world.
Contact:

Post by elecktricity »

thanks for that I will play around with it for a bit. Were would I read more about this? anything would be great, thanks
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post by Charles256 »

User avatar
elecktricity
Forum Contributor
Posts: 128
Joined: Sun Sep 25, 2005 8:57 pm
Location: Trapped in my own little world.
Contact:

Post by elecktricity »

thanks for the links, greatly appreciated

EDIT: also do you know how I could get it to display only the newest 5?
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post by Charles256 »

newest 5 what? generally speaking you could sort the table by ascending date and then select everything from the table but LIMIT 5 which limits your results to 5 effectively giving you the 5 newest fields. definitely got to use a while loop to display the data though and you also might need to put hte year first, hten month, hten day, so it sorts properly.... all that is generally speaking of course:)
User avatar
elecktricity
Forum Contributor
Posts: 128
Joined: Sun Sep 25, 2005 8:57 pm
Location: Trapped in my own little world.
Contact:

Post by elecktricity »

allright thanks for that ill go do some googling... this has really helped thanks
mickd
Forum Contributor
Posts: 397
Joined: Tue Jun 21, 2005 9:05 am
Location: Australia

Post by mickd »

after you use the select query wouldnt you need to use one of these to the be able to display it?

Code: Select all

$row = mysql_fetch_assoc($result);
echo $row['fieldname'];

$row = mysql_fetch_array($result);
echo $row[0];

$row = mysql_fetch_object($result);
echo $row->fieldname;
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post by Charles256 »

lol.damn good point.note to self..no posting while drinking :-D
previous post edited to reflect my huge oversight;)
Post Reply