Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8476359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T18:09:23+00:00 2026-06-10T18:09:23+00:00

PHP $table = $_REQUEST[‘table’]; $query = SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.Columns where TABLE_NAME = $table;

  • 0

PHP

$table = $_REQUEST['table'];

$query  = "SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.Columns where TABLE_NAME = $table";
$result = mysql_query($query);
$i = 0;
$arr = array();
while($row = mysql_fetch_array($result, MYSQL_NUM)) {
    $arr[$i] = $row['COLUMN_NAME'];
    $i++;
}
echo json_encode($arr);

Javascript

$("#verticalSelect").change(function() {
    var table = $("#verticalSelect option:selected").attr('value');

    $.post(PROCESSORFILE, {"task": "getTableDupeFields", "table": table}, function(data) {
        alert(data);
    }, "json");
});

I want take the array $arr from php and pass it to javascript where I can print its contents one by one. So far the code I have and variations of have returned errors, resource Id’s and often just nothing at all.

How can this be done in the most trite way?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T18:09:24+00:00Added an answer on June 10, 2026 at 6:09 pm

    Firstly, what’s wrong:

    while($row = mysql_fetch_array($result, MYSQL_NUM)) {
        $arr[$i] = $row['COLUMN_NAME'];
        $i++;
    }
    

    You’re specifying MYSQL_NUM, which instructs mysql_fetch_array() to return a numeric array. With that flag set, you’d access the first value as $row[0]. To get an associative array and access the fields by name, you can either use mysql_fetch_assoc() instead, not pass any flag to mysql_fetch_array(), or pass it MYSQL_ASSOC.

    Also, the $i variable you’re using is unnecessary – you can append elements to an array without specifying an index, like so:

     $arr[] = $row['COLUMN_NAME'];
    

    Finally, your script is open to SQL injection when you insert a $_REQUEST variable directly into your sql. At the very least, you should run mysql_real_escape_string() on the value before adding it to the SQL.

    $table = mysql_real_escape_string($_REQUEST['table']);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

PHP $table = mysql_real_escape_string($_REQUEST['table']); $query = SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.Columns where TABLE_NAME = '$table';
i have this php code: $query = mysql_query(SELECT * FROM table WHERE id=$id); while($item
This would be an example of database table: PHP script should limit query result
The PHP file: <? print_r($_REQUEST); $thispage = 'login'; require('db.php'); if($_POST['admin_username'] && $_POST['admin_password']) { $query=SELECT
I am exporting data table from php page to pdf I got the page
I am retrieving values from a database and displaying it a table using php.
I've got a html table I build from the database: <tr onclick=DoNav('<?php echo $result_videos[$i][video_url];
I want to request 5 random rows from my SQL table using php. for
I'm trying to get an html table from a dynamic php page on my
I have created a PHP script which builds a table from an XML document

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.