Save and Display status updates like Twitter and Facebook? [closed] - php

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
Just a quick question, how can I set up my MySQL database for status updates?
So I already have a column horizontally for each user and a column vertically for each information stored such as their "email" and "username" and such like that. Now how do I set up a thing to make people post status updates and then store each one they post but only display the latest one they post via PHP onto their page? I mean do I make a vertical column for all users that say "statuses" or what?

write sql query like this to get the latest status update.
select * from table_name where user = your_user desc limit 1

You should create a new table in your database for statuses and create a filed (in this table) that refers to the ID of the author. This is the "common way" of doing it.
And then ordering the query results is just a matter of ORDER BY status_time DESC.

Related

display result from 2 table [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I am working for small project, the main idea of the project to display
some tours:
DB - Database consist of 2 table like below
The first table consist of 4 raw:
id , tour_id , tour_name, image
and the second table for each tour details like destination and places
and raw is:
id , tour_id , from , to
The main page is done, I can display information of tour with images and url link to details page like www.domain.com/tours/get_tour?=1
where 1 is the tour_id.
My question is how can I show the information from the second table with respect tour_id?
I am working in PHP and HTML and MYSQL.
You need JOIN function of mysql. The use this type of SQL script with PHP:
$sql="SELECT first.tour_id, first.tour_image, second.tour_id
FROM first
JOIN second ON first.tour_id=second.tour_id;";
$results=$conn-->$sql; //with $conn your connection variable
$get_tour = $result->fetch_assoc();
In this way you can get first.tour_name and second.from/to depending on tour_id
Then run a while to export your datas in PHP.
$get_tour is now populated. To call elements, use
$get_tour['first.tour_id'];
$get_tour['second.from'];
...
Let me know if it works!

How can I Select duplicate results, insert the results to a new table and delete them from the original table? (phpmyadmin) [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have 2 tables, both with the same column names that look like this
I have an app that is used for clocking in/out. A user goes up to a tablet and selects there name, the data is then inputted into table 'clocktable' as shown above.
What I need to happen is when a user presses their name for a second time (to clock out) it detects that there is already a value in the table with the same employeename value, and moves both clocks to a different table 'oldclocks' so that a record is kept of clocking in/out times. The reason it needs to be in a separate table is I have a web page that displays the 'clocktable' table so we can determine who is in the building.
How can I go about doing this?
I can execute
SELECT DISTINCT EmployeeName, time FROM clocktable ORDER BY EmployeeName
from within myphp and then execute
INSERT INTO oldclocks SELECT Employeename, Department, time FROM clocktable;
Afterwards, but I cannot seem to execute them both at the same time in order to get them into a php script. Also is there a way I can delete the select results from the 'clocktable' at the same time?
Help with this would be greatly appreciated.
You can add an indicator, where 1 is in and 0 is out & if you want to save the logs, then creat another table to INSERT a record whenever the indicator's value change.
1- add 2 new attributes in table A, lets say userid & in_out for an example.
2- in_out = 1/0 where 1 is in and 0 is out
3- creat table B and insert userid & time every time the in_out value change.
And that's how you know if the user in the building or out, also you will keep logs of every move
2 tables are not nessesary. And it is bad idea.
Why dont you simply add boolean IN_BUILDING which will have 0 ->Not in building and 1->In building. Then you can do:
SELECT EmployeeName FROM clocktable WHERE IN_BUILDING = 0; which will show you all employees who are not in building
or
SELECT EmployeeName FROM clocktable WHERE IN_BUILDING = 1; which will show you all employees who are in building that moment.
Its easier also because you can change it value easy on click.

Counting large amounts of data [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
My site has a social feature. On the user profile it shows how many posts the user has, how many followers and so on.
However our database has over 100,000 rows.
Its working fine however im getting very sceptical on the performance in the long run.
I was thinking of another method which i think would work best.
So basically right now it just counts the rows which the user owns in the mysql database.
Instead of scanning through the entire mysql table would it be better to do the following:
Create a section in the "Users" table called "post_counts". Every time he makes a post the counter will go up. Everytime the user removes his post it goes down and so forth.
Ive tried both methods however since the DB is still small its hard to tell if there is a performance increase
current method just querys SELECT * WHERE user = user_id FROM table_name; then just count with php count($fetchedRows);
Is there a better way to handle this?
[update]
Basically the feature is like the twitter followers. Im sure Twitter doesnt count billions of rows to determine the users followers count.
I have MySQL tables that have 70M+ rows in them. 100,000 is nothing.
But yes I would keep the counters in a field and simply update them whenever that users posts something or deletes a post. Make sure you have good indexes.
Also what you COUNT() make a differences. A COUNT(*) takes a less overhead than a COUNT(col) WHERE...
Use "explain" to see how long different COUNT() statements take and how many rows they are scanning.
As in: mysql> explain select count(*) from my_table where user_id = 72 \G;

How to implement a next button for a forum in php? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
Currently trying to implement a next button that would take you to the next topic in a forum but I have no idea where to start.
Assuming the forum is constantly updated in terms of the time of the last post.
If they have an autoincrementing primary key in the database, you could get the current ID, bump it and create a link pointing to the next one (provided you do a quick check to make sure its valid, e.g., the next post wasn't deleted previously).
EDIT: If the forums are sorted by last update (and you want the "next" post to mean the next most recently updated, then you'll need to do a little querying.
$sql = "SELECT postID, postName FROM forum_posts WHERE last_updated < '$thisPostsLastUpdate' ORDER BY last_updated DESC LIMIT 1";
$result = mysqli_query( $dbconn , $sql );
$fetch = $result->fetch_array();
$fetch should contain the array of values you want (the ID for generating a link to the next post and postName as the link's text).

MySQL Join Users table to Groups table, find users not in any of selected groups [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
How do I write a query that takes a list of group ids (could be 1, could be 10, etc) and gets the users who are not in ANY of those groups?
We are using Doctrine, but we can't even figure out how to do it in raw SQL.
It's okay to have PHP generate part of the query if we need to do multiple joins/conditions etc based on how many ids are provided.
If my general assumptions about your table structure are correct, I believe something like this should work:
SELECT *
FROM users
WHERE user_id NOT IN (
SELECT DISTINCT user_id
FROM user_groups
WHERE group_id IN ([your group list])
);

Categories