Possible Duplicate:
Alerternative to MySQL Order By Rand()
What is an efficient way to query for random result sets in the following scenarios:
Select a single random row from many.
Select (at least) n random rows from many.
Select all rows in a random order.
In particular interested in MySQL, but might be a reason to try ...
and have the changes save straight to the mysql db only requiring an email address to make the change
...
Steps:
I want a registered user to be able to insert values into a table.
Those values would only be able to be seen or edited by the user. (a few rows)
I have a registration/login page and insert form page complete and they can add do their respective jobs.
Here's the problem and i realize it probably a super simple answer:
How d...
My logout function needs to update the latest row of a list of logins.
This is what I have came up with, however it doesn't even pass syntax validation.
$query =
'UPDATE user_logins
SET active = 0
WHERE user_id = ' . Database::instance()->escape($this->getCurrentUserId()) . '
AND datetime = MAX(datetime) LIMIT 1';
...
I am trying to export data from my MySQL database to multiple CSV files and then GZIP them.
I have a couple of problems which make exporting it to a CSV file complicated ...
Several fields (10) need to be in 1 CSV file
Other fields (multiple!) are serialized and need to be exported into a different CSV file with two other non seriali...
I have a date in this format:
24-12-2010 // DAY - MONTH - YEAR
I need to get it in this format:
1995-12-31T23:59:59.999Z // The Z is for the TimeZone I think.
Check this link out:
http://lucene.apache.org/solr/api/org/apache/solr/schema/DateField.html
The above link is the way I need the date.
I am using PHP now, so this n...
Is it considered bad practice to let die() live in a production enviroment? Just happened to read this article http://www.phpfreaks.com/blog/or-die-must-die where the author fies upon people who use such a thing in a production enviroment. So shouldn't I code this way:
$connection = mysql_connect($db_host, $db_username, $db_password);
i...
I have a very interesting task, which I don't know how to implement.
I need to store many regular expressions in a database table, and need to be able to find which of them matches the given string.
For example:
id | regexp
---|-------------
1 | ^hello world$
2 | ^I have [0-9] flowers&
3 | ^some other regexp$
4 | ^and another (o...
How can I store a date-range in solr?
I need to store the start-date and the end-date.
Lets say it is a villa which is for rent during a period (start and end).
I must use two fields right?
In the search the user may chose start-date and end-date, so when querying solr I think I could use something like:
date:[$start TO $end]
...
I have a table with two columns of ids.
TABLE
id1 id2
1 1
1 2
1 3
2 1
2 6
2 2
3 1
3 10
3 3
I would like to SELECT every id1 that is matched to a certain combination of id2s.
For example, if I have id2 = [1, 2, 3] I would like to return id1 = [1];
If I have id2 = [1, 6] I woul...
Hello,
I have a problem when using foreign keys and primary keys in MySQL datable.
Now I have two tables p1,p2.
create table p1(
id int(10) not null auto_increment,
type_id int(10) default 1,
name varchar(20),
primary key(id, type_id)
);
create table p2(
id int(10) not null,
type_id int(10) not null,
...
The data in my dabatase comes from an external source and where ever there is no data passed, I keep NULL in those places. Can anyone tell me if there are any implications in using NULL to represent empty value?
Should I follow some other convention like 'data_not_available'? or something like that?
Can anyone suggest?
...
I have two tables that are linked in a 1:n relationship. I want to get the average(value) for all rows in a that have corresponding entries in b. However, if there are multiple rows in b for a row in a, these are obviously counted multiple times. How can I avoid this?
mysql> select * from a;
+----+-------+
| id | value |
+----+-------+
...
Hello,
I have cafeid=(1,2,3,4,5,6,7)
and checkid= (1,3,5)
How can I show the output only (2,4,6,7)?
Thank you for your answers.
...
Here's my code, I don't know why the checkbox isnt updated when I try to update the mysql database. Only the input box are being updated.
<tr>
<td><font size="3"></td>
<td></td>
<input type='hidden' name="stats6" value="0">
<td><input name="stats6" type="checkbox" id="dep" value="<?php echo $row["STAT6"]; ?>" <?php echo $row["STAT6"]...
Why can't the data in mysql not updated when I use checkbox, I already tried removing the input type hidden, but still didn't work. I think the problem must be in this part, because when I try to add records and check all of the checkboxes.
Then I will try to update it. By removing the checks in the other entry. The data is updated. the...
check the database-generating sql (looks fine):
CREATE TABLE `HourOfDay` (
`id` int(11) NOT NULL,
`hourString` varchar(2) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
check the file system (it's there):
# ls -al Mycomp_test | grep -i hour
-rw-rw---- 1 _mysql wheel 0 Mar 1 08:13 HourOfDay.MYD
-r...
I am using mysql and there are bulk inserts that goes on to my table.
My doubt is if I create a trigger specifying after insert, then the trigger will get activated for every insert after, which I do not want to happen.
Is there any way to activate a trigger after all the bulk inserts are completed?
Any advice?
Thanks.
...
I'm creating a timesheet application. I have the following entities (amongst others):
Company
Employee = an employee associated with a company
Client = a client associated with a company
So far I have the following (abbreviated) database setup:
Company
- id
- name
Employee
- id
- companyId (FK to Company.id)
- name
Clie...
I have a delete form wherein the user will enter the pnum to be deleted and then it will delete the corresponding record. But I want the user to atleast see what would be deleted so I tried this code, but it doesnt seem to work:
<?php
$con = mysql_connect("localhost","root","nitoryolai123$%^");
if (!$con)
{
die('Could not conne...