logo
down
shadow

Trying to build my query by fetching column names from the selected table


Trying to build my query by fetching column names from the selected table

By : user2172903
Date : October 22 2020, 08:10 AM
should help you out I've changed the function slightly to pass in the fields which you access using global (as this isn't recommended). So you will have to alter the call to getTableDetails().
mysqli_fetch_fields() is used to return the fields which are part of the result set, as this is from a describe, you were fetching the fields which were the return values of the describe rather than the fields in the table. Instead you need to use mysqli_fetch_assoc() which returns the rows of data from the statement.
code :
function getTableDetails( $con, $user, $table_name) {
    $describeTable = mysqli_query($con, "DESCRIBE " . $user . "." . $table_name);

    $fields = [];
    while($show = mysqli_fetch_assoc($describeTable)) {
        $columnName = $show['Field'];
        // Extract length from field type (if any)
        preg_match('#\((.*?)\)#', $show['Type'], $match);
        $fields[$columnName] = ['column_name' => $show['Field'],
            'column_length' => $match[1]??0,
            'column_type' => $show['Type']];        
    }

    return $fields;
}

$table = getTableDetails( $con, $user, "articles");
foreach ($table as $columnName) {
    print_r($columnName);
}


Share : facebook icon twitter icon
fetching db column names only, for display in dynamic table using php

fetching db column names only, for display in dynamic table using php


By : Joshua Shen
Date : March 29 2020, 07:55 AM
around this issue in the code below Im searching specific columns from a db table and placing them into a html table, inserting   for empty db fields to maintain uniformed structure. That part works fine, but Im having trouble figuring out the best way to go about getting the column names that are being searched and dynamically displaying them once at the very top of the html table? If my search changes, the column names displayed on the html table will change with it accordingly. Im fairly new to php/mysql and would appreciate any help guys. , How about something like this:
code :
$result = mysql_query('SELECT part, ers, make, model, years, oe, core, inlet, outlet FROM parts LIMIT 3');
echo '<table>';

$cnt = 0;
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
    if ($cnt == 0) {
        $columns = array_keys($row);
        echo '<tr><th>' . implode('</th><th>', $columns) . '</th></tr>';
    }

    $cnt++;
    echo '<tr>';

    foreach ($row as $name => $value) {
        if ( $value == "" ) $value="&nbsp;";
        echo '<td> '.$value.' </td>'; 
    }

    echo '</tr>'; 
}

echo "</table>";
fetching column names of a join table

fetching column names of a join table


By : Abricorn
Date : March 29 2020, 07:55 AM
wish helps you Column name can be fetched via mysql_fetch_field. Example code is available in http://php.net/manual/en/function.mysql-fetch-field.php.
Need to build a query with column names stored in another table

Need to build a query with column names stored in another table


By : Nico Thousand-hand R
Date : March 29 2020, 07:55 AM
seems to work fine I don't think this is possible in pure SQL due to the dynamic nature of your requirement. You'll need some form of PL/SQL.
Assuming you're ok with simply outputting the desired results, here is a PL/SQL block that will get the job done:
code :
declare
  wExists number(1);
begin
  for rec in (select * from your_dynamic_table)
  loop
    execute immediate 'select count(*)
                         from dual
                        where exists (select null
                                        from ' || rec.table_name || ' t
                                       where length(t.' || rec.column_name || ') > ' || rec.char_length || ')'
    into wExists;

    if wExists = 1 then
      dbms_output.put_line(rec.column_name);
    end if;
  end loop;
end;
Fetching Column Names From Same Table Where Conditions

Fetching Column Names From Same Table Where Conditions


By : Kumaresh Passoupathi
Date : March 29 2020, 07:55 AM
Hope this helps I need columns names from table with condition satisfying on the same table. say if column named 'size' has value '22', while it should check for same value in 24 columns named starting as 'sizecaption1,sizecaption24', and return column names holding the value '22' for each row. This is I tried, but it doesnt works for me: , Based on your sparse specification you could try along
code :
SELECT
  id,
  TRIM(CONCAT(
    IF(sizecaption1 = size, 'sizecaption1 ', ''),
    IF(sizecaption2 = size, 'sizecaption2 ', ''),
    IF(sizecaption3 = size, 'sizecaption3 ', ''),
    IF(sizecaption4 = size, 'sizecaption4 ', ''),
    IF(sizecaption5 = size, 'sizecaption5 ', ''),
    IF(sizecaption6 = size, 'sizecaption6 ', '')
    )) AS result
FROM JoinBoom
ORDER BY id
;
How to omit the first result in the query fetching column names?

How to omit the first result in the query fetching column names?


By : Ryan
Date : March 29 2020, 07:55 AM
it fixes the issue I'm fetching column names from a specific table: , You would add:
code :
and ordinal_position > 1
Related Posts Related Posts :
  • Running two PHP versions on the same server (STRETCH)
  • Checking if a file has been selected for upload
  • Model not updating laravel
  • How to add a description of words from text to an array, to an array key by passing words?
  • Nginx rewrite rule not not passing variables if "/" is at the end of the url
  • Modify decimal point and thousands separator without changing the number of decimals
  • Remove PHP errors from CLI and PHPMyAdmin
  • Yii2 rest api - Url manager add parameters
  • 1-query batch update array of users using PDO
  • Keep getting error: implode(): Invalid arguments passed when updating data
  • Laravel 5.4 - Correct Validation rule for a required parameter that can be zero
  • What does this code mean: $objPHPExcel->getActiveSheet()->toArray(null, true,true,true)
  • Data not being added to mysql table but echo's the data?
  • While fetch row in PHP
  • IP long string filter
  • How to view first image in list per user as its highlight Profile
  • Insert multiple rows from array
  • PHP : How to remove a duplicate array item ONCE
  • Print the input box text as simple text instead of html tag
  • How to read a string variable in php as $_GET or $_POST?
  • MySQL query fetch array not working
  • LogicException with message '... must return a relationship instance.'
  • PHP - create new array with only selected keys from an existing array
  • How to allow backgrounding a process to survive a session termination?
  • How to redirect to Home page (Default page) in zend framework 2?
  • I want to call a jquery variable in php syntax
  • Disabling the default /?add-to-cart= animation on buttons in Woocommerce
  • How to use query data for another sql query in yii2
  • Replace string enclosed in specified characters based on data type
  • Symfony FormType: how to get prototype in form type file
  • Handle reply messages properly after some operations in php
  • PHP Changed Domain, how to remove old Session Cookies
  • mysqli_stmt::bind_param(): Number of variables doesn't match number of parameters in prepared statement in php
  • Error: Call to a member function update() on array laravel
  • How to change the format of a float number?
  • run ajax requests by order
  • Wordpress Install 404 Error (Cannot view login in browser)
  • Calcinai xero-php pass config once
  • Fatal error calling to undefined function in PHP file
  • Laravel hasMany and belongsTo parameters
  • How do I call a Controller method in php Laravel?
  • How to replace "@" post tag with regex in PHP?
  • Laravel : when insert record in table. How can i add that Record in the list without querying the db
  • It is possible that I could user email address to get customer id from simPRO API?
  • PHP add and merge sql result
  • laravel ckeditor dark theme
  • Laravel belongsToMany not working
  • laravel 5.4 datatables not working jquery $ referenceError
  • Zend Form 2 multiselect field is empty after validation
  • PHP - Laravel 5 get data to html table from 3 SQL database tables with column DATA as headers
  • Can't use token authorization with Laravel Passport
  • splitting lines of dates and presenting in desired format
  • Laravel 5.2 Heroku Deployment Failed to install system packages
  • Laravel relationships - are there multiple *unnecessary* database calls?
  • htaccess rewrite rule for serving index.php from parent directory
  • PHP/MongoDB - $concat aggregation
  • Remove ajax.googleapis.com from my Wordpress site
  • Image saved always empty with Storage::put in Laravel
  • How to count and sort data in junction table
  • Get common number of values in a single array
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org