The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

> UPDATE ROWS FOR N NUMBER OF TIMES
shankar from vizag
post Apr 30 2022, 09:18 PM
Post #1


Advanced Member
****

Group: Members
Posts: 202
Joined: 18-June 13
Member No.: 19,316



Greetings

Earlier I posted a topic for inserting a record for n number of times and now I need help and guidance for an update query in similar way.

Please suggest me how to update multiple rows for n number of times (like user specified times to repeat)

I tried with this, but not working

Here $days is the result of date range difference stored in a variable

if(isset($days) && is_numeric($days) && $days !='' && $days>0)
{
for($i=1;$i<=$days;$i++)
{
$sql = "UPDATE availability SET cabin1='$name' where `gen_date`='$datefrm'";

if(mysqli_query($conn, $sql)){
echo "<h3>data stored in a database successfully.";


} else{
echo "ERROR: Hush! Sorry $sql. "
. mysqli_error($conn);
}
}
}

I have a table `availability` with columns gen_date, cabin1, cabin2, cabin3, cabin4

and this is for room reservation application. the above table should fill with name of guest as per stay days corresponding to the `gen_date` column.



regards
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
 
Reply to this topicStart new topic
Replies
CharlesEF
post May 6 2022, 12:34 AM
Post #2


Programming Fanatic
********

Group: Members
Posts: 1,981
Joined: 27-April 13
From: Edinburg, Texas
Member No.: 19,088



I don't think the $sql statement I posted will do what you want. You should use:
CODE
$sql = "UPDATE `availability` SET `cabin{$ref}` = '$name' WHERE `gen_date` BETWEEN '$datefrm' AND '$dateto' ";


This post has been edited by CharlesEF: May 6 2022, 12:35 AM
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Posts in this topic


Reply to this topicStart new topic
2 User(s) are reading this topic (2 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 27th April 2024 - 02:30 PM