Hi,
I am having a problem with a concatenated string.
I start my string outside of a for() and then, concatenate the string generated with the loop to it.
the string out of the loop looks like this:
$q = "INSERT INTO (asdf1,asdf2,as df3) VALUES"
then when i add something like this:
$q .="('".$asdf1." ', '".$asdf2."' , '".$asdf3."' )"
when i make the query, mysql returns syntax error because the final string looks something like this:
"INSERT INTO (asdf1,asdf2,as df3) VALUESasdf1', 'asdf2', 'asdf3')asdf1', 'asdf2', 'asdf3')asdf1', 'asdf2', 'asdf3')asdf1', 'asdf2', 'asdf3')...
So the first part of the concatenated string:"('" ,seem to desapear.
I simplified the query string to focus on the real problem...
here is the function code: -
/* Insert new content into calendar */
-
private function insert_into_calendar(){
-
-
/* Create mysql query code */
-
$this->query = 'INSERT INTO calendar (date_id, date, hour, hour_state, hour_sub, hour_sub_state) VALUES';
-
$first = true;
-
for($i = 1; $i<= $this->days_to_add ; $i++){ //DATE
-
$date_to_add = date("d.m.y", mktime(0, 0, 0, $this->table_max_date_exploded['m'] , $this->table_max_date_exploded['d']+$i, "20".$this->table_max_date_exploded['y']));
-
-
for($j = Calendar_auto_updater::DAY_HOUR_START; $j <= Calendar_auto_updater::DAY_HOUR_END; $j++){ //HOUR
-
$hour = $j.":00";
-
-
for($k = 0; $k <= $this->hour_sub_max; $k += $this->hour_fraction){ //HOUR_SUB
-
if($k == 0){ //allways want an hour format of this kind "hh:mm"
-
$hour_sub = $j.":".$k."0";
-
}
-
else{
-
$hour_sub = $j.":".$k;
-
}
-
-
if($first == true){ //only want to put a "," before the "(" if its not just after "VALUES" SQL SYNAX
-
-
$this->query .='(\''.$this->table_max_date_id+$i.'\', \''.$date_to_add.'\', \''.$hour.'\', \'0\', \''.$hour_sub.'\', \'0\')';
-
$first = false;
-
}
-
else{
-
$this->query .=', (\''.$this->table_max_date_id+$i.'\', \''.$date_to_add.'\', \''.$hour.'\', \'0\', \''.$hour_sub.'\', \'0\' )';
-
}
-
}
-
}
-
}
-
print $this->query;
-
-
/* Make query */
-
$result = mysql_query($this->query, $this->connection) or die(mysql_error());
-
if($result == true){
-
return true;
-
}
-
else{
-
$this->error['insert'] = "Error while inserting";
-
return false;
-
}
-
}
-
if you have any suggestions... please let me know
Thank you very much,
Best Regards,
3 1534 Atli 5,058
Recognized Expert Expert
Hi.
The only thing I can see that *might* be causing this is the math in the first variable you add:
Similar to:
Try encapsulating that, like: -
$var = "(". (1 + 1) .")";
-
Hi.
The only thing I can see that *might* be causing this is the math in the first variable you add:
Similar to:
Try encapsulating that, like: -
$var = "(". (1 + 1) .")";
-
thank you very much for taking your time.
i have solved this problem by putting the "('" into different variables, and then i have concatenated them with the rest, it has worked properly, although i will try what you said just for intellectual curiosity. :)
thank you again
bilibytes
pbmods 5,821
Recognized Expert Expert
'+' and '.' have the same order of precedence and left associativity, so they will be evaluated from left to right unless you use parenthesis.
E.g,: -
'a' . 1 + 1 . 'b' = '1b'; // ((('a' . 1) + 1) . 'b')
-
'a' . (1 + 1) . 'b' = 'a2b';
-
http://php.net/operators Sign in to post your reply or Sign up for a free account.
Similar topics |
by: M Wells |
last post by:
Hi All,
I have what seems to me to be a difficult query request for a database
I've inherited.
I have a table that has a varchar(2000) column that is used to store
system and user messages from an on-line ordering system.
For some reason (I have no idea why), when the original database was
being designed no thought was given to putting these messages in
|
by: Rudolf Bargholz |
last post by:
Hi ,
I have the following tables
-------------
PAX:
Id
Order_Id
Name
Position
|
by: B Love |
last post by:
Hello Group,
I have 2 text fields that I would like to concatenate for use in a table.
One field is an ordinary text box. The other is a simple combo box which I
use to select one of about ten items.
The ordinary text field is: NewLongDescription
(This is a memo field that contains descriptions of dolls sold in an e-comm
site)
|
by: Dr. StrangeLove |
last post by:
Greetings,
Let say we want to split column 'list' in table lists
into separate rows using the comma as the delimiter.
Table lists
id list
1 aa,bbb,c
2 e,f,gggg,hh
3 ii,kk
4 m
|
by: Kurt |
last post by:
I'm using the fConcatChild function posted at
http://www.mvps.org/access/modules/mdl0004.htm to return a field from
the Many table of a 1:M relationship into a concatenated string. The
function puts everything in a comma separated format. In my case, it
returns a list of authors:
Borman, W., Oppler, S., White, L.,
I'd like to change the function so the last record in the string is
preceded by an ampersand instead of a comma, as in:
| |
by: Jeff Silverman |
last post by:
I have a PHP program that almost works. I'm running it from the command
line and simulating a form using a GET method. That part is working,
but I get spurious records with all of the fields concatenated into a
single field.
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=windows-1252"
http-equiv="content-type">
|
by: eric.goforth |
last post by:
Hello,
I'm working with a classic asp page that calls another classic asp
page. The html in my calling page looks like:
<form method="post"
action="/includes/mypage2.asp?subtype=MyType&ecd=1&eid=97702">
....Do some stuff
|
by: Jazzer |
last post by:
I want to 'flatten' two tables into one by combining the '1-n' values from the 'child' records into a single concatenated string within the parent by using queries.
I.E. create a single NVarChar field to hold all of the values that are contained in the child entries for that parent.
E.G.
Parent 1 - Child 1 Value "Big"; Child 2 Value "Small"
Parent 2 - Child 1 Value "Red"; Child 2 Value "White"; Child 3 Value "Green"
To Become...
|
by: Brad Isaacs |
last post by:
Using ASP.NET 2.0 with SQL Server 2000
Inside my dropdown list box I am using an SQL DataSource to select the
following data
SELECT RTRIM(c.Name_First) + ' ' + RTRIM(c.Name_Last) AS Contact,
c.phone As PriPortPhone
FROM mppaContacts c
Dropdown list box works well .....
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |