Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Setting all fields in a hash to name/value from sql...

Posted on 2004-09-13
1
Medium Priority
?
190 Views
Last Modified: 2013-12-25
Hi there,

I am just moving code from one server to another, where my current code uses the following syntax to get all the variables returning from the sql output (saves defining each time)....

                while( $hash =  $sth->fetchrow_hashref() )
                          {
                                           foreach( keys %$hash ){
                             $$_ = $hash->{$_}
                                 }

However now the server uses the folowing syntax, and I am not sure how to convert the statement above to "catch all" the output ......

      while (%hash = $sth->fetchhash)
      {
            $pagetemplate=$hash{'pagetemplate'};
            $fulltitledisplay=$hash{'fulltitle'};
            $pageviews=$hash{'pageviews'};
      }

can someone help me out please!
0
Comment
Question by:dreamshockDesign
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 14

Accepted Solution

by:
tomaugerdotcom earned 200 total points
ID: 12044500
You're looking for:

while (%hash = $sth->fetchhash) {
  foreach (keys %hash) {
    $$_ = $hash{$_};
  }
}

The only difference here is that you're working with a hash and not a hash reference as in your first example.

Note that neither this nor your code above will work under strict, because you're creating variable variables on-the-fly as it were.

Hope this helps,

Tom
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial will discuss fancy secure registration forms, with AJAX technology support. In this article I assume you already know HTML and some JS. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you mig…
It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question