I am using the following code to find the data from database
echo $query = "select * from `oc_order` where `store_url`='' ORDER BY `order_id` DESC LIMIT 5";
$mysqlq = mysqli_query($connection,$query) or die(mysqli_error($connection));
$mysqlw = mysqli_fetch_array($mysqlq);
echo "<pre>";
print_r($mysqlw);
foreach($mysqlw as $mysqlw)
{
echo $mysqlw['telephone'];
}
?>
I am getting the following array
Array
(
[0] => 73
[order_id] => 73
[1] => 0
[invoice_no] => 0
[2] =>
[invoice_prefix] =>
[3] => 0
[store_id] => 0
[4] =>
[store_name] =>
[5] =>
[store_url] =>
[6] => 9
[customer_id] => 9
[7] => 1
[customer_group_id] => 1
[8] => T****
[firstname] => ****
[9] =>
[lastname] =>
[10] => ********
[email] => *******
[11] => *****
[telephone] => *****
[12] =>
[fax] =>
[13] => 364ce6e2003bb1404f34
[custom_field] => 364ce6e2003bb1404f34
[14] =>
[payment_firstname] =>
[15] =>
[payment_lastname] =>
[16] =>
[payment_company] =>
[17] =>
[payment_address_1] =>
[18] =>
[payment_address_2] =>
[19] =>
[payment_city] =>
[20] =>
[payment_postcode] =>
[21] =>
[payment_country] =>
[22] => 0
[payment_country_id] => 0
[23] =>
[payment_zone] =>
[24] => 0
[payment_zone_id] => 0
[25] =>
[payment_address_format] =>
[26] =>
[payment_custom_field] =>
[27] =>
[payment_method] =>
[28] =>
[payment_code] =>
[29] =>
[shipping_firstname] =>
[30] =>
[shipping_lastname] =>
[31] =>
[shipping_company] =>
[32] =>
[shipping_address_1] =>
[33] =>
[shipping_address_2] =>
[34] =>
[shipping_city] =>
[35] =>
[shipping_postcode] =>
[36] =>
[shipping_country] =>
[37] => 0
[shipping_country_id] => 0
[38] =>
[shipping_zone] =>
[39] => 0
[shipping_zone_id] => 0
[40] =>
[shipping_address_format] =>
[41] =>
[shipping_custom_field] =>
[42] =>
[shipping_method] =>
[43] =>
[shipping_code] =>
[44] => 1,19
[comment] => 1,19
[45] => 100.0000
[total] => 100.0000
[46] => 0
[order_status_id] => 0
[47] => 0
[affiliate_id] => 0
[48] => 0.0000
[commission] => 0.0000
[49] => 0
[marketing_id] => 0
[50] =>
[tracking] =>
[51] => 0
[language_id] => 0
[52] => 0
[currency_id] => 0
[53] => INR
[currency_code] => INR
[54] => 1.00000000
[currency_value] => 1.00000000
[55] =>
[ip] =>
[56] =>
[forwarded_ip] =>
[57] =>
[user_agent] =>
[58] =>
[accept_language] =>
[59] => 0000-00-00 00:00:00
[date_added] => 0000-00-00 00:00:00
[60] => 0000-00-00 00:00:00
[date_modified] => 0000-00-00 00:00:00
)
but when i am trying to print the value of echo $mysqlw['telephone']; it is throwing warning Warning: Illegal string offset 'telephone' in
What mistake I am making in this code ?
You are trying to do a foreach on the array that you've displayed in your post. That means you're cycling through each item in the array. By trying to access $mysqlw['telephone'] you're expecting the item in the array to be another array containing the key 'telephone'.
I believe you're intending to do this:
while ($mysqlw = mysqli_fetch_array($mysqlq) {
echo $mysqlw['telephone'];
}
But also, you really should read up on how to do MySQL in a more modern style. Using things like mysqli_query in the manner you've used it here can open you up to injection attacks when you start having user input involved in the query.
Note your foreach statement has same variable name on both sides of 'as'
foreach($mysqlw as $mysqlw)
If you want to loop and access each value of an array do this instead:
foreach($mysqlw as $value)
{
echo $value;
}
Related
Here is an array that I want to sort. This is taken by an HTML table that is already stored in the database. But here it has 50 indexes. That's the thing I want to reduce to seven.
(
[0] => Array
(
[0] =>
[1] => data
[2] => data
[3] => data
[4] => data
[5] =>
[6] =>
[7] =>
[8] =>
[9] =>
[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] =>
)
[1] => Array
(
[0] =>
[1] =>
[2] =>
[3] =>
[4] =>
[5] =>
[6] =>
[7] =>
[8] =>
[9] =>
[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] =>
)
[2] => Array
(
[0] => 1
[1] => data
[2] => data
[3] => data
[4] => data
[5] => data
[6] =>
[7] =>
[8] =>
[9] =>
[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] =>
)
[3] => Array
(
[0] => 2
[1] => data
[2] => data
[3] => data
[4] => data
[5] => data
[6] =>
[7] =>
[8] =>
[9] =>
[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] =>
)
[4] => Array
(
[0] => 3
[1] => data
[2] => data
[3] => data
[4] => data
[5] => data
[6] =>
[7] =>
[8] =>
[9] =>
[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] =>
)
[5] => Array
(
[0] => 4
[1] => data
[2] => data
[3] => data
[4] => data
[5] => data
[6] =>
[7] =>
[8] =>
[9] =>
[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] =>
)
[6] => Array
(
[0] => 5
[1] => data
[2] => data
[3] => data
[4] => data
[5] => data
[6] =>
[7] =>
[8] =>
[9] =>
[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] =>
)
[7] => Array
(
[0] => 6
[1] => data
[2] => data
[3] => data
[4] => data
[5] => data
[6] =>
[7] =>
[8] =>
[9] =>
[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] =>
)
[8] => Array
(
[0] => 7
[1] => data
[2] => data
[3] => data
[4] => data
[5] => data
[6] =>
[7] =>
[8] =>
[9] =>
[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] =>
)
[9] => Array
(
[0] => 8
[1] => data
[2] => data
[3] => data
[4] => data
[5] => data
[6] =>
[7] =>
[8] =>
[9] =>
[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] =>
)
[10] => Array
(
[0] => 9
[1] => data
[2] => data
[3] => data
[4] => data
[5] => data
[6] =>
[7] =>
[8] =>
[9] =>
[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] =>
)
)
I tried with for loops, foreach loops to sort this array shows up to 7 indexes. It should be like this.
(
[0] => Array
(
[0] =>
[1] => data
[2] => data
[3] => data
[4] => data
[5] =>
[6] =>
[7] =>
)
[1] => Array
(
[0] =>
[1] =>
[2] =>
[3] =>
[4] =>
[5] =>
[6] =>
[7] =>
)
[2] => Array
(
[0] => 1
[1] => data
[2] => data
[3] => data
[4] => data
[5] => data
[6] =>
[7] =>
)
[3] => Array
(
[0] => 2
[1] => data
[2] => data
[3] => data
[4] => data
[5] => data
[6] =>
[7] =>
)
[4] => Array
(
[0] => 3
[1] => data
[2] => data
[3] => data
[4] => data
[5] => data
[6] =>
[7] =>
)
[5] => Array
(
[0] => 4
[1] => data
[2] => data
[3] => data
[4] => data
[5] => data
[6] =>
[7] =>
)
[6] => Array
(
[0] => 5
[1] => data
[2] => data
[3] => data
[4] => data
[5] => data
[6] =>
[7] =>
)
[7] => Array
(
[0] => 6
[1] => data
[2] => data
[3] => data
[4] => data
[5] => data
[6] =>
[7] =>
)
[8] => Array
(
[0] => 7
[1] => data
[2] => data
[3] => data
[4] => data
[5] => data
[6] =>
[7] =>
)
[9] => Array
(
[0] => 8
[1] => data
[2] => data
[3] => data
[4] => data
[5] => data
[6] =>
[7] =>
)
[10] => Array
(
[0] => 9
[1] => data
[2] => data
[3] => data
[4] => data
[5] => data
[6] =>
[7] =>
)
)
What did I try is,
for ($row = 0; $row <= sizeof($arr); $row++) {
for ($col = 0; $col < 7; $col++) {
$aar[] = $arr[$row][$col];
}
}
This method wasn't worked. What is the way or any suggestions on this?
If you just want to keep x amount of elements from each sub-array, you can use array_slice():
$newArray = [];
foreach($arr as $sub) {
// The example array you say you want have 8 elements, indexes 0-7
// so start with index 0 and take 8
$newArray[] = array_slice($sub, 0, 8);
}
Here's a demo: https://3v4l.org/WhFm4
Here is the one possible solution to your problem. Just define the key limit in if condition. Hope it will solve your problem.
$row = [
[
'',
'data',
'data',
'data',
'',
'',
'',
''
],
[
'',
'data',
'data',
'data',
'',
'',
'',
''
]
];
$reducedArray = [];
foreach ($row as $col) {
$tempArray = [];
foreach ($col as $innnerKey => $innerValue) {
// Define your index limit here.
// As you can see I have set the limit to 7
if ($innnerKey <= 7) {
$tempArray[] = $innerValue;
}
}
$reducedArray[] = $tempArray;
}
echo '<pre>';
print_r($row);
echo '</pre>';
echo '<br/>';
echo '<pre>';
print_r($reducedArray);
echo '</pre>';
I have an array like this -
Array ( [0] => একটু [1] => আরো [2] => নয় [3] => কাছে [4] => থাকো [5] => না [6] => কাছে [7] => ডাকো [8] => না [9] => আরো [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] => ডাকো [87] => না [88] => আরো [89] => কাছে [90] => তুমি [91] => আমার [92] => আমি [93] => তোমার [94] => )
When i am counting the same values using the following code it is giving wrong results like below -
$wordCountArr = array_count_values($matchWords);
Array ( [একটু] => 1 [আরো] => 6 [নয়] => 3 [কাছে] => 6 [থাকো] => 3 [না]
=> 6 [ কাছে] => 3 [ডাকো] => 3 [ আজ] => 1 [দুজনের] => 1 [প্রথম] => 1 [মিলনের] => 1 [ চাঁদ] => 1 [তারা] => 1 [ঐ] => 3 [সাক্ষী] => 1 [আছে] =>
1 [ তুমি] => 2 [আমার] => 5 [আমি] => 2 [তোমার] => 5 [] => 3 [ মন] => 1
[যে] => 3 [ভরেছে] => 2 [জোছনা] => 2 [ঝরেছে] => 2 [ পৃথিবী] => 2
[দ্যাখো] => 2 [ঘুমিয়ে] => 2 [পড়েছে] => 2 [ মন] => 1 [ আমি] => 3 [তুমি]
=> 3 [ একটু] => 2 [ ফুলেরই] => 1 [হাসিতে] => 1 [হাওয়ার] => 1 [বাঁশিতে] => 1 [ এ] => 1 [রাত] => 1 [শেখালো] => 1 [ভালো] => 1 [বাসিতে] => 1 )
But why [কাছে] => 6 and [ কাছে] => 3 ??? It suppose to be [কাছে] => 9
Now should i trim the spaces before and after or match words with spaces ? I used array_map('trim',$matchWords) but no luck!
How can i fix this? Please HELP !
Yes the matching is separate for those because of the space. trim() to remove spaces for each word wouldn't work for your case as it doesn't remove unicode white spaces.
So your solution use: preg_replace.
Refer:
Trim unicode whitespace
why is php trim is not really remove all whitespace and line breaks?
I have a single dimentional PHP Array that has latitude, longitude, and time data. The data goes eg [lat, long, date, lat, long, date, lat, long, date.... etc etc]
Array ( [0] => -28.0447606 [1] => 153.4340961 [2] => 1424136836118 [3] => -28.0447612 [4] => 153.4340963 [5] => 1424136876189 [6] => -28.0447658 [7] => 153.4340962 [8] => 1424136897993 [9] => -28.0447619 [10] => 153.4340615 [11] => 1424136918045 [12] => -28.0447656 [13] => 153.434057 [14] => 1424136938057 [15] => -28.0447613 [16] => 153.4340484 [17] => 1424136958085 [18] => -28.0447791 [19] => 153.4340959 [20] => 1424136978117 [21] => -28.0447584 [22] => 153.4340501 [23] => 1424136998135 [24] => -28.0447676 [25] => 153.434047 [26] => 1424137018179 [27] => -28.044782 [28] => 153.4340982 [29] => 1424137038185 [30] => -28.0447599 [31] => 153.4340496 [32] => 1424137058214 [33] => -28.0447614 [34] => 153.4340531 [35] => 1424137078589 [36] => -28.0447588 [37] => 153.4340963 [38] => 1424137098731 [39] => -28.0447768 [40] => 153.434098 [41] => 1424137138640 [42] => -28.0447141 [43] => 153.4341097 [44] => 1424137158672 [45] => -28.0447628 [46] => 153.4340962 [47] => 1424137178698 [48] => -28.0447622 [49] => 153.4340962 [50] => 1424137198726 [51] => -28.0447528 [52] => 153.4340936 [53] => 1424137218871 [54] => -28.0447636 [55] => 153.4340472 [56] => 1424137258825 [57] => -28.0447608 [58] => 153.434097 [59] => 1424137279945 [60] => -28.0447656 [61] => 153.4340979 [62] => 1424137300018 )
I am just wondering if there is an easy way to convert this into a two dimensional array so I can access them like $gps[0][1] or $gps[3][0] etc. I've tried a few ways like using a for loop, but surely there's some other way I'm overlooking.
If I'm not wrong this is what you want.
You just need to change the $arr for your variable.
$coords = array_map(function($coords) {
return array(
"lat" => $coords[0], # latitude
"long" => $coords[1], # longitude
"ts" => $coords[2] # timestamp
);
}, array_chunk($arr, 3));
/*
Array (
Array (
[lat] => 12
[long] => 34
[ts] => 56
)
Array (
[lat] => 12
[long] => 34
[ts] => 56
)
... and so on
)
*/
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Does anyone know what is conditional statement to detect a category id?
I need something like this:
If product is in category ID = 64 show some HTML
print_r($this->category);
TableCategories Object ( [virtuemart_category_id] => 16 [virtuemart_vendor_id] => 1 [category_name] => Chiloți, boxeri, indispensabili [slug] => chiloti-boxeri-indispensabili [category_description] => [category_template] => default [category_layout] => 0 [category_product_layout] => 0 [products_per_row] => 0 [ordering] => 3 [shared] => 0 [limit_list_step] => 0 [limit_list_initial] => 0 [metadesc] => [customtitle] => [metakey] => [metarobot] => [metaauthor] => [published] => 1 [_pkey:protected] => virtuemart_category_id [_pkeyForm:protected] => [_obkeys:protected] => Array ( [category_name] => Category in record is missing ! Can't save the record with no Category. [slug] => The given Sef Alias already exists. ) [_unique:protected] => 1 [_unique_name:protected] => Array ( [slug] => The given Sef Alias already exists. ) [_orderingKey:protected] => ordering [_slugAutoName:protected] => category_name [_slugName:protected] => slug [_loggable:protected] => 1 [_xParams:protected] => 0 [_varsToPushParam:protected] => Array ( ) [_translatable] => 1 [_translatableFields:protected] => Array ( [0] => category_name [1] => category_description [2] => metadesc [3] => metakey [4] => customtitle [slug] => slug ) [_langTag:protected] => en_gb [_tbl_lang:protected] => #__virtuemart_categories_en_gb [_updateNulls:protected] => [_tablePreFix] => c. [_tbl:protected] => #__virtuemart_categories [_tbl_key:protected] => virtuemart_category_id [_db:protected] => JFDatabase Object ( [mlTableList] => Array ( [0] => content [1] => modules [2] => menu ) [skipSetRefTables] => [orig_limit] => 0 [orig_offset] => 0 [skipjf] => 0 [translate] => 1 [tableFields:JFDatabase:private] => [profileData] => Array ( [JFDatabase::JFDatabase] => Array ( [total] => 0.0002288818359375 [count] => 1 [start] => Array ( ) ) [interceptDB::loadObjectList] => Array ( [total] => 0.0227241516113281 [count] => 62 [start] => Array ( [0] => 1397209811.22307 [1] => 1397209811.22406 [2] => 1397209811.22585 [3] => 1397209811.22628 [4] => 1397209811.23031 [5] => 1397209811.23254 [6] => 1397209811.24075 [7] => 1397209811.24117 [8] => 1397209811.24466 [9] => 1397209811.24608 [10] => 1397209811.27806 [11] => 1397209811.28038 [12] => 1397209811.28142 [13] => 1397209811.28238 [14] => 1397209811.28439 [15] => 1397209811.28616 [16] => 1397209811.28671 [17] => 1397209811.28773 [18] => 1397209811.28882 [19] => 1397209811.28975 [20] => 1397209811.29121 [21] => 1397209811.29171 [22] => 1397209811.29234 [23] => 1397209811.29328 [24] => 1397209811.29369 [25] => 1397209811.29412 [26] => 1397209811.2953 [27] => 1397209811.29915 [28] => 1397209811.29965 [29] => 1397209811.30009 [30] => 1397209811.30052 [31] => 1397209811.30295 [32] => 1397209811.304 [33] => 1397209811.30527 [34] => 1397209811.3057 [35] => 1397209811.30631 [36] => 1397209811.3067 [37] => 1397209811.30721 [38] => 1397209811.3123 [39] => 1397209811.32571 [40] => 1397209811.32638 [41] => 1397209811.32792 [42] => 1397209811.32891 [43] => 1397209811.32985 [44] => 1397209811.3308 [45] => 1397209811.33191 [46] => 1397209811.33233 [47] => 1397209811.333 [48] => 1397209811.33367 [49] => 1397209811.33744 [50] => 1397209811.33793 [51] => 1397209811.3384 [52] => 1397209811.33884 [53] => 1397209811.33928 [54] => 1397209811.34905 [55] => 1397209811.3519 [56] => 1397209811.35311 [57] => 1397209811.35398 [58] => 1397209811.35685 [59] => 1397209811.35732 ) ) [JFDatabase::getTableName] => Array ( [total] => 0.00406312942504883 [count] => 59 [start] => Array ( ) ) [JFDatabase::setLanguage] => Array ( [total] => 0.000144720077514648 [count] => 2 [start] => Array ( ) ) [JFDatabase::loadResult] => Array ( [total] => 0.000228643417358398 [count] => 13 [start] => Array ( ) ) [JFDatabase::loadAssoc] => Array ( [total] => 0.000162124633789062 [count] => 7 [start] => Array ( ) ) [JFDatabase::loadAssocList] => Array ( [total] => 0.000132083892822266 [count] => 4 [start] => Array ( ) ) [JFDatabase::loadResultArray] => Array ( [total] => 0.000250816345214844 [count] => 14 [start] => Array ( ) ) [JFDatabase::loadRow] => Array ( [total] => 0 [count] => 2 [start] => Array ( [0] => 1397209811.30335 [1] => 1397209811.30605 ) ) ) [name] => mysqli [nameQuote:protected] => ` [nullDate:protected] => 0000-00-00 00:00:00 [dbMinimum:protected] => 5.0.4 [_database:JDatabase:private] => 7624-magazin [connection:protected] => mysqli Object ( [affected_rows] => 0 [client_info] => mysqlnd 5.0.11-dev - 20120503 - $Id: bf9ad53b11c9a57efdb1057292d73b928b8c5c77 $ [client_version] => 50011 [connect_errno] => 0 [connect_error] => [errno] => 0 [error] => [error_list] => Array ( ) [field_count] => 1 [host_info] => ns13.host-md.net via TCP/IP [info] => [insert_id] => 0 [server_info] => 5.5.32-MariaDB-log [server_version] => 50532 [stat] => Uptime: 346321 Threads: 6 Questions: 164660555 Slow queries: 35 Opens: 1823800 Flush tables: 293 Open tables: 1024 Queries per second avg: 475.456 [sqlstate] => 00000 [protocol_version] => 10 [thread_id] => 2168966 [warning_count] => 0 ) [count:protected] => 0 [cursor:protected] => mysqli_result Object ( [current_field] => [field_count] => [lengths] => [num_rows] => [type] => ) [debug:protected] => [limit:protected] => 0 [log:protected] => Array ( ) [offset:protected] => 0 [sql:protected] => SELECT `virtuemart_vendor_id` FROM `#__virtuemart_vmusers` `au` WHERE `au`.`virtuemart_user_id`="687" AND `au`.`user_is_vendor` = "1" [tablePrefix:protected] => l50ti_ [utf:protected] => 1 [errorNum:protected] => 0 [errorMsg:protected] => [hasQuoted:protected] => [quoted:protected] => Array ( ) ) [_trackAssets:protected] => [_rules:protected] => [_locked:protected] => [_errors:protected] => Array ( ) [created_on] => 2014-03-16 21:10:24 [created_by] => 685 [modified_on] => 2014-04-08 13:29:22 [modified_by] => 685 [virtuemart_media_id] => Array ( ) [haschildren] => [children] => Array ( ) [productcount] => 6 [parents] => [images] => Array ( [0] => VmMediaHandler Object ( [media_attributes] => 0 [setRole] => [file_name] => [file_extension] => [virtuemart_media_id] => 0 [_foldersToTest:VmMediaHandler:private] => Array ( [0] => /var/www/vhosts/7624/domains/maicom.md/public_html/images/stories/virtuemart/category/ [1] => /var/www/vhosts/7624/domains/maicom.md/public_html/images/stories/virtuemart/category/resized/ ) [_actions:VmMediaHandler:private] => Array ( ) [_mLocation:VmMediaHandler:private] => Array ( ) [_hidden:VmMediaHandler:private] => Array ( ) [theme_url] => http://maicom.md/components/com_virtuemart/ [virtuemart_vendor_id] => 0 [file_title] => [file_description] => [file_meta] => [file_mimetype] => [file_type] => categories [file_url] => images/stories/virtuemart/category/ [file_url_thumb] => [published] => 0 [file_is_downloadable] => 0 [file_is_forSale] => 0 [file_is_product_image] => 0 [shared] => 0 [file_params] => 0 [file_lang] => [_translatable] => [_tablePreFix] => [created_on] => [created_by] => 0 [modified_on] => [modified_by] => 0 [file_url_folder] => images/stories/virtuemart/category/ [file_path_folder] => images/stories/virtuemart/category/ [file_url_folder_thumb] => images/stories/virtuemart/category/resized/ [media_role] => file_is_displayable ) ) [file_url_thumb] => [file_url] => images/stories/virtuemart/category/ ) </div>
What are you trying so far ?
did you need it in details page ?
if yes then try following method. I assume you are in any of the product details page layout.
if($this->product->virtuemart_category_id == 64){
echo 'your Custom HTML';
}
else{
//nothing
}
Also you need to get more details about current product just use.
echo "<pre/>";
print_r($this->product);
Hope its works..
sorry if that can be a simple question. I need to read the index value of an array. The code that I have and try to correct read only the index 0. I have try with a ciclebut continue to make mistakes.
<? if($entrata != ""){
$nome_condomino = getCondominoByIdEntrata($entrata[0]['id']);
$saldo += (float) $entrata[0]['importo_versato'];
//echo '<pre>' . print_r( $entrata,true ) . '</pre>';
?>
<tr class="gradeX">
<td class="center"><?echo $giorno;?></td>
<td class="center"><?echo $nome_condomino[0]['nome_cognome'];?></td>
<td class="center"><b><?echo "€ ".$entrata[0]['importo_versato'];?></b></td>
<td class="center"><?echo "€ ".$saldo;?></td>
<td class="center"><?echo $giorno_ok;?></td>
<td class="center"><?echo $entrata_id[0];?></td>
</tr>
<? } ?>
I need to show the other index value for the variables $nome_condominio and $entrata
That is print_r( $entrata,true )
Array
(
[0] => Array
(
[0] => 41
[id] => 41
[1] => 35
[id_condominio] => 35
[2] => 38
[id_condomino] => 38
[3] => 12
[importo_versato] => 12
[4] => 2013-11-30
[data] => 2013-11-30
[5] =>
[numero_ricevuta] =>
[6] =>
[allegato_ricevuta] =>
[7] => 0
[consumi_idrici_importo] => 0
[8] => 0000-00-00
[data2] => 0000-00-00
[9] =>
[allegato_consumi_idrici] =>
[10] => 0
[lavori_straordinari_importo] => 0
[11] => 0000-00-00
[data3] => 0000-00-00
[12] =>
[causale] =>
[13] =>
[causale_altro] =>
[14] => 10_2013
[causale_mese] => 10_2013
[15] => Ottobre 2013
[causale_mese_periodo_esteso] => Ottobre 2013
)
[1] => Array
(
[0] => 40
[id] => 40
[1] => 35
[id_condominio] => 35
[2] => 52
[id_condomino] => 52
[3] => 18.2
[importo_versato] => 18.2
[4] => 2013-11-30
[data] => 2013-11-30
[5] =>
[numero_ricevuta] =>
[6] =>
[allegato_ricevuta] =>
[7] => 0
[consumi_idrici_importo] => 0
[8] => 0000-00-00
[data2] => 0000-00-00
[9] =>
[allegato_consumi_idrici] =>
[10] => 0
[lavori_straordinari_importo] => 0
[11] => 0000-00-00
[data3] => 0000-00-00
[12] => 2
[causale] => 2
[13] =>
[causale_altro] =>
[14] =>
[causale_mese] =>
[15] =>
[causale_mese_periodo_esteso] =>
)
)
Array
(
[0] => Array
(
[0] => 39
[id] => 39
[1] => 35
[id_condominio] => 35
[2] => 34
[id_condomino] => 34
[3] => 12.5
[importo_versato] => 12.5
[4] => 2013-12-01
[data] => 2013-12-01
[5] =>
[numero_ricevuta] =>
[6] =>
[allegato_ricevuta] =>
[7] => 0
[consumi_idrici_importo] => 0
[8] => 0000-00-00
[data2] => 0000-00-00
[9] =>
[allegato_consumi_idrici] =>
[10] => 0
[lavori_straordinari_importo] => 0
[11] => 0000-00-00
[data3] => 0000-00-00
[12] => 2
[causale] => 2
[13] =>
[causale_altro] =>
[14] =>
[causale_mese] =>
[15] =>
[causale_mese_periodo_esteso] =>
)
[1] => Array
(
[0] => 44
[id] => 44
[1] => 35
[id_condominio] => 35
[2] => 51
[id_condomino] => 51
[3] => 10
[importo_versato] => 10
[4] => 2013-12-01
[data] => 2013-12-01
[5] =>
[numero_ricevuta] =>
[6] =>
[allegato_ricevuta] =>
[7] => 0
[consumi_idrici_importo] => 0
[8] => 0000-00-00
[data2] => 0000-00-00
[9] =>
[allegato_consumi_idrici] =>
[10] => 0
[lavori_straordinari_importo] => 0
[11] => 0000-00-00
[data3] => 0000-00-00
[12] => 2
[causale] => 2
[13] =>
[causale_altro] =>
[14] =>
[causale_mese] =>
[15] =>
[causale_mese_periodo_esteso] =>
)
)
Array
(
[0] => Array
(
[0] => 42
[id] => 42
[1] => 35
[id_condominio] => 35
[2] => 39
[id_condomino] => 39
[3] => 10
[importo_versato] => 10
[4] => 2013-12-03
[data] => 2013-12-03
[5] =>
[numero_ricevuta] =>
[6] =>
[allegato_ricevuta] =>
[7] => 0
[consumi_idrici_importo] => 0
[8] => 0000-00-00
[data2] => 0000-00-00
[9] =>
[allegato_consumi_idrici] =>
[10] => 0
[lavori_straordinari_importo] => 0
[11] => 0000-00-00
[data3] => 0000-00-00
[12] => 3
[causale] => 3
[13] =>
[causale_altro] =>
[14] =>
[causale_mese] =>
[15] =>
[causale_mese_periodo_esteso] =>
)
)
Array
(
[0] => Array
(
[0] => 43
[id] => 43
[1] => 35
[id_condominio] => 35
[2] => 38
[id_condomino] => 38
[3] => 9
[importo_versato] => 9
[4] => 2013-12-05
[data] => 2013-12-05
[5] =>
[numero_ricevuta] =>
[6] =>
[allegato_ricevuta] =>
[7] => 0
[consumi_idrici_importo] => 0
[8] => 0000-00-00
[data2] => 0000-00-00
[9] =>
[allegato_consumi_idrici] =>
[10] => 0
[lavori_straordinari_importo] => 0
[11] => 0000-00-00
[data3] => 0000-00-00
[12] => 2
[causale] => 2
[13] =>
[causale_altro] =>
[14] =>
[causale_mese] =>
[15] =>
[causale_mese_periodo_esteso] =>
)
)
the function:
function getCondominoByIdEntrata($idEntrata){
$sql1 = "SELECT * FROM entrate WHERE id = '".$idEntrata."'";
$r1 = executeQuery($sql1);
$id_condomino = $r1[0]['id_condomino'];
$sql2 = "SELECT * FROM anagrafe WHERE id = '".$id_condomino."'";
$r2 = executeQuery($sql2);
return $r2;
}
The print_r( $nome_condomino):
Array
(
[0] => Array
(
[0] => 38
[id] => 38
[1] => 35
[id_condominio] => 35
[2] => Carlo Vincenzo
[nome_cognome] => Carlo Vincenzo
[3] =>
[codice_fiscale] =>
[4] =>
[dati_catastali_foglio] =>
[5] =>
[dati_catastali_particella] =>
[6] =>
[dati_catastali_subalterno] =>
[7] =>
[dati_catastali_piano] =>
[8] =>
[recapito] =>
[9] => 2
[civico] => 2
[10] =>
[citta] =>
[11] => TA
[provincia] => TA
[12] =>
[telefono] =>
[13] =>
[cellulare] =>
[14] =>
[fax] =>
[15] =>
[email] =>
[16] =>
[pec] =>
[17] => si
[occupante_uguale_titolare] => si
[18] =>
[occupante] =>
[19] =>
[occupante_rapporto] =>
[20] =>
[occupante_telefono] =>
[21] =>
[occupante_cellulare] =>
[22] =>
[occupante_email] =>
[23] =>
[occupante_pec] =>
[24] =>
[nome_utente] =>
)
)
Array
(
[0] => Array
(
[0] => 52
[id] => 52
[1] => 35
[id_condominio] => 35
[2] => Mario Giancarlo
[nome_cognome] => Mario Giancarlo
[3] =>
[codice_fiscale] =>
[4] =>
[dati_catastali_foglio] =>
[5] =>
[dati_catastali_particella] =>
[6] =>
[dati_catastali_subalterno] =>
[7] =>
[dati_catastali_piano] =>
[8] => Via Rossi
[recapito] => Via Rossi
[9] => 5
[civico] => 5
[10] =>
[citta] =>
[11] =>
[provincia] =>
[12] =>
[telefono] =>
[13] =>
[cellulare] =>
[14] =>
[fax] =>
[15] =>
[email] =>
[16] =>
[pec] =>
[17] => si
[occupante_uguale_titolare] => si
[18] =>
[occupante] =>
[19] =>
[occupante_rapporto] =>
[20] =>
[occupante_telefono] =>
[21] =>
[occupante_cellulare] =>
[22] =>
[occupante_email] =>
[23] =>
[occupante_pec] =>
[24] =>
[nome_utente] =>
)
)
You want foreach statement to get all data from array $entrata & $nome_condominio. Something like this maybe work:
UPDATED:
<?php if($entrata != ""){
//echo '<pre>' . print_r( $entrata,true ) . '</pre>';
$i = 0;
foreach($entrata as $entr){
$nome_condomino = getCondominoByIdEntrata($entr['id']);
$saldo += (float) $entr['importo_versato'];
?>
<tr class="gradeX">
<td class="center"><?echo $giorno;?></td>
<td class="center"><?echo $nome_condomino['nome_cognome'];?></td>
<td class="center"><b><?echo "€ ".$entr['importo_versato'];?></b></td>
<td class="center"><?echo "€ ".$saldo;?></td>
<td class="center"><?echo $giorno_ok;?></td>
<td class="center"><?echo $entr['id'];?></td>
</tr>
<?php
$i++;
} ?>
<? } ?>
Seems like $entrata isn't an array or is empty? Try changing
if ($entrata != '') {
to
if (!empty($entrata) && is_array($entrata)) {
will ensure that you're getting a non empty array