probably easy solved problem with list-menu?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
perik78
Forum Newbie
Posts: 8
Joined: Mon Dec 28, 2009 5:20 pm

probably easy solved problem with list-menu?

Post by perik78 »

Hi!

Im using a forum that is called e107 (http://www.e107.org) which is build in php.
Im editing this plugin:
http://plugins.keal.me.uk/plugins/recip ... ecipes.php

and run into a problem.
In the "Select Category" (see picture below) I succeded to list all the posts from a single author instead of categories by editing this code:

Code: Select all

          $recipemenu_selcat = '
            <select class="tbox" name="recipemenu_select" onchange="this.form.submit()">
                <option value="" >' . RCPEMENU_111 . '</option>';
            if ($sql->db_Select('recipemenu_category', '*', ' order by recipe_category_name', 'nowhere', false))
            {
                while ($recipemenu_row = $sql->db_Fetch())
                {
                    extract($recipemenu_row);
                    $recipemenu_selcat .= "<option value='{$recipe_category_id}' ";
                    if ($recipe_category_id == $recipemenu_recipecat)
                    {
                        $recipemenu_selcat .= ' selected="selected"';
                        $recipe_catdesc = $recipe_category_description;
                        $recipemenu_catname = $recipe_category_name;
                        $recipemenu_where = "recipe_category='$recipemenu_recipecat'";
                        if ($recipemenu_row['recipe_category_icon'] && file_exists('images/caticons/' . $recipemenu_row['recipe_category_icon']))
                        {
                            $recipemenu_caticon = '<img src="images/caticons/' . $recipemenu_row['recipe_category_icon'] . '" style="border:0;" alt="" />';
                        }
                    }
                    $recipemenu_selcat .= '>' . $tp->toFORM($recipe_category_name) . '</option>';
                } // while
            }
            else
            {
                $recipemenu_selcat .= '<option value="0">' . RCPEMENU_4 . '</option>';
            }
            $recipemenu_selcat .= '</select>';
into:

Code: Select all

// START CODE
            $recipemenu_selcat = '
            <select class="tbox" name="recipemenu_select" onchange="this.form.submit()">
                <option value="" >' . RCPEMENU_111 . '</option>';
            if ($sql->db_Select('recipemenu_recipes', '*', ' order by recipe_author', 'nowhere', false))
            {
                while ($recipemenu_row = $sql->db_Fetch())
                {
                    extract($recipemenu_row);
                    $recipemenu_selcat .= "<option value='{$recipe_author}' ";
                    if ($recipe_author == $recipemenu_recipecat)
                    {
                        $recipemenu_selcat .= ' selected="selected"';
                        $recipe_catdesc = $recipe_author_description;
                        $recipemenu_catname = $recipe_author;
                        $recipemenu_where = "recipe_author='$recipemenu_recipecat'";
                        if ($recipemenu_row['recipe_author_icon'] && file_exists('images/caticons/' . $recipemenu_row['recipe_author_icon']))
                        {
                            $recipemenu_caticon = '<img src="images/caticons/' . $recipemenu_row['recipe_author_icon'] . '" style="border:0;" alt="" />';
                        }
                    }
                    $recipemenu_bortmedborjan = explode(".", $recipemenu_row['recipe_author'], 2);
                    $recipemenu_lank = $tp->toFORM($recipemenu_bortmedborjan[1], false);
                    $recipemenu_selcat .= '>' . $recipemenu_lank . '</option>';
                } // while
            }
            else
            {
                $projectmenu_selcat .= '<option value="0">' . RCPEMENU_4 . '</option>';
            }
            $projectmenu_selcat .= '</select>';
// END CODE  
what i basically did was to replace the recipe_category with recipe_author.

The function works but the problem is that now I get a list that looks like this:
Image

as you can see the authors are repeating eachother. I just want the different authors to be displayed once.

I was thinking to solve it by count the project_author in the project_author and if they where more than 1 i just displayed one but since im not very good in php I run into problems. This is what I tried anyway:

Code: Select all

$text = "";
$count_project_author = $sql->db_Count("projectmenu_projects", "*", "project_author", ?????);
if($count_project_author > 1)
echo $text;
I know that would never work and the echo text and everything is not the right way but maybe if someone want to help to dig a bit deeper into this?

Heres a picture from the database from phpmyadmin:
Image

thanks a lot! any help what so ever would be very much apreciated!!!
bjazmoore
Forum Newbie
Posts: 11
Joined: Mon Dec 28, 2009 12:12 pm

Re: probably easy solved problem with list-menu?

Post by bjazmoore »

That is the brute force method of doing it, and not knowing much about the various classes that the system is built on, that is about all I could recommend.

If you want to write your own SQL you could use the select distinct query to get one instance of each author from the database. It would take some study and a bit of work to integrate that into the modified module, but it would probably be more efficient.

Bjaz
manojsemwal1
Forum Contributor
Posts: 217
Joined: Mon Jun 29, 2009 4:13 am
Location: India

Re: probably easy solved problem with list-menu?

Post by manojsemwal1 »

yes u can use distinct or group in sql query ............................
it will reduce u r problem...
perik78
Forum Newbie
Posts: 8
Joined: Mon Dec 28, 2009 5:20 pm

Re: probably easy solved problem with list-menu?

Post by perik78 »

solved it by changing:

Code: Select all

   if ($sql->db_Select('projectmenu_projects', '*', ' order by project_author', 'nowhere', false))
to:

Code: Select all

 
            if ($sql->db_Select('projectmenu_projects', 'project_author', ' GROUP BY project_author', 'nowhere', false))
The whole code is now:

Code: Select all

//FROM
            $projectmenu_selcat = '
            <select class="tbox" name="projectmenu_select" onchange="this.form.submit()">
                <option value="" >' . RCPEMENU_111 . '</option>';
//              if ($sql->db_Select('projectmenu_projects', '*', ' order by project_author', 'nowhere', false))
            
            if ($sql->db_Select('projectmenu_projects', 'project_author', ' GROUP BY project_author', 'nowhere', false))
            {
                while ($projectmenu_row = $sql->db_Fetch())
                {
                    extract($projectmenu_row);
                    $projectmenu_selcat .= "<option value='{$project_author}' ";
                    if ($project_author == $projectmenu_projectcat)
                    {
                        $projectmenu_selcat .= ' selected="selected"';
                        $projectmenu_catname = $project_author;
                        $projectmenu_where = "project_author='$projectmenu_projectcat'";
//              if ($projectmenu_row['project_author_icon'] && file_exists('images/caticons/' . $projectmenu_row['project_author_icon']))
//              {
//              $projectmenu_caticon = '<img src="images/caticons/' . $projectmenu_row['project_author_icon'] . '" style="border:0;" alt="" />';
//              }
                    }
                    $projectmenu_bortmedborjan = explode(".", $projectmenu_row['project_author'], 2);
//                  $projectmenu_lank = $tp->toFORM($projectmenu_bortmedborjan[1], false);
                    $projectmenu_selcat .= '>' . $tp->toFORM($projectmenu_bortmedborjan[1], false) . '</option>';
                } // while
            }
// TO
 
But now I would like to change so I get links instead of <option> menu so it displays like below:
Katapult <a href LINK THAT LISTS ALL THE PROJECTS OF THAT USER>
Per <a href LINK THAT LISTS ALL THE PROJECTS OF THAT USER>
User3 <a href LINK THAT LISTS ALL THE PROJECTS OF THAT USER>
User4 <a href LINK THAT LISTS ALL THE PROJECTS OF THAT USER>
and so on ...
so links instead of the users that are displayed in option menu "Show by member:":
Image

any tips how?

By the way in the picture of the phpmyadmin there have been some small namechangnings so just imagine that everywhere it says project there shall be recipe instead.

Thanks a lot!

Per
manojsemwal1
Forum Contributor
Posts: 217
Joined: Mon Jun 29, 2009 4:13 am
Location: India

Re: probably easy solved problem with list-menu?

Post by manojsemwal1 »

u have to make a file called abc.php and that file u have to print all the author project detail. for that you
just call the project author code in the query and while printing the project author also take the projectauthor code
like <a href='abc.php?$projectauthorcode'> Project Author Name</a>
when the visitor will be click on the link the abc.php file will call . and in that file u can get the author id and call the query
regarding author project details..


Thanks
perik
Forum Newbie
Posts: 6
Joined: Tue May 10, 2005 5:18 am

Re: probably easy solved problem with list-menu?

Post by perik »

hi

thanks for help!

what could the code in abc.php look like?

Im newby
Post Reply