Page 1 of 1
database display
Posted: Sun Oct 02, 2005 7:22 pm
by elecktricity
Hello im trying to display some data from a database, I have tried using google but didnt get much, and also tried:
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
Posted: Sun Oct 02, 2005 7:37 pm
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
Posted: Sun Oct 02, 2005 7:40 pm
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
Posted: Sun Oct 02, 2005 7:45 pm
by Charles256
Posted: Sun Oct 02, 2005 8:44 pm
by elecktricity
thanks for the links, greatly appreciated
EDIT: also do you know how I could get it to display only the newest 5?
Posted: Sun Oct 02, 2005 8:50 pm
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:)
Posted: Sun Oct 02, 2005 8:57 pm
by elecktricity
allright thanks for that ill go do some googling... this has really helped thanks
Posted: Sun Oct 02, 2005 8:58 pm
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;
Posted: Sun Oct 02, 2005 9:00 pm
by Charles256
lol.damn good point.note to self..no posting while drinking

previous post edited to reflect my huge oversight;)