Forum Moderators: coopster

Message Too Old, No Replies

newbie style

please help!

         

enerah

6:44 pm on May 1, 2005 (gmt 0)



Hey there, im very new to php and have run into a wall! let me first explain what i have set out to create:
a login system using sessions
a booking page which inserts a logged in users data
a viewing page, where the correct logged in user can view there bookings
a edit page to make ammendments to bookings
and a delete page.
I have managed to create a login system reading up a few tutorials online along with the booking page which inserts the data. What i am having problems with is viewing the data, basically what i want it setup to do is -
1. get the users name from the session,
2. get the data from the db according to what the user name is
The data i want to call is in multiple colums and in multiple rows heres how the db is layed out:
+-------------------------------+
¦Booking table ¦
+-------------------------------+
¦ username ¦ day ¦ month ¦ year ¦
¦ jay ¦ 12 ¦ may ¦ 2005 ¦
¦ kim ¦ 17 ¦ may ¦ 2005 ¦
¦ jay ¦ 13 ¦ may ¦ 2005 ¦
+-------------------------------+

basically what i want to do is depending on which username is logged in i want to show all rows in which the username appears, so from the above if the user jay is logged in it should show the day / month / year as
day ¦ month ¦ year
12 may 2005
13 may 2005

and not show the row in which kim appears.
Can somebody please help me! i really have hit a wall and would truly appricieate a hand thank you.

gmbogie

8:30 pm on May 1, 2005 (gmt 0)



Query the DB with something like this:

Note this is a generalization not specific code

Select * where username like jay

Stormfx

9:07 pm on May 1, 2005 (gmt 0)

10+ Year Member



if (!$cid = mysql_connect($host,$user,$pass)) {
die('Cannot connect.');
}
mysql_select_db($db,$cid);

if (!$qid = mysql_query("SELECT day,month,year FROM booktable WHERE username = 'jay'",$cid)) {
die('Invalid query.');
}

while ($row = mysql_fetch_assoc($qid)) {
echo $row['month'].'/'.$row['day'].'/'.$row['year']."\n<br />",
}

Something like that ... ;p

mcibor

9:57 pm on May 1, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



For starter I would show the mysql error as well:

<?php
$conn = mysql_connect("dbhost", "dbuser", "dbpass") or die(mysql_error());
mysql_select_db("dbname", $conn) or die(mysql_error());

$name = "jay";
$query = "SELECT day, month, year FROM booktable WHERE username = '$name'";
$ask = mysql_query($query, $con) or die(mysql_error());

while ($row = mysql_fetch_assoc($ask)) //or $row = mysql_fetch_array($ask)
{
echo $row['month'].'/'.$row['day'].'/'.$row['year']."\n<br />",
}
?>

Best luck!
Michal Cibor

PS. Why don't you use the mysql date format? CREATE TABLE test (to_day DATE); date is in this format YYYY-mm-dd eg 2005-05-01 in php to create such today just $to_day = date("Y-m-d");