Support » Fixing WordPress » How to select all information in a table

  • Hello fellow WordPressers,

    I am trying to use $wpdb to gather all the information in a custom table that I created. Can someone help me out with this because I am trying to understand how $wpdb works but I can’t seem to get it to work.

    Here is what I have setup in the database.

    ID ————–Name————–Request
    1 ————–John————–Update contacts
    2 ————–Jane————–Remove post
    3 —————Scott————-Add new category.

    What I want to do is create a function that pulls the name and request information and displays them in a format from newest to oldest in a list format where I can read these, the way it is displayed doesn’t matter. I can connect to the database using PHP and MySQL queries but not through the $wpdb. I need to know how to get all the information from the table and display it using ARRAY_A format. Basically this is what I have been doing:

    //Query to run on the database.
    $query = “SELECT * FROM wp_requests”;

    //Get the results form the database.
    $result = mysql_query($query) or die(mysql_error());

    //display only 100 results.
    for($counter = 0;$counter<=100;$counter+=1){
    while($row = mysql_fetch_array($result)){
    echo “<tr><td style=\”border-bottom:1px solid #DDDDDD;\”>”.$row[‘name’]. “</td><td style=\”border-bottom:1px solid #DDDDDD;\”>”. $row[‘request’].”</td></tr>”;

    This works but I want to do it with $wpdb. But for some reason I could not get it working. If someone could help me out with this and give a basic idea on how to do this. I read the article about $wpdb and it really does not explain what I am wanting to do in lame man terms. Even if someone could give me a great tutorial on how to write plugins that interact with databases.


  • The topic ‘How to select all information in a table’ is closed to new replies.