• Xaib Aslam

    (@lahorimela)


    Hello,
    I create a site with WordPress, then I install CPT UI to create custom post types. After that, I create a table in the database with the name (wp_christian_names) and I upload that file to excel and add some data. I have more than 7000+ rows inside, see this https://ibb.co/4Fzw539.

    So I was thinking that how I can make 7000+ URLs for that, so I created a taxonomy-like tag system, and I add all these names only, so I will get the URL for that. now I am confused that how I can show the exact name data for that. I do a search on google and found the answer but can’t figure out how WordPress knows that this name has data in the database.

    <?php
      global $wpdb;
      $table_name = $wpdb->prefix . "wp_christian_names";
      $user = $wpdb->get_results( "SELECT * FROM $table_name" );
    ?>
    
    <table border="1">
        <tr>
         <th>NAME</th>
         <th>GENDER</th>
         <th>ORIGIN</th>
         <th>RELEGION</th>
        </tr>
    
    <?php foreach ($user as $row){ ?>
    <tr>
    
        <td><?php echo $row->name ?></td>
        <td><?php echo $row->gender ?></td>
        <td><?php echo $row->origin ?></td>
        <td><?php echo $row->relegion ?></td>
    </tr>
    <?php } ?>
    
    </table>

    for example, I have a tag with the name Aana and want to fetch data of this name from the database.
    Can anyone help me with this please.

    • This topic was modified 2 years ago by Xaib Aslam.
Viewing 2 replies - 31 through 32 (of 32 total)
  • Thread Starter Xaib Aslam

    (@lahorimela)

    Also i have question here that i add name in taxonomy like this and you can see the URL as well.

    https://ibb.co/2j62gmm

    So if I add a slug column inside the SQL table will this work fine? So i have to just change the column name in this SQL query!

    <?php
    $name = get_query_var('christian_boy_name');
    global $wpdb;
    $sql = $wpdb->prepare("SELECT * FROM wp_names_christian WHERE name_slug=%s;", $name );
    $row = $wpdb->get_row( $sql );
    ?>
    Moderator bcworkz

    (@bcworkz)

    Assuming the request was something like example.com/name/ab-ul-hasan/, so that $name == 'ab-ul-hasan' after the get_query_var() call, then that should do it.

Viewing 2 replies - 31 through 32 (of 32 total)
  • The topic ‘Display data from database’ is closed to new replies.