Jump to content

Looking for help for my problem in PHP


Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.