Skip to:
Content
Pages
Categories
Search
Top
Bottom

query/php problem

  • Hi,

    I have made a new plugin, works great, but I have one little problem with it.

    Here is the php code/query/function and how the table looks:

    http://www.sourceskins.com/problem.jpg

    What does it do?

    Well it checks if the page id == location. If so, give a id named current. This works. The problem is the first line (see the db table in the jpg). Look at location. I have entered 2 values in location: front-page || topic-page

    I have used || in it the split them.

    The idea was: if bb_get_location == front-page OR topic-page give the id. So it had to look if it matches a record from that row.

    Problem is, it aint working cause it will spit out: front-page || topic-page and the code isn’t able to look for a match.

    How can I solve this? Any ideas?

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

  • chrishajer
    Participant

    @chrishajer

    I don’t know anything about your plugin, but why not put the OR in the PHP, similar to how WordPress checks for pages or posts:

    <?php if(is_home() || is_single() || is_page()) {

    whatever;

    } ?>

    Maybe you could put the logic in the PHP? I don’t understand what the plugin does, but the value in the database seems odd to me.

    so, for your application:

    <?php if ((bb_get_location == front-page) || (bb_get_location == topic-page)) {

    give the ID;

    } ?>


    ardentfrost
    Member

    @ardentfrost

    Yeah, I’m with chris on this one. SQL can’t determine what page you’re on. It can only get stuff from the DB. You’ll need to use php to figure out when to get the information from the db.

    Okay, I changed the location value with:

    is_front() || is_forum() || is_tag() || is_topic()

    And changed the code with:

    function get_bb_menu() {

    global $bbdb;

    $menutest = mysql_query("SELECT * FROM $bbdb->menu WHERE set = 'active' ORDER BY order ASC");

    And re-written the li part with php:

    <li><a <?php if ('location')

    {

    echo " id="current";

    ?>

    href="<?php ('page'); ?>"><?php ('item'); ?></a>

    <?php

    }

    ?></li>

    So technically I need to put this in a foreach and it wil be like:

    <li><a <?php if (is_front() || is_forum() || is_tag() || is_topic())

    echo " id="current"; ?>href="index.php">Forums</a> </li>

    <li> <a href="search.php"> Search</a></li>

    (the is_front() etc will not be shown ofcourse, but it’s to make it clear)

    But how to make such a foreach?

    Note: using id="current" in this way is dodgy because plugins have to generate content that co-operates with other plugins.

    If another plugin also uses id="current" the page will not validate (because each ID (identity) should be unique).

    You could just say id="X8VQm2_current" but (a) it would look ugly and (b) regardless, you’re not changing the identity of the row, you’re just saying something about it, so using ID is still wrong.

    The solution is easy: use class="current" instead and adjust your css so that instead of #current {} you use .current {}

    The example I wrote for you before shows how to do it.

    There is a painful habit of mis-using the id attribute among many theme designers and that makes it difficult to know what to do or why to do it :)

    Well what I dont understand is that THIS works:

    <li><a <?php if (is_front() || is_forum() || is_tag() || is_topic() || is_bb_feed() || is_bb_profile() || is_bb_favorites() || is_view())

    {

    echo "id="current"";

    }?> href="index.php">Forums</a></li>

    And this aint:

    $current = ($rw['location']) ? ' id="current"' : '';

    echo '<li ' . $first . '><a href="' . $rw['page'] . '"' . $current . '>' . $rw['item'] . '</a></li>';

    Cause ($rw) will give: (is_front() || is_forum() || is_tag() || is_topic() || is_bb_feed() || is_bb_profile() || is_bb_favorites() || is_view()) too

    It looks like your $rw["location"] variable contains the text "(is_front() || is_forum() || is_tag() || is_topic() || is_bb_feed() || is_bb_profile() || is_bb_favorites() || is_view())"

    Is that what you’re describing?

    If so a ternary structure (the x?y:z thing) won’t work because you need to give it a boolean value, so this may work…

    $switch = eval("return ".$rw["location"]);

    $current = ($switch ? ' id="current"' : "");

    … but if that does work, then you seriously need to ask yourself why you have such code in a variable – why can’t it be evaluated first then the result put in the variable – and if you can’t come up with a cogent answer you need to rethink your code.

    If that’s not what you’re describing then can you describe “not working” a bit better? Error messages and variable dumps help… or upload the source somewhere.

    Thx going to try that, and well I am no programmer at all, learning along the way. It goes like: Hmm that would be cool for bbPress -> is it possible (YES) -> how to make it? (google :)) -> try and error -> try and error -> try and error-> try and error -> getting fed up with it -> post help cry on this forum :)

    I’ll learn along the way :)

    And yes I want it this way, cause it’s only 1 record that looks so clumpsy, all others just have 1 record…

    Hmm got this error now when entered your code:

    Parse error: parse error, unexpected $ in /xxx/bbpress/my-plugins/bbmenu.php(123) : eval()’d code on line 1

    Thats where the $switch begins…

    If you want the beta of my plugin (for code), throw me an email and I will email it (got some uploading problems atm)

    email: mauricederegt at gmail.com

    Release early, release often. Release it as a non-working draft. Email is a hassle, and many eyes can benefit from the learning experience.

    Okay, I’ll release bbMenu BETA 0.1 next week (I am on holiday this weekend) so we can all see the code and the way it works (it does work :)) and I hope we can solve this problem I have…

Viewing 10 replies - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.
Skip to toolbar