Selective export from MySQL database - php

I've got a database called Members, people would register online entering their fullname, email address, phone number, etc. I made a hidden form where it would set random 4 digit unique number and register it with their data, then I send it via email. People would use these unique IDs to enter an event, only 80% came. I collected the IDs, now I have a list of IDs that belongs to the people that came to the event, I want to export all the rows of people who came using their IDs. Example: For every row that include number: 4293, 1932, 9382 = export. Is there's a way to do this in MySQL?

Following query should do the trick
select fullname from members where ID in (4293, 1932, 9382)

Related

Creating an Address book with different users.

I'm trying to make an Address book with different users in which they can log in with their username and password. And they can store the information like contact id, first name, last name, phone etc. I want each user to have his own address book.
Can someone please explain how I create different address book for different users.
Thanks a lot.
Create a database. take a primary id to each user or provide unique id.Then create another table fill the fields that you want(address book).Match the user who logged in and and with that another table(foreign key relationship).
When you login ..it checks with db then allows.After that you have to use insert ,update keywords for further process to put data in db.That particular unique id/primary key is used to fetch the related data(address book fields) of that user.
It is actually not a good question for StackOverflow but I will still roughly explain it to you.
You will need two different tables for this. The first one will be used for login details and the second one will record user's address book.
For example:
Table auth will have 3 columns id, username, password
Table addressBook will have contact id, first name, last name, phone etc and also have one more which will be called userID
Whenever any user eneter the data in addressBook their userID from auth table coloum id will be stored along with it. Now you can display their own data to the users.
If you have anymore question ask in comment here.

How better to create Users table?

I created Users table.
After the user registered, The system enter his address, phone, city and more personal details to Users table.
There is another table, called Contacts, there the user add another people details.
Now, if there is Contacts table, How better to save the personal details of the user in Users table? in one json column that contains all the user personal details, or in normal columns (address, phone, city)?
I just do not want to happen a situation of multiple data.
I think separate columns for each field will be the better option!
Well, it would of course be easy to just store it as JSON, but that way, it could be a bit messy to search for certain stuff in the database (say you wish to check all users from a given city for example).
When it comes to user information, I always find the best way to do this is to store only login vital data and the base info in a users table.
Something like:
id | email | password
And then have different tables for the other data.
Name and such (which a user only has one of (of course one could have multiple names, but I usually only store first and last names)) could be stored in a user_information table, which is in a one to one relation with the user (foreign key for the user_id so that it can be quickly fetched when needed).
When it comes to address and phone number, a user could actually have multiple.
I understand that its possible that your system/app is only supposed to support one address or one phone number and the like, but its always nice to make it "right" from the start, so that its easy to just let the user add multiple of them whenever the need is there.
That way, you would have a few different tables:
users
user_information
addresses
phone_numbers
and so on...
The user_information, addresses and phone_numbers would preferably all have a user_id column which would be used for a foreign key to point at the user who owns it. And if you wish to make it possible to use the same tables for contacts, a contact_id could be added too (and a foreign key to point to the contact).

Connect users with tags they create without having duplicate content in mysql database

I want to allow users to enter up to 5 tags tag like a company name, or charity their associated with. When a user clicks on that tag, it will take them to a page with all the users associated with that tag.
example: If somebody enters CBS, it will show all users associated with CBS.
I know I can add a unique index to keep users from entering duplicate content like stated here , but won't that keep users from being able to enter a company they are associated with if it already exist in the database.
I don't wan't duplicates in the database, but do wan't to allow users the choice to pick companies that may already exists in the database submitted from other users.
This database will hold only data submitted from the users.
I am using larval 5
my database looks like this:
Users
id|username|email
Tags
id|tags
usertags
id|userId|tagId
You can use the validate in request file of laravel
Use Unique based on the tag(and/or)comment & user id
It will help you to get data what you are expecting
refer laravel document also

display number of emails sent using php mail function

I am creating a real-estate website that displays properties. On each property listing I would like a button that says 'Express Interest', when clicked, this button should send an email to me containing the user details who expressed interest (the user will be logged in and so all their details will be taken from their account).
I have the email function working fine, HOWEVER, I also want to display the number of people who have 'Expressed Interest'. Is there a way to track how many times an email has been sent using this button and display "xx people have expressed interest in this property"
Store in the database before sending the mail and just before sending the mail include the number of people or the people who are interested, a simple query would suffice, or if you have a content management system you can include it there, in both cases you would need an intermediate table (connection between user id and real-estate id)
I would add another table to your database that stores a property_id and a user_id. If a user clicks expresses interest, you add another row to that table with the current property_id and the current user_id. To get the amount of links you simply count the rows
SELECT count(user_id) FROM interest_relation WHERE property_id = 'your property id'
This way you can also find out which user is interested in which property.

How create a DRY workflow for associating phone numbers with users

So basically what I'm working with is a database full of phone numbers.
if I get one of those users from that phone database and they sign up to my website I want to automatically associate the number from the database that is already present, how would I go about linking those 2 tables together once a user signs up?
Assuming that you have phone number table and users table you need to store the primary keys of both table together
You can do it:
In a user table, but then you will be able to link only one phone number to a user (and later if you will have to add more then one phone you might end up adding fields like phone_number_1, phone_number_2, etc... which is quite horrible)
In a phone number table, but then you will be able to link only one user to a phone number (same problem may arise as in point one)
In a separate table, but then you will have to use a join every time you need to get a user or phone number
The right choice depends on the relationships between the data that you are trying to model.
So, the database would be structured using composition. Keep a phone_numbers table w/ phone_number_id, the users table w/ user_id, and then a customer_phone_numbers table that maps user_ids to phone_number_ids. Then your PHP code would do something like this:
<?php
$user->save(); // save normal user data
$phoneNumbers = array();
foreach($user->getPhoneNumbers() as $phoneNumber) {
$phoneId = getPhoneNumberId($phoneNumber); // get the phone number, or save a new record if necessary, and return that number
$phoneNumbers[] = $phoneId;
}
$user->savePhoneNumbers( $phoneNumbers ); // adds or removes phone numbers as necessary
EDIT: Based on your feedback, it doesn't sound so much like you are just looking for a way to associate the data. If I understand you correctly, the user will sign up for your website via their phone, then later register on the website. You want to combine the two registrations when this happens.
Are users creating a complete profile from their phone? Do you have a process in place to verify that the phone number provided by the user is actually theirs?
If the user is not creating a full profile via the phone, it sounds like there are two types of "profiles" being stored, a complete website profile, and a telephone profile. This way, you would have a phone profile w/ a phone_profile_id and a regular user record w/ a user_id. Then, let users verify their telephone information and associate them to a phone_profile_id using a composition table as above.
Is that a little closer?
Thanks,
Joe

Categories