I am working on a small social network with PHP and MySQL I want the users to have the possibility to upvote a post, and I already did this but the problem is that I want the user to be able to upvote only one time. Here is my PHP code: This is the form of the upvote button :
Tag: mysql
Count occurrences of distinct values
I am trying to find a MySQL query that will display the number of occurrences of an ID value within a year. Table: Expected output: I’m trying with the something along the lines of following sql query, but it gives me nothing like the expected output. It’s the 3rd column im struggling with. How can i create that 3rd column?
How to unify three different queries in mysql when exists multiple criteria?
I have a table and I need to get the number of rows using different criteria. Currently I use 3 queries one after another: SELECT COUNT(status) FROM projects WHERE project=’1′ SELECT COUNT(status) FROM projects WHERE project=’1′ AND status>’10’ SELECT COUNT(status) FROM projects WHERE project=’1′ AND status>’20’ How do I merge these queries into a single query? P.S. There are 30
how to show decimals in sql instead of 0
I am trying to get the percent and it just shows up as zero. I want to show two decimal places such as 0.65 Here is a piece of the query I am selecting: if I use this it shows up as 0 and gets rid of the rest Answer Meanwhile, I question whether COUNT(numbers) is what you want. That
MySQL order by field in Eloquent
When I want to define a custom sort order in a MySQL query I can do something like this: ORDER BY FIELD(language,’USD’,’EUR’,’JPN’) What would be the Eloquent ORM version of that? UPDATE: This is …
Create MySQL Tables with Ansible
I’m using ansible to manage a small mail server using ubuntu. I wanted to use ansible to create a database which I can do and also create users for the database(s) which I can do also. But I’m not …
Get all matching records where IDs are joined to a comma separated list
I have two database table like below: Form Id Name Fields(varchar-255) FormFields Id Name InputType Sample data for Form Sample data for FormFields Now I write query as below: And I get only one record as below: But I want all the records of FormFields table whose Id is present in the Fields columns of Form table. I want result
MySQL Query join last comment to topic
I have a topic and topic_comments table. I want to join them both. The join is on topic.id = topic_comments.parent_id. I want to show the topic with latest comment and order by latest comment createdate. And not show duplicate topics. Can anyone help me? So far I have this: This however doesn ‘t show topics without comments. It only returns
MYSQL: UNION results between two tables where omitting records from first table if PK found in second table
I have two tables products and product_edits which hold product information on the pricelist. My app works in a way that if user changes any product info in products table it inserts it into …
Query to check if a certain row has 2 words
How to return rows where a column has 2 words (that is, strings separated by a space) in it? It must be purely using SQL. Answer I dont know the names when querying. Its a big dataset. I only have to check if the name contains a spacebar basically (from a comment). If you want to distinguish names that have