dongliao2011 2017-08-06 07:20
浏览 52

Android MYSQL数据插入

I have a booking application. So I have a table called description where a company can add their informations. Second table is called booking, and in this table, people can make a booking to one of the company informations.

Table description:

  1. company_id Auto-Increment
  2. companytitle Text
  3. jobtitle Text
  4. description Text
  5. startDate Text
  6. endDate text

Table bookings:

  1. id Auto-Increment
  2. companytitle Text In this field, when you make a booking, it will display the company name of the company
  3. name Text
  4. surname Text - Your surname
  5. date Text - the date when you can make a booking
  6. company_booking_id - Here, when you make a booking you have an ID, that will be the FK of the companyid that is in the first table.

Php script:

"insert into bookings (companytitle, name, surname, date, company_booking_id) values ('$companytitle','$name', '$surname', '$date','$company_booking_id' )";

Now, lets say you are logging in as a User, you have a customLayout with the informations that every company has put, you choose one company, how can you make a booking to that specific company ? How the app will know for which company you made a booking ?

Exemple: First company

  • Company Title - X
  • Company Description - Selling carrots
  • Start Date - 20 july 9:00 PM
  • End Date - 21 july 9:00 pm

Second company:

  • Company Title - Y
  • Company Description - Selling potatoes
  • Start Date - 20 july 9:00 PM
  • End Date - 21 july 9:00 pm

These are 2 different companies, I'm logging in as a user and I want to make a booking to one of these, how the app will know for which company I made the booking ? :D

BookingAddClass:

> public class BookingAdd {
>     String companytitle;
>     String name;
>     String surname;
>     String data;
> 
>     public BookingAdd(){}
> 
>     public BookingAdd(String companytitle, String name, String surname, String date) {
>         this.companytitle = companytitle;
>         this.nume = nume;
>         this.prenume = prenume;
>         this.data = data;
>     }
> 
>     public String getCompanytitle() {
>         return companytitle;
>     }
> 
>     public void setCompanytitle(String companytitle) {
>         this.companytitle = companytitle;
>     }
> 
>     public String getNume() {
>         return nume;
>     }
> 
>     public void setNume(String nume) {
>         this.nume = nume;
>     }
> 
>     public String getName() {
>         return name;
>     }
> 
>     public void setSurname(String surname) {
>         this.surname = surname;
>     }
> 
>     public String getData() {
>         return data;
>     }
> 
>     public void setData(String data) {
>         this.data = data;
>     } }

Every user when is making an account has to complete their personal info.

> public class BookingsAdapter extends BaseAdapter {
>     Context c;
>     ArrayList<CompanyData> informations = new ArrayList<>();
>     LayoutInflater inflater;
>     Button makeABooking;
> 
>     public Button getMakeABooking() {
>         return makeABooking;
>     }
> 
>     public void setMakeABooking(Button makeABooking) {
>         this.makeABooking = makeABooking;
>     }
> 
>     public BookingsAdapter(Context c, ArrayList<CompanyData> informations) {
>         this.c = c;
>         this.informations = informations;
>         inflater = (LayoutInflater) c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
>     }
> 
>     public BookingsAdapter() {
>         super();
>     }
> 
>     @Override
>     public int getCount() {
>         return informations.size();
>     }
> 
>     @Override
>     public Object getItem(int i) {
>         return informations.get(i);
>     }
> 
>     @Override
>     public long getItemId(int i) {
>         return i;
>     }
> 
>     @Override
>     public View getView(int i, View view, ViewGroup viewGroup) {
>         CompanyData companyData = informations.get(i);
> 
>         if(view == null) {
>             inflater = (LayoutInflater) c.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
>             view = inflater.inflate(R.layout.bookingslayout, null);
>         }
>         // ImageView logo = (ImageView)view.findViewById(R.id.logoImageView);
>         TextView title = (TextView) view.findViewById(R.id.companyTitletextview);
>         TextView description = (TextView) view.findViewById(R.id.companyDescriptiontextview);
>         TextView startDate = (TextView) view.findViewById(R.id.textviewstart);
>         TextView endDate = (TextView) view.findViewById(R.id.textviewend);
> 
>         title.setText(companyData.getTitle());
>         description.setText(companyData.getDescription());
>         startDate.setText(companyData.getStartDate());
>         endDate.setText(companyData.getEndDate());
> 
> 
>         return view;
> 
> 
>     }
> 
>     @Override
>     public CharSequence[] getAutofillOptions() {
>         return new CharSequence[0];

}

}

Layout with the listview, I dont have any special info in it at the moment..

> public class Bookings extends AppCompatActivity {
>     ListView listView;
>     final static String urlAdress = "http://localhost/bookingslist.php";
> 
>     public void makebookingbutton(View view){
>         BookingAdd addbooking = new BookingAdd();
>         //add the booking
>         Toast.makeText(Bookings.this, "Test", Toast.LENGTH_SHORT).show();
>     }
> 
> 
>     @Override
>     protected void onCreate(Bundle savedInstanceState) {
>         super.onCreate(savedInstanceState);
>         setContentView(R.layout.activity_bookings);
>         listView = (ListView)findViewById(R.id.listView1);
> 
>         BookingsDownloader downloader = new BookingsDownloader(Bookings.this,urlAdress,listView);
>         downloader.execute();
>     } }
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题
    • ¥20 易康econgnition精度验证
    • ¥15 msix packaging tool打包问题
    • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
    • ¥15 python的qt5界面
    • ¥15 无线电能传输系统MATLAB仿真问题
    • ¥50 如何用脚本实现输入法的热键设置
    • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
    • ¥30 深度学习,前后端连接
    • ¥15 孟德尔随机化结果不一致