nlvraghavendra Posted March 8, 2009 Share Posted March 8, 2009 Hi, I'm NLV. I'm doing a project using PHP and MYSql to create groups and add members to the groups. I've got stuck with a problem. After a user signs in, in his groups page i need to fetch all the groups in which he is present and display it as a link where if it is clicked it takes us to that specific group's home page. But i'm not able to think a logic as how to the pass the group name which is specifically clicked since there will be many groups. I came to know that it can be done using radio buttons and java script. But is there a way to do it with PHP alone? Looking for help! Regards NLV Quote Link to comment https://forums.phpfreaks.com/topic/148467-looking-for-help-for-my-problem-in-php/ Share on other sites More sharing options...
Mchl Posted March 8, 2009 Share Posted March 8, 2009 Pass the variable through url? <a href="groups.php?groupid=1">PHP Freaks!</a> Quote Link to comment https://forums.phpfreaks.com/topic/148467-looking-for-help-for-my-problem-in-php/#findComment-779598 Share on other sites More sharing options...
nlvraghavendra Posted March 8, 2009 Author Share Posted March 8, 2009 Thanks for your reply... I'm not specific as it should be a url..whatever it may be..the structure of my groups table is mysql> desc groups; +--------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +--------+-------------+------+-----+---------+-------+ | gname | varchar(40) | YES | | NULL | | | uname | varchar(30) | YES | | NULL | | | status | varchar(20) | YES | | NULL | | +--------+-------------+------+-----+---------+-------+ gname - Group name uname - username status - membership status..like owner, moderator etc.. If i use groupid, then how to match the groupid with the group name? Since the list of groups changes from users to users how to manage it?? Can you explain a bit?? Thanks.. Regards NLV Quote Link to comment https://forums.phpfreaks.com/topic/148467-looking-for-help-for-my-problem-in-php/#findComment-779605 Share on other sites More sharing options...
Mchl Posted March 8, 2009 Share Posted March 8, 2009 You should create a many-to-many relation between users and groups using extra table. table users --------- ID, name, login, password table groups ---------- ID, name table users_to_groups ------------ userID, groupID, status Quote Link to comment https://forums.phpfreaks.com/topic/148467-looking-for-help-for-my-problem-in-php/#findComment-779608 Share on other sites More sharing options...
nlvraghavendra Posted March 8, 2009 Author Share Posted March 8, 2009 i'm very very sorry as i'm not able to get you completely. How to get that group id in that destination php page? Instead of sending that group id why cant i send the group name itself directly? Can you explain me that solution once again. I just want to display the groups. If it is clicked it should show the corresponding group's home page. This is my requirement. Thanks Regards NLV Quote Link to comment https://forums.phpfreaks.com/topic/148467-looking-for-help-for-my-problem-in-php/#findComment-779610 Share on other sites More sharing options...
Mchl Posted March 8, 2009 Share Posted March 8, 2009 I'm suggesting, that you should rethink your database design. As it is now, it causes unnecessary confusion. Once you have a many to many relation between users and groups you can 1. Select groupnames and groupIDs for given user 2. Create a list of linksm that use groupname as description and groupID as destination 3. When the link is clicked display all information about given group. Quote Link to comment https://forums.phpfreaks.com/topic/148467-looking-for-help-for-my-problem-in-php/#findComment-779614 Share on other sites More sharing options...
nlvraghavendra Posted March 8, 2009 Author Share Posted March 8, 2009 Thanks Mchl. Finally got the idea. Sorry for being slow in understanding the idea. I've only one doubt. For example if you have a link like http://localhost/group.php?groupid=21 and if it is clicked, how to get that groupid in that php page? Regards NLV Quote Link to comment https://forums.phpfreaks.com/topic/148467-looking-for-help-for-my-problem-in-php/#findComment-779622 Share on other sites More sharing options...
Mchl Posted March 8, 2009 Share Posted March 8, 2009 <?php $groupID = $_GET['groupid']; echo $groupID; Quote Link to comment https://forums.phpfreaks.com/topic/148467-looking-for-help-for-my-problem-in-php/#findComment-779625 Share on other sites More sharing options...
nlvraghavendra Posted March 8, 2009 Author Share Posted March 8, 2009 Thank you very much for your help!!! Regards NLV Quote Link to comment https://forums.phpfreaks.com/topic/148467-looking-for-help-for-my-problem-in-php/#findComment-779630 Share on other sites More sharing options...
nlvraghavendra Posted March 10, 2009 Author Share Posted March 10, 2009 hello!! I've stuck with another problem. I've downloaded a template for my project and used the basic strucutre of the template for all my pages. I've renamed the html file as php file and i've inserted my php code inbetween to do my functionalities. I've pages like login.php, home.php, groups.php, search.php, logout.php etc. I've set $_SESSION["uname"] to the username who is logging in at the time of login. I've written the following code in the logout.php : <?php session_start(); unset($_SESSION['uname']); session_unset(); session_destroy(); include 'login.htm'; ?> and it is working perfectly. But if i directly go to the page http://localhost/home.php i should check whether the user is logged in or not and should do the corresponding actions. I've found that i've to do the following if(!isset($_SESSION['uname'])) { //show login page } else { //show home page } But the design of the template is completely in html tags . If i give <?php session_start(); if(!isset($_SESSION['uname'])) { //error log in first } else { echo " // here i've given the entire tags of the design of that template " } ?> I'm getting parse error and it is showing in the last line. I'm confused..wont that code work? Looking for help.. Thanks Regards NLV Quote Link to comment https://forums.phpfreaks.com/topic/148467-looking-for-help-for-my-problem-in-php/#findComment-781161 Share on other sites More sharing options...
dpacmittal Posted March 10, 2009 Share Posted March 10, 2009 Try this: <?php session_start(); if(!isset($_SESSION['uname'])) { //error log in first } else { ?> All your tags here <? } ?> Quote Link to comment https://forums.phpfreaks.com/topic/148467-looking-for-help-for-my-problem-in-php/#findComment-781529 Share on other sites More sharing options...
nlvraghavendra Posted March 11, 2009 Author Share Posted March 11, 2009 Try this: <?php session_start(); if(!isset($_SESSION['uname'])) { //error log in first } else { ?> All your tags here <? } ?> Perfectly working!!! Thanks a ton!!! Quote Link to comment https://forums.phpfreaks.com/topic/148467-looking-for-help-for-my-problem-in-php/#findComment-782161 Share on other sites More sharing options...
nlvraghavendra Posted March 11, 2009 Author Share Posted March 11, 2009 Meeting another problem..(hope you wont get irritated ) in one a library management project, i'm using a block operation. In this a user can sign in and search for a book and block it if it is available. The block should be valid for 12 hours. Within 12 hours the user has to borrow the book. Or else the block in that book has to be released. When the user blocks that i insert that user's name, book ISBN and that instance of time when the book is blocked. The problem is that i've to delete that record from that block table in order to release the block. So how to automatically execute a query to delete that record after 12 hours? Looking for help! Regards NLV Quote Link to comment https://forums.phpfreaks.com/topic/148467-looking-for-help-for-my-problem-in-php/#findComment-782172 Share on other sites More sharing options...
dpacmittal Posted March 12, 2009 Share Posted March 12, 2009 I assume you are using database for the purpose. You could use AJAX to call a php script which would check if the blocked books timestamp is more than 12hours ago, if yes, it would delete the record else it wouldn't. I hope you got the point. Quote Link to comment https://forums.phpfreaks.com/topic/148467-looking-for-help-for-my-problem-in-php/#findComment-782674 Share on other sites More sharing options...
nlvraghavendra Posted March 12, 2009 Author Share Posted March 12, 2009 i'm a newbie in Ajax and i've zero knowledge about it. Can you give me a point as where to start from? Regards NLV Quote Link to comment https://forums.phpfreaks.com/topic/148467-looking-for-help-for-my-problem-in-php/#findComment-782853 Share on other sites More sharing options...
dpacmittal Posted March 13, 2009 Share Posted March 13, 2009 http://www.w3schools.com/ajax/default.asp http://www.xul.fr/en-xml-ajax.html (this is an excellent tutorial.) Try searching for some ebooks for ajax. Google ajax tutorials, you will find tons of results. Quote Link to comment https://forums.phpfreaks.com/topic/148467-looking-for-help-for-my-problem-in-php/#findComment-783666 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.