WordPress.org

Ready to get started?Download WordPress

Forums

How to get row data (3 posts)

  1. yeagerc50
    Member
    Posted 1 year ago #

    This is what I have so far:
    $myrows = $wpdb->get_results('SELECT * FROM wp_cars',ARRAY_A);
    //var_dump($myrows);

    Using mysql would look like this:
    while ($row = mysql_fetch_row($myrows)){
    echo "$row[1] $row[2]" etc.
    This is how it looks using mysql: http://www.joomlawebsitesbyjim.com/wordpress/sample-used-car-dealer/

    How do I duplicate this using wpdb?

  2. s_ha_dum
    Member
    Posted 1 year ago #

    You have duplicated it with $wpdb. That is as far as $wpdb goes. You now have a PHP associative array. Just loop over it.

    Something like:

    foreach ($myrows as $v) {
      echo $v['column1'],$v['column2'];
    }

    Since you specifically asked for an associative array, you will have to have the names of the table columns, or loop though each $v individually. If you used ARRAY_N instead you could use index numbers.

  3. yeagerc50
    Member
    Posted 1 year ago #

    Sometimes the answer is so simple I look right past it.

    Thank You!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags