Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
As a very humble and fresh monk I come here to seek some guidance on accomplishing the following: My current project aims to aid in ebookmanagement. It does a lookup in an SQLite database for e-books matching the search criteria. The next step is where I'm stuck right now. The results from the database search need to be returned to the program. An array seems the most obvious solution and while the results consist of a set of columns, it should be a multidimensional one where @results[0] 0-7 holds the first entry, @results1 0-7 the next one and so on. However, due to my poor skills on array's I am unable to put the results into such an array. For a start I tried to put the book's title into elementx 1 of the array but no luck.

$sth = $dbh->prepare("select author, title, language, format, filename +, fullpath, category, tags from ebooks where author like'%$searchauth +%' and title like'%$searchtitle%' and language='$searchlang' and form +at='$searchfmt' and category like'%$searchcategory%' and tags like'%$ +searchtags%' LIMIT 50;");<br/>
(Above is the working query, just for informational purposes.)
Below is my code which can certainly be improved. Please guide me!
$sth->execute(); $loopcount = 0; while ($row = $sth->fetchrow_arrayref()) { # print "@$row[0] @$row[1] @$row[2] @$row[3] \n"; print "File found: @$row[4] \n"; # print "Category: @$row[6] Tags: @$row[7]\n\n"; $author = @$row[0]; $title = @$row[1]; $results[$loopcount] [1] = (@$row[1]); THIS LINE IS NOT WORKING. $language = @$row[2]; $format = @$row[3]; $filename = @$row[4]; $fullpath = @$row[5]; $category = @$row[6]; $tags = @$row[7]; print "$loopcount $results[$loopcount] [1]"; $loopcount++; }
When removing the # from the lines containing the print statements, the output is what you would expect; i.e. results are being returned from the query. My problem is how to put them into the array. I do use 'strict' and the program returns no syntax errors. /emgi

In reply to multidimensional array's by emgi

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others imbibing at the Monastery: (7)
    As of 2014-07-28 09:56 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My favorite superfluous repetitious redundant duplicative phrase is:









      Results (195 votes), past polls