- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
$q = "SELECT product_id FROM jos_vm_product WHERE product_parent_id=$prodid";
$res = mysql_query($q);
if(!$res) die('Error 3: ' . mysql_error());
$td_str=' ';
$pos_atrribs=array();
$row=0;
$sort_by=0;
$subrows=0;
$show_cells=0;
while($pos=mysql_fetch_array($res))
{
$posid=$pos['product_id'];
$q1 = "SELECT attribute_value,attribute_name FROM jos_vm_product_attribute WHERE product_id=$posid ORDER BY attribute_name DESC";
$res1 = mysql_query($q1);
if(!$res1) die('Error 4: ' . mysql_error());
$col=0;
while($posattrib=mysql_fetch_array($res1))
{
if($posattrib['attribute_name']=='Код фитинга' || $posattrib['attribute_name']=='Код' || $posattrib['attribute_name']=='Кодфитинга' || $posattrib['attribute_name']=='Ordering code')
{
$sort_by=$posattrib['attribute_name'];
}
$pos_atrribs[$row][$posattrib['attribute_name']]=$posattrib['attribute_value'];
$col++;
}
$q1 = "SELECT product_in_stock FROM jos_vm_product WHERE product_id=$posid";
$res1 = mysql_query($q1);
if(!$res1) die('Error 4: ' . mysql_error());
$stock=mysql_fetch_array($res1);
$pos_atrribs[$row]['Склад']=$stock['product_in_stock'];
$q1 = "SELECT product_price FROM jos_vm_product_price WHERE product_id=$posid";
$res1 = mysql_query($q1);
if(!$res1) die('Error 4: ' . mysql_error());
$price=mysql_fetch_array($res1);
$pos_atrribs[$row]['Цена EUR']=$price['product_price'];
$pos_atrribs[$row]['posid']=$posid;
$row++;
}
function columnSort($sorted, $column) {
for ($i=0; $i < sizeof($sorted)-1; $i++)
{
for ($j=0; $j<sizeof($sorted)-1-$i; $j++)
if ($sorted[$j][$column] > $sorted[$j+1][$column])
{
$tmp = $sorted[$j];
$sorted[$j] = $sorted[$j+1];
$sorted[$j+1] = $tmp;
}
}
return $sorted;
}
$sorted = columnSort($pos_atrribs, $sort_by);
unset($pos_atrribs);
$new_attribs=array();
$num=0;
$matches=0;
for ($i=0; $i < sizeof($sorted); $i++)
{
if(substr($sorted[$i][$sort_by],-2)!='.1' && substr($sorted[$i][$sort_by],-2)!='.4')
{
$fs=(int)substr($sorted[$i][$sort_by],0,3);
$fe=(int)substr($sorted[$i][$sort_by],-3);
for ($j=0; $j<sizeof($sorted); $j++)
{
$ss=(int)substr($sorted[$j][$sort_by],0,3);
$se=(int)substr($sorted[$j][$sort_by],-3);
if ($fe==$se && $fs<$ss)
{
$new_attribs[$num]=array($sorted[$i],$sorted[$j]);
$num++;
$matches++;
}
}
}
}
Джомло проект, в ходе запросов(11-46 строки) получает 250+ запросов к БД, и время выполнения только этого куска 40+ секунд. Далее сортировка тоже не слабая.