How to get the right data from MySQl? [closed] - php

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 9 years ago.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Improve this question
I have a login-page which allows users to log-in after registeration.
I have also a form that allows the loged-in users to sunbmit a advertisment.
I get the submitted data in my database.
My databse has 2 tabels.
First one (users) is for users to register and the second one (adver) is for the advertisement data.
In my 'adver' table I have a column which gets the first_name of the user, after submitting the form.
My question is how to display the user information next to the submitted advirtesment by that same user!?

Use mysql Join query.
First of all, assign a unique id to every user (which is an obvious thing), if the registered user submits the advertisement then use his registered unique id in the advertisement table.
See the explanation below:
To implement this, you can refer this link

If you have a userId present in both the table you can try with:
Select
*
from
users u
inner join advertisements a on (u.userId = a.userId)

Select
*
from
users u
inner join advertisements a on (u.first_name = a.first_name)

Related

Using SQL table join to use a value from one table as a reference to a value in another (primary key) [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 8 years ago.
Improve this question
I have two tables stored on phpmyadmin, 'gigs' and 'bands'.
gigs: "gigID, gigBand, gigDate"
bands: "bandID, bandName, bandGenre...."
gigBand is a integer which corresponds to the bandID. I am aiming to diplay all the available gigs, but show the actual band name rather than the number. I have read table joins are the easiest way of doing this, and I have no trouble displaying the data of 'gigs' on the webpage.
But managing to display the name rather than the value is proving very difficult.
Any advice, or even an example of the code would be greatly appreciated.
You need to use a MySQL JOIN to pull the records of two related tables.
http://dev.mysql.com/doc/refman/5.7/en/join.html
SELECT * from gigs
INNER JOIN bands ON gigBand = bandID
This is pretty basic stuff though, so I would strongly recommend taking the time to do a bit more research. This seems like a good place to start:
http://www.tutorialspoint.com/mysql/index.htm

How should I implement a "like" counter to my site? (not facebook) [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
In my website users can post submissions, and I want other users to be able to do what would be my equivalent of facebook's "likes".
But I don't know how to implement this. My main problem is that I need to prevent uses from liking the same thing more than once.
I was planning to add a long string into the database entry of each submission, for example "userid:rating/userid:rating/userid:rating". But I think that would be highly inefficient, because I would need to parse the string every time someone presses a button, and if there's lots of ratings then it would have to do a lot of work I think.
Should I make a separate table for ratings globally, and use the submission ID to link them to the right thing, or what? I feel it would be very inefficient to make mysql dig through the whole database and look for all individual rating entries that have a matching ID every time someone opens a submission page...
You create another table: submission_rating. Three columns would suffice: rating, submission_id and user_id.
Someone presses like, you do an an INSERT. But, before you do the insert, you check whether or not this particular user has already liked this submission. If the user has, you remove the like. If it does not, you insert the rating.
edit: As two gentleman below suggested, rather than relying on another check, go for the UNIQUE index. Make sure you catch the error and properly show it when trying to insert. Boldly said, if(!$insert) {}.

PHP registration allow admin to create accounts [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am developing an application where it will be necessary that during registration the user who registers becomes the "admin" for their group and then has the ability to create sub users who they can manage.
I plan on creating a table with the following fields: unique id; username; password; role and group.
I am uncertain best method to enable that the original account is auto tagged as the admin and has the ability to both create groups and have the sub groups tied to it.
The original question got tagged as not being right for the forum -- but I am not looking for how to code and more so best process.
You could add a boolean field "group_admin" in the table where these users are stored to control if the user can or cannot create other users. If group_admin equals true (or 1) he is able to manage the group. Did that help you?

Feedback form with rating system [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I want to create a Feedback form for my website with rating system, which will then display the monthly average rating to a separate page as a graph.
I do have a little concept. But It's lacking something. I know how to create a feedback form. But I am confused on how to save it in Mysql. I mean do I need to calculate the average rating before saving it to mysql or when calling from the graphs page.
Please help me with concept or example.
Thanks.
You will have a form, where the user will put all the rating and the info.
When the user press the "Send" button you will execute a PHP code, this script will take the value of the form, and insert them inside a database, with the current year / month.
When you will go on the page that will show the rating you will execute a php code that will take all the rating in the current year/month from the database , sum them, and do the average calculation. Then you will show the value.

How do I allow users to add additional data to a mySQL users database table after they have already joined? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
I am fairly new to PHP but am in the process of hacking together a web app focused around gardening. I followed a tutorial and built a registration and login system. I want the user in the app to be able to input additional data at a later date including fields like Postcode/Zip code and the ability for them to select 'Plants' to add to their account. I know how I create the form but I want to know how to add this data to the database so that it corresponds with their account details such as username which are already in the database.
Hopefully you have a column in the users table called 'id' or something similar which auto increments and is unique, this gives you a point of reference for each user.
When the user logs in, using his username and password, you can retrieve this id, and then use it throughout your app when working with the table or other tables that are related (using the id).
So if you were to add/update information in the table you'd use the user's id eg:
UPDATE users SET postcode = 'sg12988' WHERE id = '8374'
You can read more about SQL commands here or here .

Categories