• Resolved ladyuk

    (@ladyuk)


    I have just updated WordPress to the latest version, and have trawled the boards and docs looking for an answer…

    This is the select statement I was/am using


    <?php echo $link_cats = $wpdb->get_results(“SELECT link_category, link_name FROM $wpdb->wp_links order by link_category ASC”);

    foreach ($link_cats as $link_cat) { ?>
    <h3 class=”maintitle” >
    <?php echo $link_cat->cat_name; ?>
    </h3>

      <?php wp_get_links($link_cat->cat_id); ?>

    <?php } ?>

    And when I run it in PMA it comes out fine (SELECT link_category, link_name FROM wp_links order by link_category asc)

    SOOOO

    Does anyone know why I keep getting

    “WordPress database error: [You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘order by link_category ASC’ at line 1]” at http://www.thegeneva.com ?

    I just want to display all of my links in their categories…

Viewing 2 replies - 1 through 2 (of 2 total)
  • The ‘link_category’ record in the links table (which would be called as $wpdb->links and not $wpdb->wp_links) is no longer extant, as categories for links and posts have been combined.

    Welcome to WordPress 2.1! :P

    There is a disconnect between which records your echo’ed query is collecting (‘link_category’, ‘link_name’) and what your foreach loop is using (‘cat_name’, ‘cat_id’). But anyway, try the following query to collect the link categories:

    $link_cats = $wpdb->get_results("SELECT cat_ID, cat_name FROM $wpdb->categories WHERE link_count > 0 ORDER BY cat_name ASC");

    Thread Starter ladyuk

    (@ladyuk)

    Thanks, that did it.

    Here is the code I used, for example, if anyone else wants to use it

    <?php

    $link_cats = $wpdb->get_results(“SELECT cat_ID, cat_name FROM $wpdb->categories WHERE link_count > 0 ORDER BY cat_name ASC”);

    foreach ($link_cats as $link_cat) { ?>

    <h2> <?php echo $link_cat->cat_name;?></h2>

      <?php wp_get_links($link_cat->cat_ID);?>

    <?php }?>

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘error in your SQL syntax – links and categories’ is closed to new replies.