Jump to content

Displaying the results of a query


dorich

Recommended Posts

Background

I want to be able to UPDATE a priority field (currently set as enum with three values.). I'm a novice at using php and mysql so I found a script, shown below, to populate the form field. I set up a test page to test the script only and it worked perfectly.  The next step is to integrate the script into my existing php page.

My Question/Problem

I thought it would be a good learning experience to reverse engineer the script so that I knew exactly what was going on, as well as figure out how to integrate it into my existing page. As you can see the script uses explode on the array derived from the query.

To understand how the string was being processed I wanted to see the raw data of the the string. However, I can't see how to print the 'raw' data to the page so that I can see it and refer back to the explode function.

My question is how do I see the string.

Caveat I realize this isn't a problem solution type of question so perhaps its not appropriate to this forum but I'm hoping that someone can point me in the right direction so that I can educate myself on how to understand how this is working.

To be clear it is the string for processing that I'm trying to get at, not the values of the fields.

It would appear that this should be trivial but in spite of a lot of experiments and a few hours of searching the web I can't find  an answer.

 

Some of the novice things I've tried

print $result;    This prints out "Resource id #5"

print $row;        This prints out "Array"

 

I'd appreciate any pointers on how to see the original string.

 

The script I used is taken http://jadendreamer.wordpress.com/2011/03/16/php-tutorial-put-mysql-enum-values-into-drop-down-select-box/.

 

The script is:

$table_name = "your_table_name"
$column_name = "field_with_enum_options";

echo "<select name="$column_name">";
$result = mysql_query("SELECT COLUMN_TYPE FROM INFORMATION_SCHEMA.COLUMNS
    WHERE TABLE_NAME = '$table_name' AND COLUMN_NAME = '$column_name'")
or die (mysql_error());

$row = mysql_fetch_array($result);
$enumList = explode(",", str_replace("'", "", substr($row['COLUMN_TYPE'], 5, (strlen($row['COLUMN_TYPE'])-6))));

foreach($enumList as $value)
    echo "<option value=$value>$value</option>";

echo "</select>";

 

 

 

Thanks

Link to comment
Share on other sites

@jasonc

 

Thanks.

 

Looks like that produces the correct response.

I did a print_r on the array and produced the following:

Array ( [0] => enum('High','Medium','Low') [COLUMN_TYPE] => enum('High','Medium','Low') )

 

 

Thanks for the help.

Link to comment
Share on other sites

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.