Jump to content

user selects checkbox wich columns to retrieve


Klein_Kipje

Recommended Posts

I do not have code yet, i just want a general idea how to get started.

 

I have a database with +/- 15 columns. 6 people are using this database. Not all columns are relevant for each user.

 

So my idea was that each user will be able to make his preference by checking checkboxes for each column -> store this in the database so that when he logs in , his preference will be retrieved and used to make the right query.

 

second question, how do i make the headers so that they are the same als the preferences from the user ?

 

Just put me on the right track (or if someone has it on the shelf, post the code)

 

thanks in advance

Link to comment
Share on other sites

Post the code? Uh, what code are you going to try and learn and do this complex thing with? PHP? JS? JQ?

 

It's all very doable but if you haven't programmed AT ALL in your life, you have a long road ahead of you. You might want to start with the simple stuff. There's a lot to learn about writing good, working, secure and safe code.

Link to comment
Share on other sites

I have a database with +/- 15 columns. 6 people are using this database. Not all columns are relevant for each user.

 

 

this sounds like a bad database table design.

 

correctly designed database tables have one row for each distinct data item, making it easy to insert, retrieve, update, delete, or associate each data item to related data in other tables.

 

post an example of your data is to get the best help.

Link to comment
Share on other sites

Create a 'preferences' screen where you show a checkbox for each column that people may choose to view.

 

Behind that screen your php script will grab those checks and store them under their id with multiple rows to contain each checkbox value. Ex.:

[id][col_id]
user1  1
user1  2
user1  5
user1  8
user1  9
user1  10
user1  13
Here 'user1' wants to see columns 1,2,5,8,9,10 & 13.

 

In your display script you will look up the preferences for 'user1' and then build a query string using the above choices as well as another table that links col_id to column names of your table. Ex.:

[col_id][col_name][col_label]
1       colname1   Col 1
2       colname2   Col 2
3       colname3   My Column
4       colname4   This Column
...
...
You have the query result of the user's preferences and you can include the above column info with that query (join) and then you loop through the results and build a query string. Ex.

$qry = "";
while($row = $results->fetch())
{
if ($qry=='')
$qry .= "select ".$row['col_name']";
else
$qry .= ",".$row['col_name']";
}
$qry .= "from (tblname) order by xyz where xyz";

 

Hope this makes sense - it is very OTT. (off the top).

Edited by ginerjm
Link to comment
Share on other sites

Regarding the process of using the saved preferences of the user:

 

I'm not knocking ginerjm's approach, but I would do it a little differently. I would not put logic into the query to determine which columns to fetch. If you make any mistake in properly validating the data you may create a potential hole in security. Instead I would have a single process to fetch the data that gets all the potential columns that users may want to see. Parameters I would put in such a process, if needed, would be things such as a sort order and a limit (if the user can define the page size). I would then modify the output when processing those record to determine which fields to include in the output.

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.