PDA

View Full Version : SQL PHP help



b.rich
August 10th, 2003, 06:56 PM
ok im trying to get this down but i keep running into problems... first off i have a table named tc_pat in which i want to display only the items from todays date. So if you were to log in you would only see the items for the current day:

here is what i got:


$appoint = "SELECT * FROM tc_pat WHERE date = '$today'";

this is what i am using to try and display:

<p>&lt;? ehco &quot;$appoint&quot; ?&gt;</p>

am i way off ???


i am new to this so any help is appriciated.

Jubba
August 10th, 2003, 09:57 PM
are you way off.... yes. I don't know how much you know about database and using PHP to access the data stored in a database, so I guess I will start at the beginning...



<?

$linkID = mysql_connect("HOSTNAME", "USERNAME", "PASSWORD"); //connect to the DB

mysql_select_db("DATABASENAME"); //select which database

$query = "SELECT * FROM tc_pat WHERE date='$today'"; //tell the code what to get from the database

$resultID = mysql_query($query, $linkID); //issue the query

if($resultID)
{
for($x=0;$x<mysql_num_rows($resultID);$x++)
{
$row = mysql_fetch_assoc($resultID);
print $row['fieldname'];
}
}
else
{
print mysql_error($linkID);
}

mysql_close($linkID);

?>

I can't really exlpain much of it because most of it is pretty much self explanitory. Check the manual at www.php.net for specific information on what each command does... and check out this book:

http://www.amazon.com/exec/obidos/tg/detail/-/0764535617/qid=1053751242/sr=8-1/ref=sr_8_1/002-2551283-1162431?v=glance&s=books&n=507846


sorry this can't be more comprehensive... i gotta get going...

b.rich
August 10th, 2003, 10:19 PM
thanks man i knew how to connect i just wasnt sure about getting the info but i definatly got the information i was looking for thanks alot.:)