Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    Master Coder
    Join Date
    Apr 2003
    in my house
    Thanked 201 Times in 197 Posts

    fetchrow_hashref question


    Having queried my db and running the loop as shown below, I am confused about why data isn't seemingly accessible in the way it would be stored in a hash.

    when I want to output a 'key' and beside it, all its 'values', I get the 'key' outputting each time a value is outputted, like this.

    double 2010-01-01 - 2010-03-31
    double 2010-04-01 - 2010-09-30
    when it should be (I want it to be),

    double 2010-01-01 - 2010-03-31
    2010-04-01 - 2010-09-30
    This is how I get the data from the query and I thought by getting a hashref, it would work as described.
    while ( $file_data = $sth->fetchrow_hashref)  {
      my $product_name = $file_data->{product_name};
      my $room_type = $file_data->{room_type};
      my $start_date = $file_data->{start_date};
      my $end_date=$file_data->{end_date};
      my $currency = $file_data->{currency};
      my $tariff = $file_data->{tariff};
    But I wonder if I should get it in a fetchrow_array and then build a hash for processing. And if this (above), is the correct way to get the data, why do I then need to build the hash?

    What am I not making sense of?

    Dumper shows me the hashref output so should I make a hash of the hashes like this?

    or am I doing something in perl, which mysql/DBI can do better?

    Last edited by bazz; 12-08-2009 at 10:16 PM.
    "The day you stop learning is the day you become obsolete"! - my late Dad.

    Why do some people say "I don't know for sure"? If they don't know for sure then, they don't know!
    Useful MySQL resource
    Useful MySQL link


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts