array(2) {
[0]=>
object(stdClass)#21 (7) {
["id"]=>
string(1) "1"
["title"]=>
string(7) "cvxzcvd"
["con"]=>
string(10) "gvsdvgsdfg"
["is_important"]=>
string(1) "1"
["date"]=>
string(3) "123"
["image"]=>
string(2) "55"
["cat_id"]=>
string(1) "1"
}
[1]=>
object(stdClass)#22 (7) {
["id"]=>
string(1) "2"
["title"]=>
string(4) "fsdf"
["con"]=>
string(9) "dfdsfvfds"
["is_important"]=>
string(1) "1"
["date"]=>
string(4) "5145"
["image"]=>
string(7) "5454124"
["cat_id"]=>
string(1) "2"
}
}
I passed this array into a view
$this->load->view('home/index',$news_data);
but I wanna use the data separately.
I mean if I wanna use the second title
or the second data.
how can I express that in the view
thanks
You can go like this:-
$news_data[1]->title;
$news_data[1]->data;
Store the array into variable like
$news_data['arr'] = { } ;
,and in view file access it by $arr;
print_r($arr);
I got a joomla database with a field that has multiple image paths. I want to seperate those paths and read them using json_decode. But when I try my code the image source is empty (where I want the path to be shown)
How I get the data and use json_decode:
$content = "SELECT * FROM `snm_content` WHERE catid = 13";
$contentcon = $conn->query($content);
$contentcr = array();
while ($contentcr[] = $contentcon->fetch_array());
$image = json_decode($content['images'], true);
I got the following line inside a foreach:
<img src="'.$image['image_intro'].'" alt="" class="company_logo">
I don't get any output in the img src. Why is that?
This is how I start the foreach if this is relevant:
foreach($contentcr as $content)
{
Output of $contentcr:
" [6]=> string(1) "1" ["state"]=> string(1) "1" [7]=> string(2) "13" ["catid"]=> string(2) "13" [8]=> string(19) "2015-11-20 08:56:29" ["created"]=> string(19) "2015-11-20 08:56:29" [9]=> string(3) "361" ["created_by"]=> string(3) "361" [10]=> string(0) "" ["created_by_alias"]=> string(0) "" [11]=> string(19) "2015-11-30 11:00:10" ["modified"]=> string(19) "2015-11-30 11:00:10" [12]=> string(3) "361" ["modified_by"]=> string(3) "361" [13]=> string(3) "361" ["checked_out"]=> string(3) "361" [14]=> string(19) "2015-12-02 10:49:59" ["checked_out_time"]=> string(19) "2015-12-02 10:49:59" [15]=> string(19) "2015-11-20 08:56:29" ["publish_up"]=> string(19) "2015-11-20 08:56:29" [16]=> string(19) "0000-00-00 00:00:00" ["publish_down"]=> string(19) "0000-00-00 00:00:00" [17]=> string(209) "{"image_intro":"images\/mobieleairco\/Airco_blog.jpg","float_intro":"","image_intro_alt":"","image_intro_caption":"","image_fulltext":"","float_fulltext":"","image_fulltext_alt":"","image_fulltext_caption":""}" ["images"]=> string(209) "{"image_intro":"images\/mobieleairco\/Airco_blog.jpg","float_intro":"","image_intro_alt":"","image_intro_caption":"","image_fulltext":"","float_fulltext":"","image_fulltext_alt":"","image_fulltext_caption":""}" [18]=> string(121) "{"urla":false,"urlatext":"","targeta":"","urlb":false,"urlbtext":"","targetb":"","urlc":false,"urlctext":"","targetc":""}" ["urls"]=> string(121) "{"urla":false,"urlatext":"","targeta":"","urlb":false,"urlbtext":"","targetb":"","urlc":false,"urlctext":"","targetc":""}" [19]=> string(593) "{"show_title":"","link_titles":"","show_tags":"","show_intro":"","info_block_position":"","show_category":"","link_category":"","show_parent_category":"","link_parent_category":"","show_author":"","link_author":"","show_create_date":"","show_modify_date":"","show_publish_date":"","show_item_navigation":"","show_icons":"","show_print_icon":"","show_email_icon":"","show_vote":"","show_hits":"","show_noauth":"","urls_position":"","alternative_readmore":"","article_layout":"","show_publishing_options":"","show_article_options":"","show_urls_images_backend":"","show_urls_images_frontend":""}" ["attribs"]=> string(593) "{"show_title":"","link_titles":"","show_tags":"","show_intro":"","info_block_position":"","show_category":"","link_category":"","show_parent_category":"","link_parent_category":"","show_author":"","link_author":"","show_create_date":"","show_modify_date":"","show_publish_date":"","show_item_navigation":"","show_icons":"","show_print_icon":"","show_email_icon":"","show_vote":"","show_hits":"","show_noauth":"","urls_position":"","alternative_readmore":"","article_layout":"","show_publishing_options":"","show_article_options":"","show_urls_images_backend":"","show_urls_images_frontend":""}" [20]=> string(2) "14" ["version"]=> string(2) "14" [21]=> string(1) "3" ["ordering"]=> string(1) "3" [22]=> string(22) "€ 50 (vanaf 2 weken)" ["metakey"]=> string(22) "€ 50 (vanaf 2 weken)" [23]=> string(5) "Slang" ["metadesc"]=> string(5) "Slang" [24]=> string(1) "1" ["access"]=> string(1) "1" [25]=> string(1) "0" ["hits"]=> string(1) "0" [26]=> string(53) "{"robots":"","author":"","rights":"","xreference":""}" ["metadata"]=> string(53) "{"robots":"","author":"","rights":"","xreference":""}" [27]=> string(1) "0" ["featured"]=> string(1) "0" [28]=> string(1) "*" ["language"]=> string(1) "*" [29]=> string(0) "" ["xreference"]=> string(0) "" } [1]=> array(60) { [0]=> string(2) "10" ["id"]=> string(2) "10" [1]=> string(2) "69" ["asset_id"]=> string(2) "69" [2]=> string(16) "Aelia 12 (AL-12)" ["title"]=> string(16) "Aelia 12 (AL-12)" [3]=> string(14) "aelia-12-al-12" ["alias"]=> string(14) "aelia-12-al-12" [4]=> string(297) "
Your variable names where confusing matters, but the answer that you where calling json_decode on the sql string, not the row:
$sql = "SELECT * FROM `snm_content` WHERE catid = 13";
$result = $conn->query($content);
while ($row = $result->fetch_array()){
$image = json_decode($row['images'], true);
echo '<img src="'.$image['image_intro'].'" alt="" class="company_logo">';
}
First sorry for my English.
I have a weird problem using the php $_SESSION Object.
I spent 2 days without find the solution.
I am triying to save a multidimensional array that stores some post values.
I create an array with this values and then i create a multidimensional array containing this arrays.
Page 1 (setvalues in multi array ans save in session)-> GET -> Page 2 read the session.
My code Page 1:
First, save the post values into a object property and validate them.
public function validateData(){
$this->nombres=$_POST["nombre"];
$this->imp_nombres=$_POST["imp_nombre"];
$this->numeros=$_POST["numero"];
$this->imp_numeros=$_POST["imp_numero"];
$this->tallas=$_POST["talla"];
$this->cantidades=$_POST["cantidad"];
$this->productos=$_POST["products"];
$this->equipos=$_POST["equipo"];
if(WSI_Funtions::compareSizes($this->nombres,$this->imp_nombres,$this->numeros,$this->imp_numeros,$this->tallas,$this->cantidades,$this->productos,$this->equipos))
{
$this->isValidModel=true;
$this->saveProductsValues();
}
else{
$this->isValidModel=false;
$this->errorMessage="Los datos no son correctos. Los parametros no coinciden";
}
}
If data is ok, I save those values:
public function saveProductsValues()
{
$this->productsValues=array();
$this->productsValues["names"]=$this->nombres;
$this->productsValues["imp_nombres"]=$this->imp_nombres;
$this->productsValues["numeros"]=$this->numeros;
$this->productsValues["imp_numeros"]=$this->imp_numeros;
$this->productsValues["tallas"]=$this->tallas;
$this->productsValues["cantidades"]=$this->cantidades;
$this->productsValues["productos"]=$this->productos;
$this->productsValues["equipos"]=$this->equipos;
}
Then I save it in a session :
public function saveSessionValues()
{
$_SESSION['customer'] = $this->customerObject;
$_SESSION['productsValues'] =$this->productsValues;
echo var_dump($_SESSION['productsValues']);
}
The saveSessionValues echo print this:
array(8) { ["names"]=> array(12) { [0]=> string(0) "" [1]=> string(12) "ÁNGEL HDEZ." [2]=> string(11) "VUJASINOVIC" [3]=> string(4) "ABIA" [4]=> string(10) "MUTAKABBIR" [5]=> string(8) "PETROVIC" [6]=> string(5) "DOBOS" [7]=> string(4) "HOMS" [8]=> string(6) "CASTRO" [9]=> string(0) "" [10]=> string(0) "" [11]=> string(0) "" } ["imp_nombres"]=> array(12) { [0]=> string(0) "" [1]=> string(1) "1" [2]=> string(1) "1" [3]=> string(1) "1" [4]=> string(1) "1" [5]=> string(1) "1" [6]=> string(1) "1" [7]=> string(1) "1" [8]=> string(1) "1" [9]=> string(0) "" [10]=> string(0) "" [11]=> string(0) "" } ["numeros"]=> array(12) { [0]=> string(1) "7" [1]=> string(1) "8" [2]=> string(1) "9" [3]=> string(0) "" [4]=> string(2) "11" [5]=> string(2) "12" [6]=> string(2) "18" [7]=> string(2) "19" [8]=> string(2) "22" [9]=> string(1) "5" [10]=> string(2) "33" [11]=> string(0) "" } ["imp_numeros"]=> array(12) { [0]=> string(1) "1" [1]=> string(1) "1" [2]=> string(1) "1" [3]=> string(0) "" [4]=> string(1) "1" [5]=> string(1) "1" [6]=> string(1) "1" [7]=> string(1) "1" [8]=> string(1) "1" [9]=> string(1) "1" [10]=> string(1) "1" [11]=> string(0) "" } ["tallas"]=> array(12) { [0]=> string(4) "XXXL" [1]=> string(3) "XXL" [2]=> string(2) "XL" [3]=> string(3) "XXL" [4]=> string(3) "XXL" [5]=> string(3) "XXL" [6]=> string(4) "XXXL" [7]=> string(3) "XXL" [8]=> string(2) "XL" [9]=> string(4) "XXXL" [10]=> string(2) "XL" [11]=> string(3) "XXL" } ["cantidades"]=> array(12) { [0]=> string(1) "1" [1]=> string(1) "1" [2]=> string(1) "1" [3]=> string(1) "1" [4]=> string(3) "145" [5]=> string(1) "1" [6]=> string(1) "1" [7]=> string(1) "1" [8]=> string(1) "1" [9]=> string(1) "1" [10]=> string(1) "1" [11]=> string(1) "1" } ["productos"]=> array(12) { [0]=> string(3) "109" [1]=> string(3) "109" [2]=> string(3) "109" [3]=> string(3) "109" [4]=> string(3) "109" [5]=> string(3) "109" [6]=> string(3) "109" [7]=> string(3) "109" [8]=> string(3) "109" [9]=> string(3) "109" [10]=> string(3) "109" [11]=> string(3) "109" } ["equipos"]=> array(12) { [0]=> string(7) "LEB ORO" [1]=> string(7) "LEB ORO" [2]=> string(7) "LEB ORO" [3]=> string(7) "LEB ORO" [4]=> string(7) "LEB ORO" [5]=> string(7) "LEB ORO" [6]=> string(12) "ES TALLA 4XL" [7]=> string(7) "LEB ORO" [8]=> string(7) "LEB ORO" [9]=> string(12) "ES TALLA 4XL" [10]=> string(7) "LEB ORO" [11]=> string(7) "LEB ORO" } }
My code Page 2 (php tags ommitted):
if (!isset($_SESSION)) { session_start(); }
echo var_dump($_SESSION['productsValues']);
This echo print the next value:
array(8) { ["names"]=> NULL ["imp_nombres"]=> NULL ["numeros"]=> NULL ["imp_numeros"]=> NULL ["tallas"]=> NULL ["cantidades"]=> NULL ["productos"]=> NULL ["equipos"]=> NULL }
The first level array exists, because the subarrays keys are printed, but all the second level arrays are NULL..
Maybe is for use the $_POST value??
I had try to encode the values of the $_POST object, saving only a json string instead of saving a object with the same result, the first nodes in the JSON are the keys of the arrays but the values are "NULL"
Any help please??
Thanks!!
You are over writing the values. Try with -
$_SESSION['productsValues'][] = $this->productsValues;
I have the array like this:
} ["items":"Jcart":private]=> array(3) {
[0]=>
string(1) "3"
[1]=>
string(1) "2"
[2]=>
string(7) "ABC-123" }
How to get the "items" values in a php variable?
///////
Te complete object is:
object(Jcart)#1 (8) {
["config"]=>
array(12) {
["jcartPath"]=>
string(6) "jcart/"
["checkoutPath"]=>
string(12) "checkout.php"
["item"]=>
array(6) {
["id"]=>
string(10) "my-item-id"
["name"]=>
string(12) "my-item-name"
["price"]=>
string(13) "my-item-price"
["qty"]=>
string(11) "my-item-qty"
["url"]=>
string(11) "my-item-url"
["add"]=>
string(13) "my-add-button"
}
["paypal"]=>
array(5) {
["id"]=>
string(38) "seller_1282188508_biz#conceptlogic.com"
["https"]=>
bool(true)
["sandbox"]=>
bool(false)
["returnUrl"]=>
string(0) ""
["notifyUrl"]=>
string(0) ""
}
["currencyCode"]=>
string(3) "USD"
["csrfToken"]=>
bool(false)
["text"]=>
array(14) {
["cartTitle"]=>
string(13) "Shopping Cart"
["singleItem"]=>
string(4) "Item"
["multipleItems"]=>
string(5) "Items"
["subtotal"]=>
string(8) "Subtotal"
["update"]=>
string(6) "update"
["checkout"]=>
string(8) "checkout"
["checkoutPaypal"]=>
string(20) "Checkout with PayPal"
["removeLink"]=>
string(6) "remove"
["emptyButton"]=>
string(5) "empty"
["emptyMessage"]=>
string(19) "Your cart is empty!"
["itemAdded"]=>
string(11) "Item added!"
["priceError"]=>
string(21) "Invalid price format!"
["quantityError"]=>
string(38) "Item quantities must be whole numbers!"
["checkoutError"]=>
string(34) "Your order could not be processed!"
}
["button"]=>
array(4) {
["checkout"]=>
string(0) ""
["paypal"]=>
string(0) ""
["update"]=>
string(0) ""
["empty"]=>
string(0) ""
}
["tooltip"]=>
bool(true)
["decimalQtys"]=>
bool(false)
["decimalPlaces"]=>
int(1)
["priceFormat"]=>
array(3) {
["decimals"]=>
int(2)
["dec_point"]=>
string(1) "."
["thousands_sep"]=>
string(1) ","
}
}
["items":"Jcart":private]=>
array(2) {
[0]=>
string(1) "3"
[1]=>
string(1) "2"
}
["names":"Jcart":private]=>
array(2) {
[3]=>
string(12) "Hockey Stick"
[2]=>
string(13) "Baseball Mitt"
}
["prices":"Jcart":private]=>
array(2) {
[3]=>
string(5) "33.25"
[2]=>
string(5) "19.50"
}
["qtys":"Jcart":private]=>
array(2) {
[3]=>
string(1) "1"
[2]=>
string(2) "20"
}
["urls":"Jcart":private]=>
array(2) {
[3]=>
string(15) "http://bing.com"
[2]=>
string(16) "http://yahoo.com"
}
["subtotal":"Jcart":private]=>
float(423.25)
["itemCount":"Jcart":private]=>
int(21)
}
I just need the values in ["items":"Jcart":private]
I assume you got this by casting an object to an array. If that's the case, you shouldn't be doing that! The property is private because you're not supposed to access it directly because it's not a public API. The object should have a public method which you're supposed to call instead, that's the public API. Something like $foo->getItems() or such. Read the documentation and/or source code.
i'm using codeigniter for create a web site. and i need to take result from mysql table as
this
object(mysqli_result)#2 (5) { ["current_field"]=> int(0) ["field_count"]=> int(4) ["lengths"]=> NULL ["num_rows"]=> int(12) ["type"]=> int(0) }
but always i got as a result something efferent from this.
when i'm using result_object() in codeigniter i'm getting something like this
array(12) { [0]=> object(stdClass)#24 (4) { ["id"]=> string(1) "1" ["label"]=> string(15) "Web Development" ["link_url"]=> string(0) "" ["parent_id"]=> string(1) "0" } [1]=> object(stdClass)#25 (4) { ["id"]=> string(2) "10" ["label"]=> string(19) "Sales and Marketing" ["link_url"]=> string(0) "" ["parent_id"]=> string(1) "0" } [2]=> object(stdClass)#26 (4) { ["id"]=> string(1) "7" ["label"]=> string(18) "Design and Artwork" ["link_url"]=> string(0) "" ["parent_id"]=> string(1) "0" } [3]=> object(stdClass)#27 (4) { ["id"]=> string(1) "2" ["label"]=> string(16) "Content Creation" ["link_url"]=> string(0) "" ["parent_id"]=> string(1) "0" } [4]=> object(stdClass)#28 (4) { ["id"]=> string(1) "4" ["label"]=> string(19) "OSCommerce projects" ["link_url"]=> string(29) "/php_web_development_jobs.php" ["parent_id"]=> string(1) "1" } [5]=> object(stdClass)#29 (4) { ["id"]=> string(1) "3" ["label"]=> string(8) "PHP Jobs" ["link_url"]=> string(29) "/php_web_development_jobs.php" ["parent_id"]=> string(1) "1" } [6]=> object(stdClass)#30 (4) { ["id"]=> string(1) "5" ["label"]=> string(22) "Technical Writing Jobs" ["link_url"]=> string(29) "/php_web_development_jobs.php" ["parent_id"]=> string(1) "2" } [7]=> object(stdClass)#31 (4) { ["id"]=> string(1) "6" ["label"]=> string(13) "Forum Posting" ["link_url"]=> string(29) "/php_web_development_jobs.php" ["parent_id"]=> string(1) "2" } [8]=> object(stdClass)#32 (4) { ["id"]=> string(1) "8" ["label"]=> string(20) "Blog Design Projects" ["link_url"]=> string(29) "/php_web_development_jobs.php" ["parent_id"]=> string(1) "7" } [9]=> object(stdClass)#33 (4) { ["id"]=> string(1) "9" ["label"]=> string(24) "Freelance Website Design" ["link_url"]=> string(29) "/php_web_development_jobs.php" ["parent_id"]=> string(1) "7" } [10]=> object(stdClass)#34 (4) { ["id"]=> string(2) "11" ["label"]=> string(29) "Internet Marketing Consulting" ["link_url"]=> string(29) "/php_web_development_jobs.php" ["parent_id"]=> string(2) "10" } [11]=> object(stdClass)#35 (4) { ["id"]=> string(2) "12" ["label"]=> string(25) "Leads Generation Services" ["link_url"]=> string(29) "/php_web_development_jobs.php" ["parent_id"]=> string(2) "10" } }
$this->db->order_by('parent_id','id','ASC');
$query = $this->db->get('dyn_menu');
if ($query->num_rows() > 0) {
$data = $query->result_object();
return $data;
}
how can i get the result as i want?
try using just result(), like:
...
$data = $query->result();
return $data;
...
try this if single record you want, make $is_single = true
if($is_single)
return $query ->row_array();
else
return $query ->result_array();