I'm working on one project and having problem with obtaining data from mysql to website and from website to mysql.
It's about getting data from mysql--> rotate data(to pick one value of more)--> show this on website--> count visits and if someone click on some link, track it as +1 to database.
Mysql design for better understanding:
Campaigns Table
-c_id 1 2
-name Campaign 1 Campaign 2
Parameters Table
-p_id 1 2
-name Title Image
-c_id 1 1
Variations Table
-v_id 1 2 3 4
-variation Welcome1 Welcome2 img1.jpg img2.jpg
-p_id 1 1 2 2
-c_id 1 1 1 1
So when php/js file is called it should return 1 variation(Welcome1 or Welcome2 for parameter Title with id 1 and img1.jpg or img2.jpg for parameter Image with id 2) of all parameters(Title, Image).
This data should be added to website with php echo or js document write. (php echo $parameter1; ).
After that there should be onclick on link/s so I can track with which combination user clicked on link. Problem I'm facing here is I don't know how to get and pass which elements was show on website(which variation) and also how to pass.
This will not be placed in same folder and domain as website. Only the server will be same. So I think there won't be problem with accessing database.
I'm not asking for full code of anything just for ideas how to make it the simplest way and also effective.
The database looks a little strangely built, but if that suits you then it should be fine. There are also some other things missing and I am not sure what you are trying to accomplish.
But, when passing the parameters to JS or PHP also pass the ID of the variation, not only the value. When you pass the parameters pass
Title = Welcome1
TitleId = 1
Image = img1.jpg
ImageId = 3
When you create the link that will take you to the other page you should create it passing to it the 2 parameters link?TitleId=1&ImageId=3
In the page that gets process with link count that the visitor got there by pressing on a link with TitleId=1 & ImageId=3
Related
I'm trying to achieve this in Codeigniter. I have got a URL like below
https://www.example.com/5474/my-first-post
I'll be processing this URL using the id and get the blog content from this id. but I don't want to show the ID in the URL.It should be like below.
https://www.example.com/my-first-post
I'm doing this because previously I was getting the blog content using the title. But that makes the website very slow when there are a lot of rows in the database (It takes around 5 seconds roughly on the local server).Where as I tried the same using the ID. I was getting the row from database using the ID. It takes very less time like say 0.0007 seconds. Any solution to this is highly appreciated.
This is too hard to do routes for each url.
add a field in your table..
ID | url | post_title
33 | hello-world | Hello World.
Then use that url text on behalf of id
convert your numeric id using base64_encode()
You can use
uri-routing
Example:
$route['my-first-post'] = 'your_controller/your_function';
I'm trying to show or not show links based on a users access level. The links will be different depending on the section of the site the user might be in. The links also may not all be in one menu. They will more than likely be in various places on the page.
Currently I have a database table that contains Users, Groups and Sections. The main menu is built from the Sections database table. I'm thinking I should create an Actions table and add a link that I'd like to show for each section in the action menu. So, my tables so far are like.
Users
user_id
Groups
group_id
group_title
Sections
section_id
section_title
Table I'm thinking of adding.
Actions
action_id
action_title
action_group_id
action_section_id
The part I'm not sure on is should I add the same link multiple times to the Actions table for each group that is allowed access. Or, just add it once and do a if group id is greater than, then show link.
Example for entering the same link multiple times.
action_id action_title action_group_id action_section_id
1 View all 1 1
2 View all 2 1
3 View all 3 1
I was hoping to not flood the page with a bunch of if/then statements. Plus, this doesn't seem like the best way to handle because it requires human interpretation as to what the access levels stand for.
Any help on this is appreciated. I could be going in the complete wrong direction here?
Create a many to many relationship with an additional table where you insert an entry for each permission the group has access to. Am I correct in assuming section is what you're creating permission to?
Table: Group_Section (Or whatever you'd like to name it)
Group_id | Section_ID
---------+-----------
1 | 1
1 | 2
1 | 3
2 | 1
2 | 3
|
You can see that the Group with ID = 1 can access sections 1,2,3 while Group with ID = 2 can access only 1,3. You can then add whatever permissions to the table you want and manage them through the use of foreign keys.
Does that make sense?
Here is a good article but the things are discussed in general http://en.wikipedia.org/wiki/Access_controlenter link description here
In your case, use what TheCapn wrote and I'll just add, that its 'best to start session for every user and just check his access level when he's trying to reach a restricted part.
Personnaly, to do this kind of thing, i set a user level in the user table and a section level in the section table.
Then you simply have to filter the section according to your user level.
You can do this by adding a statemtn to you sql like
AND section_level >= "user_level";
or then again, get all the section and filter tham with php.
foreach($section as $s){
if ($s->level >= user_level) echo $s->title
}
Of course, you'll need to adjust the <. = and > according to the hierachy of your system.
I personnaly use a lowering hierachy, meaning, the lower the level you are the more right you have. This way you can make a 'banned' user by setting his level to 99 or something.
THis would be only for your menus, make sure you control the user_level on each page as well so if someone get to the page directly it get kicked..
Hope it points your in the right direction. ;)
I have been trying to come up with a way design a webpage to allow users to make selections on a webpage and then query those selections in a database and returned to the user.
For example, my database is a list of houses. The data base table is set up something like this:
Country Region State City House
1 1 1 1 A
1 1 1 1 B
1 1 1 2 C
1 1 1 2 D
1 1 1 3 E
1 2 2 4 G
1 2 3 5 H
1 3 4 6 I
1 4 5 7 J
From the search bar, I want the user to be able to say show me any and all houses in region 2, any houses in state 3, and any houses in city 1.
In this example, the data base query would come back with houses G,H,A, and B. The order of the search and results don't really matter right now.
Is something like this even possible? I have considered using check boxes on the website but ideally I would rather just have one search bar using autocomplete (jquery) where each entry has specific values tied to it. These values are what would be passed to the search query as variables.
you could use comma separator as when you use google maps, then split the content of the search box using the comma delimiter and then you will have the 3 parameters that you need.
Your best bet would be <select> elements in a <form method="GET" action="somefile.php">, and then within the file somefile.php retrieving the $_GET values that the user posted on the form in the <select> elements and then generating SQL queries appropriately to retrieve the data.
The answer is yes, it is possible, but you're asking a lot if you're asking for someone to do it for you.
As #khanahk said, you could use select boxes.
I couldn't figure out how to search for more than just one term at a time.
You could have multiple select boxes, such as four or five on one line, with a submit button to search using the paramters selected by those select boxes.
Or you could do something really cool with a search box that uses keywords to separate the different type of search, ex.) House-a IN region-1
I'd take a look at the following link:
http://www.arroyocode.com/client-side-keyword-search-with-jquery-ui-autocomplete-and-asp-net-mvc-4
This is a followup to a question I posted a few days ago.
basically, I have a site with six links. In order to access the site, users must log in using LDAP authentication. When they do this, I grab some of their account credentials (username, firstname, lastname), and store it in a PHP $_SESSION variable.
That works; the user can log in, and the session data is being stored successfully.
Now, I want to set up a way to track which links have been clicked by what users. Basically just store a time stamp in the database of when they clicked the link. I want to be able to see who has (or has not) clicked each link, and when.
Can I do this in a single table / would that be a bad idea? I was thinking setting up the table like this:
TABLE (each bullet indicative of a column)
auto-incrementing ID
user account name: abc1234
user account first name: John
link 1: Last Accessed 5/2/2012 at 4:15PM
link 2: NULL
link 3: NULL
link 4: Last Accessed 5/1/2012 at 2:20PM
link 5: NULL
link 6: NULL
basically the above would say that "John" had only clicked the first and 4th links. The rest are null because he has never accessed them. If he were to click #1 again, it would overwrite with the more recent date/time.
Can I do this in a single table? or will that create complications? I feel like the thing I will have the hardest time with is checking to see if the user is already in the database before adding the info (ie so that if John logs in a second time, a whole new row isn't created for him)
Thanks for any help!
That would be a bad idea. What if you wanted to have a seventh link? What if the user format would change?
This solution requires 3 tables:
Users - contains user data (And a user ID).
Links - contains link data (And a link ID).
Clicks - many-to-many relationship between users and links.
That third table would look like this:
user_id | link_id | timestamp
-----------------------------
1 | 2 | ...
2 | 2 | ...
1 | 3 | ...
............
why not just have
increment_ID
Account_ID
Link_URL
Timestamp
Then just insert a new record for each click. You also don't need to manage links since you'll store the entire URL path
I'm currently have around 100 rows in a table on my website, which include a URL and few sets of numbers pulled from a database on my server. What I would like to do is to dynamically create pages based on a cell of each row, which would contain data pulled from the same database. For example, each row (displayed in the table) would look like this:
Icon (url) | Name (url) | Number 1 | Number 2 | Number 3 | Number 4 | Number 5
Inside my database however, each row is like this:
Icon (url) | Name (url) | Number 1 | Number 2 | Number 3 | Number 4 | Number 5 | Description (large body of text) | LargeImage (url)
Since I have so many entries, I would like to be able to have some way to generate the pages based on the name of the row in the database (it would take too long to make each page individually, and I will be updating this table frequently with content), so I can display more of the information out of the database row (the description, largeimage etc) that I wouldn't be able to fit into the table.
Are there any plugins for Wordpress that can do this, and if not, how would I go about doing this in PHP?
I'm not sure how to best integrate this into WP, but it's fairly straightforward in PHP. You just have a file like mypage.php?id={#} where the # is the individual record's ID. You pull the ID using GET ($id = $_GET["id"];) and then run an SQL query with it as the WHERE, take the results and populate the page with that row of data. Then, using .htaccess, you can do what WP does and make this look like a URL (ie. mypage/2/).
You can create the custom page by using a method like this for example.
You could integrate this into WP by creating a separate file (other than single.php, for example) that would run this PHP script, but include the WP header and footer to make it fit into the theme. However, this wouldn't really be fully integrated into single.php and therefore wouldn't appear in the posts section in the admin or anything. Is that a requirement?