Jump to content

Recommended Posts

Let's say there are 100 fields within a table and, instead of manually using $variable = $row['fieldname']; to assign each one, I'd like to dynamically take all of the results and create variables with the same field name.  For example, I have this:

 

$id = $_GET['id'];
$query = "SELECT * FROM table1 WHERE ID=$id";
$result = mysql_query($query);
while($row = mysql_fetch_assoc($result)) {
    $fname = $row['FNAME'];
    $lname = $row['LNAME'];
    $moddate = $row['MODDATE'];
}

 

except that it's a lot longer.  As you can see, I'm naming the variables as the lowercase equivalents of their field name within the table.  I'm sure there's an easy way to have it go through each field and assign the value to a variable, I just don't know what it is.  I would assume that, since I'm making the variables lowercase, it would be something like:

 

$strtolower($row['FNAME']) = $row['FNAME'];

 

but that doesn't work.  Suggestions?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.