1

My db is storing hotel_names in 1-7 rows but counts are stored in 8-14 rows.i want to store counts according to hotel_name. Actually i am stuck at one point. i want to display like this:

 Hotel_id   Hotel_name| Is_pool |   Pool_count                                              
1   cAnberra hotel  1   1.4 
2   Hayat hotel     1   1.2 
3   grand           1    1.0    
4   New one hotel   1   1.99    
5   7 hotels        1   0.98    
6   New light       1   0.78    
7   Lime light hotel1   0.1 

but my code is dislaying :

Hotel_id    Hotel_name  Is_pool Pool_count
  1    cAnberra hotel        1  
  2     Hayat hotel          1  
  3     grand                1  
  4     New one hotel        1  
  5     7 hotels             1  
  6      New light           1  
  7     Lime light hotel     1  
  8                                1.4
  9                                1.2
  10                               1.0
  11                               1.99
  12                               0.98
  13                               0.78
  14                               0.1

This is my code:

for hotel in myarrayUrl[ind_pos]:
    print("The myarrayUrl converted to a list")
    print(hotel)

    c.execute("INSERT INTO hotels (hotel_name, is_pool) VALUES (?,?)" , [hotel,1])   


for count in myarray[ind_pos]:

    print("The myarray converted to a list")
    print(count)

    c.execute("INSERT INTO hotels (pool_count)  VALUES (?)" , [count])

help me.thanks in advance.

Techgeeks1
  • 556
  • 1
  • 4
  • 18
  • How is this not a duplicate of your [earlier question](http://stackoverflow.com/questions/42969204/if-the-column-hotel-name-values-already-exist-then-add-1-in-the-column-of-is-poo)? – CL. Mar 31 '17 at 14:16
  • Possible duplicate of [if the column hotel\_name values already exist then add 1 in the column of is\_pool,otherwise add new data to hotel\_name column](http://stackoverflow.com/questions/42969204/if-the-column-hotel-name-values-already-exist-then-add-1-in-the-column-of-is-poo) – Noctis Skytower Mar 31 '17 at 14:19
  • @CL. i have edited the question now can u help me? – Techgeeks1 Apr 01 '17 at 09:25

1 Answers1

0

Each INSERT statement creates a new row.

To change some value in an existing row, you would need to do an UPDATE.

However, in this case, you should just insert all values into the same row at once:

for hotel, count in zip(myarrayUrl[ind_pos], myarray[ind_pos]):
    c.execute('INSERT INTO hotels(hotel_name, is_pool, pool_count) VALUES (?, ?, ?)',
              [hotel, 1, count])
CL.
  • 173,858
  • 17
  • 217
  • 259