A lot of people seem to have problems with updating or inserting data in tables in an intelligent way. We shouldn’t point a finger to those who don’t use the correct syntax for the problem it solves, because there are a lot of different ways to do this, but I wanted to create a little list of interesting syntax’s that are often forgotten and never used. I will talk about:
- insert… on duplicate key update
- replace
- insert… select
- Load data infile and select into outfile
- delayed
Read more…
Categories: General, database, mysql Tags: delayed, duplicate key, infile, insert, mysql, option, outfile, replace, select, syntax, update
I had a problem earlier today: I needed to have a select box that returns 2 or more values in stead of 1.
I got this far:
The value of the options gets the id of the item that is displayed in each option.
I do have an other value that should be linked on this option. Is there an easy way to do this?
<select id="category" name="data[cat]">
<option label="0" value="12">A</option>
<option label="0" value="7">B</option>
</select>
I tried to do this with entering the second value into a label attribute but then the problem is that i don’t know the correct way to get the label value of the selected option. This is written in Jquery.
To get the selected option I use:
$("#category").livequery('change', function () {
var catId = ($(this)[0].value);
});
the solution seems to be quite simple:
The label attribute is used by some browsers to display the content of the option, so your list box might display two 0 options.
A better solution might be to do the following:
<select id="category" name="data[cat]">
<option value="12,0">A</option>
<option value="7,0">B</option>
</select>
and split the value in the event handler, e.g.
$("#category").livequery('change', function () {
var values = ($(this)[0].value).split(",");
var catId = values[0];
var otherId = values[1];
});
Wasn’t that easy
Recent Comments