Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^2: problem with returning all records

by frank1 (Scribe)
on Apr 16, 2024 at 13:42 UTC ( [id://11158893]=note: print w/replies, xml ) Need Help??


in reply to Re: problem with returning all records
in thread problem with returning all records

Can i have a solution for this

am getting results like this :

{"msg":"data "} {"msg":"data "} and so on.........

i want to return the whole data to single json like:

{"msg":" all data goes here"}
my $sth = $dbh->prepare("SELECT snd.name, snd.country, m.item, m.eqty, m.price, m.line, m.prodct FRO +M buys as m JOIN Busers as snd ON snd.id = m.buyer WHERE CASE WHEN (SELECT SUM(s +tatus = ?) FROM buys) > 0 THEN m.status = ? ELSE m.status = ? OR m. +status = ? OR m.status = ? END ORDER BY created ASC"); $sth->execute('sold', 'forsell', 'bugt', 'paid', 'inshop'); my $Data = $sth->fetchall_arrayref(); foreach my $Data (@$Data) { my ($name, $country, $item, $eqty, $price, $line, $prodct) = @$Dat +a; $html = "<tr> <td> <p>$name</p> <p> $eqty, $price, $line, </p> $prodct $country </td> </tr> "; my $json = encode_json( { msg => $html} ); print $q->header( -type => 'application/json' ),$json; }

Replies are listed 'Best First'.
Re^3: problem with returning all records
by marto (Cardinal) on Apr 16, 2024 at 15:37 UTC

      hippo example was hard for me to figure it out, according to what i want

        If you step over the code you've posted, you're still doing everything inside the foreach. It doesn't make sense to

        • Clobber $html rather than append to it.
        • Create a json object.
        • print a header and the encoded json. The new problem.

        for each query result. Use  $html .= rather than clobber it. Create json once outside the foreach then print the header and json content once.

        Again, it'd be a lot less painful for all concerned if you took the time to read and understand what has been written in replies and read & step thorough your own code since you don't seem to understand what you wrote.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11158893]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2024-05-21 17:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found