Update
If you were forced to use a single char on a split method, which char would be the most reliable?
Definition of reliable: a split character that is not part of the individual sub strings being split.
I have these rows in a table
ID Name Price Delivery
== ==== ===== ========
1 apple 1 1
2 apple 3 2
3 apple 6 3
4 apple 9 4
5 orange 4 6
6 orange 5 7
I want to have the price at the third delivery (Delivery=3) or the last price if there's no third delivery.
It would give me this :
ID Name Price Delivery
== ==== ===== ========
3 apple 6 3
6 orange 5 7
I don't necessary want a full solution but an idea of what to look for would be greatly appreciated.
Hey everyone. I'm currently preparing for my exams and would like to know some examples of user-defined integrity rule in database systems. As far as I understand, it means that I can set up certain conditions for the columns and when data is inserted it needs to fulfill these conditions.
For example: if I set up a rule that an ID needs to consist of 5 integers ONLY then when I insert a row with ID which is made up of integers and some chars then it won't accept it and return an error.
Could someone confirm and give me some opinion on that? Thank you very much in advance!
I need to construct a long string with javascript. Thats how i tried to do it:
var html = '<div style="balbalblaba"> </div>';
for(i = 1; i <= 400; i++){
html=+html;
};
When i execute that in firefox its taking ages or makes it crash. what is the best way to do that? What is generally the best way to construct big strings in JS.
can someone help me?
I have a situation that I'm sure is quite common and it's really bothering me that I can't figure out how to do it or what to search for to find a relevant example/solution. I'm relatively new to MySQL (have been using MSSQL and PostgreSQL earlier) and every approach I can think of is blocked by some feature lacking in MySQL.
I have a "log" table that simply lists many different events with their timestamp (stored as datetime type). There's lots of data and columns in the table not relevant to this problem, so lets say we have a simple table like this:
CREATE TABLE log (
id INT NOT NULL AUTO_INCREMENT,
name VARCHAR(16),
ts DATETIME NOT NULL,
eventtype VARCHAR(25),
PRIMARY KEY (id)
)
Let's say that some rows have an eventtype = 'start' and others have an eventtype = 'stop'. What I want to do is to somehow couple each "startrow" with each "stoprow" and find the time difference between the two (and then sum the durations per each name, but that's not where the problem lies). Each "start" event should have a corresponding "stop" event occuring at some stage later then the "start" event, but because of problems/bugs/crashed with the data collector it could be that some are missing. In that case I would like to disregard the event without a "partner". That means that given the data:
foo, 2010-06-10 19:45, start
foo, 2010-06-10 19:47, start
foo, 2010-06-10 20:13, stop
..I would like to just disregard the 19:45 start event and not just get two result rows both using the 20:13 stop event as the stop time.
I've tried to join the table with itself in different ways, but the key problems for me seems to be to find a way to correctly identify the corresponding "stop" event to the "start" event for the given "name". The problem is exactly the same as you would have if you had table with employees stamping in and out of work and wanted to find out how much they actually were at work. I'm sure there must be well known solutions to this, but I can't seem to find them...
void spriteput(int x,int y, int stype)
{
char sprite1[5]="OOOO";
char sprite2[5]="OOOO";
char sprite3[5]="OOOO";
char sprite4[5]="OOOO";
if (stype == 1)
{
char sprite1[5] = " OO ";
char sprite2[5] = "OOOO";
char sprite3[5] = "OOOO";
char sprite4[5] = " OO ";
mvprintw(2,y,"%s \n",sprite1);
}
mvprintw(x+1,y,"%s \n",sprite2);
mvprintw(x+2,y,"%s \n",sprite3);
mvprintw(x+3,y,"%s \n",sprite4);
}
If I'm correct that block of code should print out on a NCURSES screen
OO
OOOO
OOOO
OO
Instead however, it prints out the default text (the first char statements). Can anyone tell me why this is? The "printw" statement inside the If-block prints out the proper text, so it's being assigned correctly. Thank you in advance.
String dateimput=request.getParameter("datepicker");
System.out.printl("datepicker:" +dateimput);
DateFormat df = new SimpleDateFormat("MM/dd/yyyy");
Date dt = null;
try
{
dt = df.parse(dateimput);
System.out.println("date imput is:" +dt);
} catch (ParseException e)
{
e.printStackTrace();
}
*datepicker:04/29/2010 (value I currently selected from datepicker).
*the field in database is typed date.
1-date imput is:Thu Apr 29 00:00:00 CEST 2010
and in database level it is inserted like that 01/01/0001 00:00:00
I have a data set that I import into a SQL table every night. One field is 'Address_3' and contains the City, State, Zip and Country fields. However, this data isn't standardized. How can I best parse the data that is currently going into 1 field into individual fields. Here are some examples of the data I might receive:
'INDIANAPOLIS, IN 46268 US'
'INDIANAPOLIS, IN 46268-1234 US'
'INDIANAPOLIS, IN 46268-1234'
'INDIANAPOLIS, IN 46268'
Thanks in advance!
David
Hi,
I am working on a Japanese File and I have no knowledge of the language. The file is encoded in S-JIS. Now, I am supposed to convert the contents into UTF-8 so that the content looks like Japanese. And here I am completely blank. I tried the following code that I found somewhere on Internet but no luck:
byte[] arrByte = Encoding.UTF8.GetBytes(arrActualData[x]);
string str = ASCIIEncoding.ASCII.GetString(arrByte);Can anyone help me with this?
Thanks in advance
Kunal
I'm trying to create a script that allows me to upload an image, grab the details sent through inputs (a description and chosen project number) and insert this information into a table. I currently have this function:
public function NewEntry() {
$connect = new dbconnect;
$_SESSION['rnd'] = substr(number_format(time() * rand(),0,'',''),0,15);
$allowedExts = array("gif", "jpeg", "jpg", "png");
$size = $_FILES["file"]["size"];
$path = $_FILES["file"]["name"];
$extension = pathinfo($path, PATHINFO_EXTENSION);
$pr = $_POST['project'];
$cl = $_POST['changelog'];
$file = $_SESSION['rnd'] . "." . $extension;
if (in_array($extension, $allowedExts) && $size < 200000000) {
if ($_FILES["file"]["error"] == 0) {
if (!file_exists("../uploads/" . $_SESSION['rnd'])) {
move_uploaded_file($_FILES["file"]["tmp_name"], "../uploads/" . $_SESSION['rnd'] . "." . $extension);
}
}
} else {
echo "File validation failed.";
}
$row = $connect->queryExecute("INSERT INTO entries(project,file,changelog)VALUES($pr,$file,$cl)");
header('location:http://www.example.com/admin');
}
When the form is posted the function runs, the image uploads but the query isn't executed.
The dbconnect class isn't at fault as it's untampered and has been used in past projects. The error logs don't give any output and no MySQL errors show. Any ideas?
I would really love your help with the following problem:
I want to get as an input from the user a maximum length of 30 chars string and check whether it contains an end of line.
This is what I tried to write so far:
int main(void) {
int i;
char* command = (char*)calloc(31, sizeof(char));
while (0 < 1) {
scanf("%s", command);
for (i = 0; i <= strlen(command); ++i) {
if (command[i] == '\n')
printf("here");
}
if (strcmp(command, "quit") == 0)
break;
}
The idea is to check whether the command given by the user as input is "legal" - that is of length < 31.
when i run this code, it never prints "here" regardless of the length of input.
I tried to take input in form of string, specifically:
int i=0;
char c[50][500];
for(;i<50;++i)
scanf("%s",A[i]);
The input is
x is a website that allows the easy[1] creation and editing of any number of interlinked
web pages via a web browser using a simplified markup language or a WYSIWYG text editor.
In my program, I want the text to be stored as:
A[0]="x is a website that allows the easy[1] creation and editing of any number of interlinked"
A[1]=" web pages via a web browser using a simplified markup language or a WYSIWYG text editor."
But my code causes the text to be stored as
A[0]="is"
A[1]="a"
A[2]="website"
....
What am I doing wrong?
I want be able to find tags of items under the a certain category. Following is example of my database design:
images
+----------+-----+-------------+-----+
| image_id | ... | category_id | ... |
+----------+-----+-------------+-----+
| 1 | ... | 11 | ... |
+----------+-----+-------------+-----+
| 2 | ... | 12 | ... |
+----------+-----+-------------+-----+
| 3 | ... | 11 | ... |
+----------+-----+-------------+-----+
| 4 | ... | 11 | ... |
+----------+-----+-------------+-----+
images_tags
+----------+--------+
| image_id | tag_id |
+----------+--------+
| 1 | 53 |
+----------+--------+
| 3 | 54 |
+----------+--------+
| 2 | 55 |
+----------+--------+
| 1 | 56 |
+----------+--------+
| 4 | 57 |
+----------+--------+
tags and categories each have their own table relating the id to an actual name(text).
So my question is how will i find out that images with category_id=11 have have the tag_id 53 54 55 56 57.
In other words how to find the tags that images in certain category have?
Hello,
Im trying to insert data into a table in MySQL. I found/modified some code from w3Schools and still couldn't get it working. Heres what I have so far:
<?php
$rusername=$_POST['username'];
$rname=$_POST['name'];
$remail=$_POST['emailadr'];
$rpassword=$_POST['pass'];
$rconfirmpassword=$_POST['cpass'];
if ($rpassword==$rconfirmpassword) {
$con = mysql_connect("host","user","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("mydbname ", $con);
}
mysql_query("INSERT INTO members (id, username, password)
VALUES ('4', $rusername, $rpassword)");
?>
Did I mistype something? To my understanding "members" is the name of the table. If anyone knows whats wrong I appreciate the help.
Thanks
I have followed the code example here
toupper c++ example
And implemented it in my own code as follows
void CharString::MakeUpper()
{
char* str[strlen(m_pString)];
int i=0;
str[strlen(m_pString)]=m_pString;
char* c;
while (str[i])
{
c=str[i];
putchar (toupper(c));
i++;
}
}
But this gives me the following compiler error
CharString.cpp: In member function 'void CharString::MakeUpper()':
CharString.cpp:276: error: invalid conversion from 'char*' to 'int'
CharString.cpp:276: error: initializing argument 1of 'int toupper(int)'
CharString.cpp: In member function 'void CharString::MakeLower()':
This is line 276
putchar (toupper(c));
I understand that toupper is looking for int as a parameter and returns an int also, is that the problem? If so how does the example work?
Hello-
I am a newbie in Bash and I am doing some string manipulation.
I have the following file among other files in my directory:
jdk-6u20-solaris-i586.sh
I am doing the following to get jdk-6u20 in my script:
myvar=`ls -la | awk '{print $9}' | egrep "i586" | cut -c1-8`
echo $myvar
but now I want to convert jdk-6u20 to jdk1.6.0_20. I can't seem to figure out how to do it.
It must be as generic as possible. For example if I had jdk-6u25, I should be able to convert it at the same way to jdk1.6.0_25 so on and so forth
Any suggestions?
i intend to fill a char-pointer array successively in a for-loop. the content to fill in is a integer so i need to cast. but i didn't get the result i want to..
for (i=0;i<max0;i++){
sprintf(buf, "%d", content[i]);
}
sprintf replaces the hole buf, but i want to append.
for (i=0;i<max0;i++){
buf[i]=(char) contint[i]
}
but this isn't working too. it seems to me, i get ascii-code of the content[i].
Hello,
I have a database full of rows like
id,action,date
2,2,2010-03-01
3,2,2010-03-01
4,3,2010-03-01
5,3,2010-03-01
6,4,2010-02-01
7,4,2010-02-01
And I want to select all the count all the 2's and all the 3's and all the 4's. But I don't want to have to do 3 different SELECT COUNT() commands, is there a way to do this in a single command?
Note, I want to display this as something like
Action 2 = 2
Action 3 = 2
Action 4 = 2
(etc etc).
And I will also need to specific a date (so it only counts all the 2,3,4,etc for dates between 2010-02-03 and 2010-03-01 for example)
I have the following code:
LPCTSTR strPermission = Method();
if (strPermission == L"0")
{
return true;
}
else
{
return false;
}
While debugging I can see that strPermission does equal "0", yet when I compare it like in the if statement it always returns false.
The only thing I can think of is that it is comparing the memory address of the variable rather than the variable value.
How do I compare strPermission to L"0" so that it would return true if strPermission equals "0".
Thank you!
Hi. Code not working because of async query and variable scope problem. I can't understand how to solve this. Change to $.ajax method with async:false - not an option. I know about closures, but how I can implement it here - don't know. I've seen all topics here about closures in js and jQuery async problems - but still nothing. Help, please.
Here is the code:
var map = null;
var marker;
var cluster = null;
function refreshMap()
{
var markers = [];
var markerImage = new google.maps.MarkerImage('/images/image-1_32_t.png', new google.maps.Size(32, 32));
$.get('/get_users.php',{},function(data){
if(data.status == 'error')
return false;
var users = data.users; // here users.length = 1 - this is ok;
for(var i in users)
{
//here I have every values from users - ok
var latLng = new google.maps.LatLng(users[i].lat, users[i].lng);
var mark = new google.maps.Marker({
position: latLng,
icon: markerImage
});
markers.push(mark);
alert(markers.length); // length 1
}
},'json');
alert(markers.length); // length 0
//if I have alert() above - I get result
cluster = new MarkerClusterer(map, markers,
{
maxZoom: null,
gridSize: null
});
}
Thanks.