Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6583099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:21:51+00:00 2026-05-25T16:21:51+00:00

I have a matrix of inputs boxes which contain prices for dates. If there

  • 0

I have a matrix of inputs boxes which contain prices for dates. If there is no price in the database for a particular date the input box displays 0. I have the following code which saves into the database the prices typed into the input boxes. It does not save all the 0 values only the new prices.

Which is fine. However I have now discovered an issue. If one of the inputs dislays a value from the database, say $10 and I want to set it now to 0, the code will not do it.

It will only save if the values and above 0. I have not been able to do this final check.

The conditions for saving are
1. If the value is numeric
2. If it is 0 and already has an entry in the database then save
3. If it has no value in the database and is greater than 0
4. If it is 0 and has no value in the database then do not save

        if (isset($this->data['Rate'])){

            // for each rate
            foreach($this->data['Rate'] as $rate_id => $room){

                    // for each room type           
                    foreach($room as $room_id => $room){

                        $price_for_today = isset($room['Price'][$key]) ? $room['Price'][$key] : 0;

                        // get existing availabilities is num (get this from previous date loop)
                        $today = ''.$date.' 00:00:00';          
                        $conditions = array('Availability.date' => $today,'Availability.room_id'=>$room_id);
                        $this->Availability->contain();         
                        $result = $this->Availability->find('all',array('order'=>'Availability.room_id ASC', 'conditions'=>$conditions));
                        $avail_id = $result[0]['Availability']['id'];

                        // check prices
                        $check_prices = "SELECT * FROM prices 
                                WHERE rate_id = '".$rate_id."' AND availability_id = '".$avail_id."'";
                        $prices_result = $this->Availability->query($check_prices);

                        // if new prices > 0.00
                        if($price_for_today>0 && is_numeric($price_for_today)){
                            // better checking needed!
                            if($prices_result){
                                    $setprices = "UPDATE prices SET price = '".$price_for_today."'  
                                    WHERE rate_id = '".$rate_id."' AND availability_id = '".$avail_id."'";
                                    $update = $this->Availability->query($setprices);
                            } else {
                                    $setprices = "INSERT INTO prices (price, availability_id, rate_id) 
                                    VALUES ('".$price_for_today."', '".$avail_id."', '".$rate_id."')";
                                    $insert = $this->Availability->query($setprices);           
                            }
                        }

                        //$errors[] = $setprices;

                    } // end rooms loop

            } // end Rates loop
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T16:21:52+00:00Added an answer on May 25, 2026 at 4:21 pm

    Your problem is in

    > // if new prices > 0.00
    >                         if($price_for_today>0 &&
    > is_numeric($price_for_today)){
    

    here you specify that $prices_for_today have to be >0, so if you had a price and want to put it 0 today then you will not do anything… You should use

    if(($price_for_today>0 && is_numeric($price_for_today)) || (!empty($prices_result) && $price_for_today==0 && is_numeric($price_for_today))){
    

    if you change it it will now enter in the if and do the change.

    I sugest that you do NOT use the query function unless is extremely necesary. you should create a model for price (if you haven’t done that already) and then use the associations (hasMany, HasOne, HABTM) or load the model directly in the controller with $this->loadModel(‘Price’). Then use a find ‘all’ as always with conditions and fields. This recomendation is to use cake as it was intended, not indispensable. Also the save, updatefield, read can be done if you do this… leaving the checks and everything to cake.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a 3x12 matrix I'd like to input into my LaTeX (with amsmath)
I have a MATLAB matrix, that is 1000x4, to use as an input for
I've got 2 different files, one of them is an input matrix (X) which
I have data sorted by dates: e.g. Region - Date - Count East -
I have a NxN matrix which I want to split into non-overlap KxK block.
In OpenCV, there is a CvSVM class which takes in a matrix of samples
I have a problem, user inputs number m (meaning matrix has m-rows, m-columns), then
I have a Matlab application that generates a output matrix based on user input.
I have a text file which contains matrix of N * M dimensions. For
I have a 4x8 matrix. { 0,0,0,0,0,0,0,0 0,0,0,0,0,0,0,0 0,0,0,0,0,0,0,0 0,0,0,0,0,0,0,0 } if i input

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.