product(id, manufactured_id, name)
manufactured (id, name)
SELECT *
FROM manufactured
LEFT JOIN product ON product.manufactured_id = manufactured.id
WHERE product.id IS NULL
SELECT *
FROM manufactured
LEFT JOIN product ON product.manufactured_id = manufactured.manufactured_id
WHERE product.product_id IS NULL
<form ...>
<div ...><input name="values[]" ...></div>
</form>
<form ...>
<div ...><input name="values[]" ...></div>
<div ...><input name="values[]" ...></div>
</form>
<?php
//скрипт в который происходит submit
...
$values = implode(";", $_POST["values"]);
//сохранить в базу строку $values
?>
//скрипт отображения form-ы
<form ...>
<?php
//достать $values из базы
$arr = explode(";", $values);
for ($arr as $value)
{
echo "<div><input name=\"values[]\" value=\"$value\" /></div>";
}
?>
<imput type="submit" />
</form>
var_dump(number_format(microtime(true), 6));
time_nanosleep(0, 10 * 1000 * 1000);
echo "<br />";
var_dump(number_format(microtime(true), 6));
вывел следующее:string(20) "1,396,895,032.113305"
string(20) "1,396,895,032.123673"
$lastTime = microtime(true);
for($i = 1; $i <= 1000; $i ++){
while (true)
{
$new_last = microtime(true);
if ($new_last - $lastTime > 0.010)
{
$lastTime = $new_last;
break;
}
}
/*
* какой-то код
*/
}
TABLE POST {id, text}
TABLE CATEGORY {id, name}
TABLE CATEGORY_POST {id, category_id, post_id}
SELECT POST.id, POST.text, GROUP_CONCAT(CATEGORY.name SEPARATOR ', ') AS categories FROM POST
JOIN CATEGORY_POST ON (POST.id = CATEGORY_POST.post_id)
JOIN CATEGORY ON (CATEGORY.id = CATEGORY_POST.category_id)
GROUP BY POST.id, POST.text
- (IBAction)login:(UIButton *)sender {
sender.enabled = NO;
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
NSDictionary *parameters = @{@"_login": @"bar", @"_pass" : @"123"};
[manager POST:@"http://example.com/resources.json" parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"JSON: %@", responseObject);
sender.enabled = YES;
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
sender.enabled = YES;
}];
}
select * from mails where name = "name";
илиselect * from mails where name = 'name';
mysql_query("SELECT * FROM mails WHERE name='$template'");
function getLabel($count)
{
if ($count == 0)
return "Нет собак";
if ($count == 1)
return "Одна собака";
if ($count % 100 > 10 && $count % 100 < 20)
return $count . " собак";
switch ($count % 10)
{
case 0: return $count . " собак";
case 1: return $count . " собака";
case 2: return $count . " собаки";
case 3: return $count . " собаки";
case 4: return $count . " собаки";
case 5: return $count . " собак";
case 6: return $count . " собак";
case 7: return $count . " собак";
case 8: return $count . " собак";
case 9: return $count . " собак";
}
}
$objects = array(array('lon' => 1, 'lat' => 2), ..., ...);
$cluster = array();
$levels = 10;
$firstRectWidth = 0.01; //самый маленький "квадрат" будет 1111 на 1111
for ($i = 0; $i < count($objects); $i++)
{
$obj = $objects[$i];
for ($level = 1; $level <= $levels; $level++)
{
$lon_index = ($obj->lon) / ($firstRectWidth * (2 ^ $level)); // не помню как степень в php
$lat_index = ($obj->lat) / ($firstRectWidth * (2 ^ $level)); // не помню как степень в php
$cluster[$level][$lon_index . "-" . $lat_index][] = $i;
}
}
// использование
$zoom = 1..10;
echo "кластеров ".(count($cluster[$zoom]))."<br >";
foreach ($cluster[$zoom] as $key => $value)
{
echo "область ".$key."<br >";
echo "кол-во элеметнов ". (count($value));
}
0000000000000000000000000
псевдо код
bool write(f, char[2][2] data, start_x, start_y, width)
{
f_seek(f, start_y * width + start_x);
f_write(f, data[0]);
f_seek(f, (start_y + 1) * width + start_x);
f_write(f, data[1]);
return true;
}
char[2][2] read(f, start_x, start_y, width)
{
char[2][2] result;
f_seek(f, start_y * width + start_x);
result[0] = f_read(f, 2); // читаем два элемента
f_seek(f, (start_y + 1) * width + start_x);
result[1] = f_read(f, 2); // читаем два элемента
}
...
Customers *customers;
NSMutableDictionary *dictionaryCustomers;
NSArray *sortedKeys = nil;
...
for (NSDictionary *dictionary in [responseData objectForKey:@"data_list"]) {
customers = [[Customers alloc] init];
for (NSString *key in [dictionary allKeys]) {
if ([customers respondsToSelector:NSSelectorFromString(key)]) {
[customers setValue:[dictionary objectForKey:key] forKey:key];
}
}
//например по имени индексируем
NSString *fisrtSymbol = [[customers.name substringFromIndex:1] uppercaseString];
if ([dictionaryCustomers.allKeys containsObject:fisrtSymbol] == NO)
{
dictionaryCustomers[fisrtSymbol] = [NSMutableArray new];
}
[dictionaryCustomers[fisrtSymbol] addObject:customers];
}
sortedKeys = [dictionaryCustomers.allKeys sortedArrayUsingComparator:^NSComparisonResult(NSString *obj1, NSString *obj2) {
return [obj1 compare:obj2];
}]
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return dictionaryCustomers.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [dictionaryCustomers[sortedKeys[section]] count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
Customers *c = [dictionaryCustomers[sortedKeys[indexPath.section]] obkectAtIndex:indexPath.row];
...
return cell;
}
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
{
return sortedKeys;
}
@interface MyViewController ()
@property NSMutableDictionary *dictionaryCustomers; // исходные которые были заполненны из responseData
@property NSArray *sortedKeys; // исходные которые были заполненны из responseData
@property NSDictionary *currentDictionaryCustomers;
@property NSArray *currentSortedKeys;
@end
@implemented MyViewController
- (void)parseResponse:(id)responseData
{
// парсим ответ
self.dictionaryCustomers = ...
self.sortedKeys = ...
self.currentDictionaryCustomers = self.dictionaryCustomers;
self.currentSortedKeys = self.sortedKeys;
}
- (void)filterCustomers:(NSString *)sFilter
{
NSMutableDictionary *result = [NSMutableDictionary new];
for (NSString *key in [self.dictionaryCustomers allKeys])
{
for (Customers *customer in self.dictionaryCustomers[key])
{
if (<customer.company содержит sFilter>)
{
if ([result.allKeys containsObject:key] == NO) result[key] = [NSmutableArray new];
[result[key] addObject:customer];
}
}
}
self.currentDictionaryCustomers = result;
self.currentSortedKeys = [result.allKeys sortedArrayUsingComparator:^NSComparisonResult(NSString *obj1, NSString *obj2) {
return [obj1 compare:obj2];
}]
[self.tableView reloadData];
}
// тут заполняем tableView из self.currentDictionaryCustomers и self.currentSortedKeys
@end
-(void)viewDidLoad
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(needChangeLabel:) name:@"WBCAddWaterViewControllerChangeLabelNotification" object:nil];
}
- (void)needChangeLabel:(NSNotification *)n
{
NSLog(@"%@", n.userInfo);
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"WBCAddWaterViewControllerChangeLabelNotification" object:nil];
}
NSDictionary *userInfo = @{@"key1" : @"value1", @"key2" : @"value2"};
[[NSNotificationCenter defaultCenter] postNotificationName:@"WBCAddWaterViewControllerChangeLabelNotification" object:nil userInfo:userInfo];
@interface MyViewController ()
@property (strong, nonatomic) SDReachability *reachability;
@end
@implementation MyViewController
//...
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self monitorReachability];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear];
[self stopMonitorReachability];
}
- (void)monitorReachability
{
self.reachability = [SDReachability reachabilityWithTarget:self action:@selector(reachabilityChanged:)];
}
- (void)stopMonitorReachability
{
self.reachability = nil;
}
- (void)reachabilityChanged:(SDReachability *)reachability
{
switch (reachability.reachabilityStatus)
{
case SDNotReachable:
{
NSLog(@"Connection lost");
UIAlertView* alert = [[UIAlertView alloc] initWithTitle:nil message:@"Connection lost" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alert show];
// тут делаеш с view всё что захочешь
break;
}
case SDReachableViaWiFi:
NSLog(@"Connected via WiFi");
break;
case SDReachableViaWWAN:
NSLog(@"Connected via WWAN");
break;
}
}
@end
@interface MyRootViewController ()
@property (strong, nonatomic) SDReachability *reachability;
@end
@implementation MyRootViewController
//...
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self monitorReachability];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear];
[self stopMonitorReachability];
}
- (void)monitorReachability
{
self.reachability = [SDReachability reachabilityWithTarget:self action:@selector(reachabilityChanged:)];
}
- (void)stopMonitorReachability
{
self.reachability = nil;
}
- (void)reachabilityChanged:(SDReachability *)reachability
{
switch (reachability.reachabilityStatus)
{
case SDNotReachable:
{
NSLog(@"Connection lost");
UIAlertView* alert = [[UIAlertView alloc] initWithTitle:nil message:@"Connection lost" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alert show];
[self.navigationController popToRootViewController]; // убираем все контроллеры из стека
// тут модифицируешь self.view - например добавляеш на неё label "Connection Lost"
break;
}
case SDReachableViaWiFi:
NSLog(@"Connected via WiFi");
break;
case SDReachableViaWWAN:
NSLog(@"Connected via WWAN");
break;
}
}
@end
<head>
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
...
<head>
<script>
$.post( "test.php", { name: "John", time: "2pm" } , function(data) {
//выполнится после запроса и в data будет лежать то, что выведет скрипт test.php в output
});
</script>
<script>
$.post( "test.php", 'key1=value1&key2=value2' , function(data) {
//выполнится после запроса и в data будет лежать то, что выведет скрипт test.php в output. в этом случае в php будет доступно $_POST['key1']
} );
</script>