PDA

View Full Version : help with dynamic table displaying logged in users listings


nanny
05-04-2006, 06:09 AM
Hi I need to find a way to show the listings a logged in user has placed. I can get their registration details to show but not their listings. Would it be a mysql or php problem? I have used a session variable in the page to display the logged in users registration details but it doesn't work for displaying the logged in users listings.

Really having trouble with this one.

davidj
05-04-2006, 07:51 AM
you have a seperate table displaying listings?

and you should have a user reference in the listings table so you can identify them?

nanny
05-04-2006, 11:06 PM
Hi yes I do I have the users id referenced in the listings table. I have used that in the recordset but I don't get a connection between the two. Would it be a problem with the insert record that the user uses for the listing? That id is in a hidden field.
I need to work out a connection between the two tables within the recordset to show a dynamic table of the logged in users listings.
Thanks for your time.

davidj
05-05-2006, 07:28 AM
why not just have one recordset but do a join between the 2 tables

post your SQL from your first recorset

nanny
05-05-2006, 07:44 AM
SELECT class_ad.classid, class_ad.class_category, class_ad.categorytype, class_ad.classbusinessname, class_ad.stateCode, class_ad.regid
FROM class_ad
WHERE class_ad.classid = 'varClassid'
varClassid = $_SESSION['MM_Username']

nanny
05-05-2006, 07:47 AM
Sorry david the class_ad.regid is a foreign key from the table regid.
I did try to inner join regid on class_ad.regid = regid.regid
but that didn't work either so I was trying for the session variable to work through to connect the tables.
Thanks

davidj
05-05-2006, 08:51 AM
try a left join

nanny
05-05-2006, 10:57 AM
Thanks I will in the morning.
Cheers

nanny
05-06-2006, 07:48 AM
Hi I tried the left join and it shows all listings but not by the logged in user only.
I still can't show a connection for only the logged in user's displayed.
Do you think it would be better to have the user to search for their listings rather than trying to have a dynamic table display from the recordset?
This is very frustrating and I appreciate your input.

davidj
05-06-2006, 09:15 AM
when a user logs in a session should be set with his login ID

why not use that in your WHERE clause

select * from table left join ... WHERE userID = '%s', $_SESSION[MM_userID];

nanny
05-31-2006, 01:01 AM
Hi any suggestions on how to change the Insert Record to indentify a userid as a foreign key from another table or do I just put a LEFT JOIN in amongst the %s (understanding that is the string)
e.g.
$insertSQL = sprintf("INSERT INTO CV (CVid, Userid, Category, Title, Code) VALUES (%s, %s, %s, %s, %s) LEFT JOIN User ON CV.Userid = User.Userid ",

or do I try to include some variables somewhere to make the insert record identify the connection between the two tables.
I have never done that before and would like to learn.
Hope you can help.
Thanks.