• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

Array to string conversion in php

 
Ranch Hand
Posts: 93
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello i have write a php code that retrieve data from a database and assign them to a variable
but i am getting this error
help me sort this out please


Notice: Array to string conversion in C:\xampp\htdocs\webpage\reviewvani.php on line 22

Notice: Array to string conversion in C:\xampp\htdocs\webpage\reviewvani.php on line 22

Notice: Array to string conversion in C:\xampp\htdocs\webpage\reviewvani.php on line 23

Notice: Array to string conversion in C:\xampp\htdocs\webpage\reviewvani.php on line 23

Notice: Array to string conversion in C:\xampp\htdocs\webpage\reviewvani.php on line 24

Notice: Array to string conversion in C:\xampp\htdocs\webpage\reviewvani.php on line 24

Notice: Array to string conversion in C:\xampp\htdocs\webpage\reviewvani.php on line 27

Notice: Array to string conversion in C:\xampp\htdocs\webpage\reviewvani.php on line 27

Notice: Array to string conversion in C:\xampp\htdocs\webpage\reviewvani.php on line 28

Notice: Array to string conversion in C:\xampp\htdocs\webpage\reviewvani.php on line 28

Notice: Array to string conversion in C:\xampp\htdocs\webpage\reviewvani.php on line 29

Notice: Array to string conversion in C:\xampp\htdocs\webpage\reviewvani.php on line 29
000successful

here is the php code:
 
Vani Sweety
Ranch Hand
Posts: 93
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
note that there is only one value for toyota 4 in both table
 
Saloon Keeper
Posts: 14010
315
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Each line, you are defining a new array, and then trying to string-concatenate it to the row, using the dot operator.

Example: $row.['post'] defines an array containing the string 'pos', and then you concatenate it to $row.

If you meant to access cells of the row instead, you should omit the dot.
 
Vani Sweety
Ranch Hand
Posts: 93
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
it works but the answer is being concatenated
if in table 1 i have values for total is 15  pos is 20  neg is 5
and in the second table i have values for total is 9  pos is 8  neg is 2

this is what is displaying:
143.512

how can i print each value in different line so that i can perform the average
 
Vani Sweety
Ranch Hand
Posts: 93
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have included the pre tag in php and it is working correctly
now i have to display it usung javascript
and it is not working

php code


code in javascript:
 
Stephan van Hulst
Saloon Keeper
Posts: 14010
315
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ItDoesntWorkIsUseless
 
Vani Sweety
Ranch Hand
Posts: 93
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
how can i alert the php variables $total, $positive, $negative in the javascript file?
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can use json_encode()

<?php
$arr = array('a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5);

echo json_encode($arr);
?>
Later just use json_decode() to decode the string from your DB. Anything else is useless, JSON keeps the array relationship intact for later usage!
 
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic