Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Returning data

by johngg (Canon)
on Apr 20, 2024 at 20:53 UTC ( [id://11158995]=note: print w/replies, xml ) Need Help??


in reply to Returning data

%output .= (

should perhaps be

%output = (

I haven't looked at the overall logic of what you are doing but that leaps out of the page!

Cheers,

JohnGG

Replies are listed 'Best First'.
Re^2: Returning data
by frank1 (Monk) on Apr 21, 2024 at 08:45 UTC

    this returns 1 row

    this returns {"items":"title","Jo0993"}

    this is the format i want

    ({ "items": [ { "title": "Valls" }, { "title": "AUT15605" }, { "title": "10UT15605" } ] })

    My Try on ur suggestion

    my $dbh = DBI->connect("DBI:mysql:$dbname:$host", $usr, $pwd, { RaiseError => 1, }) or die $DBI::errstr; my $sth = $dbh->prepare("SELECT titles FROM tbl_1"); $sth->execute(); my $Data = $sth->fetchall_arrayref(); my %output; foreach my $Data (@$Data) { my ($title) = @$Data; %output = ( 'items' => [("title" => "$title")] ); } my $encoded = encode_json \%output; print $Cgi->header( -type => 'application/json' ),$encoded;

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2025-11-16 13:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your view on AI coding assistants?





    Results (72 votes). Check out past polls.

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.