Link to home
Start Free TrialLog in
Avatar of sureshp
sureshp

asked on

how to push values into the combobox using....

The following codes are used to put values into the combo box.

## subroutine continues
 
 elsif ($_ =~ /<!--Combobox-->/)
 {
 for ($i=0;$i<=$gno;$i++)
 {
 $j=0,$n=0;
 $arrayname = "array".$i;
 $codearrayname = "codearray".$i;
 @$arrayname = ();
 @$codearrayname =();
 $sql = "select uu_folder_name, uu_folder_path,uu_folder_uid,uu_gen_no,uu_folder_no from uu_folder
 where uu_gen_no ='$i' and uu_user_no='$user_no' ";
 $result = $conn->exec($sql);
 while (@value = $result->fetchrow)
 {
 @$arrayname[$i] = "$value[0]";
 $i++;
 }

 $$codearrayname[$n] = &fv_code_to_add($_,$i,$user_no);
 $n++;
 }


 ###For filling the code array####

 @addcodearray =();
 for ($k=$gno;$k>=0;$k--)
 {
 my $x=0;
 $p = $k+1;
 $outerarrayname = "array".$k;
 $codearrayname = "codearray".$k;
 $codeouterarrayname = "codearray".$p;
 foreach $folder_fullpath (@$outerarrayname)
 {
 $m = $k+1;
 my $y=0;
 $innerarrayname ="array".$m;
 foreach (@$innerarrayname)
 {
 if ($_ =~ /$folder_fullpath/)
 {
 $$codearrayname[$x] .= $$codeouterarrayname[$y];
 $$codeouterarrayname[$y] ="";

 }
 $y++;
 }

 $x++;
 }

 my $addcode;
 foreach (@$codearrayname)
 {
 $addcode.=$_;
 }

 }
 }

 else
 {
 print $_;
 }

 }
 return 1;
 }


 sub fv_code_to_add($$$)
 {
 my ($uu_folder_path,$noofnbsp,$user_no) = @_;
 my $nbspstring;

 for ($l=0;$l<$noofnbsp;$l++)

 {
 $nbspstring .= "&nbsp;&nbsp;&nbsp;";
 }

 print <<"EOF";

 <html><head><body><table>
 <tr>
 <th width="73%">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Select the destination folder</th>
 <td>&nbsp;&nbsp;&nbsp;<select name="MyFavorites" value="MyFavorites">
 EOF

 foreach $arrayname(@$arrayname)
 {
 print "<option>$nbspstring$arrayname</option>";
 } print <<"EOF";
 </select>
 </td> </tr>

 </table></body></head></html>

 EOF

 }

 But i am getting individual combobox with entry (depends on the generation values)
 eg; Select the destination folder : perl ----this value in combobox(when gno=0)
 Select the destination folder : Javascript --- -this value in combobox(when gno=1)

and one more doubt ....how can i arrange the elements like a tree structure?


 pls send a soln:
 Regards
 Suresh


                                                     





Avatar of maneshr
maneshr

"...But i am getting individual combobox with entry (depends on the generation values) .."

typically the HTML combobox tag is slightly different from what you have used.

the value attribute is given to the option tag and the select tag only has the name.

Eg.

<select name="MyFavorites">

foreach $arrayname(@$arrayname){
  print "<option value=\"$nbspstring$arrayname\">$nbspstring$arrayname</option>";
.......

================================================
"...and one more doubt ....how can i arrange the elements like a tree structure? ..."

if by a tree structure you mean the entries in the combobox should be indented with space, then you can do that in your script itself.

Eg. here is the tree structure i am referring to.

Grandparent
  Parent
    Child 1
    Child 2

....etc
Avatar of sureshp

ASKER

Hi maneshr,
  Thanks for your comment. I am using query this query to  retrieve values from database..
 
$sql = "select uu_folder_name, uu_folder_path,uu_folder_uid,uu_gen_no,uu_folder_no  from uu_folder  where uu_gen_no ='$i' and uu_user_no='$user_no' ";

Suppose, I am having the same gno(generation no)-- more than one.. Each contains child..
How  can i listed  it as a tree structure?
 For eg:
    Maneshr----is my root  
       Manesh
           Manes
       Manesr
           Man
 Using loop , i should maintain this structure?
 Hope you can solve ..

Regards,
Suresh
Avatar of sureshp

ASKER

Hi maneshr,
  Thanks for your comment. I am using query this query to  retrieve values from database..
 
$sql = "select uu_folder_name, uu_folder_path,uu_folder_uid,uu_gen_no,uu_folder_no  from uu_folder  where uu_gen_no ='$i' and uu_user_no='$user_no' ";

Suppose, I am having the same gno(generation no)-- more than one.. Each contains child..
How  can i listed  it as a tree structure?
 For eg:
    Maneshr----is my root  
       Manesh
           Manes
       Manesr
           Man
 Using loop , i should maintain this structure?
 Hope you can solve ..

Regards,
Suresh
"..Using loop , i should maintain this structure? .."

from the looks of it, it seems you are building some kind of directory tree structure.

you can do the tree, but there is a disadvantage that i think you should know about upfront.

this indentation will cause the size(width) of your combobox to be a lot.

what if there is a tree like so..

Manesh
  Manes
    Mane
      Man
        Ma
          M
......

then the no of spaces will increase with every sub-directory and you will end up having a pretty wide combo box.

if you still want to do it, give me some sample data that is returned by your SQL and i will write the code.
Avatar of ozo
instead of
${"codearray$k"}[$x] .= ${"codearray$p"}[$y];
Why not
$codearray[$k][$x] = $codearray[$p][$y];
?
Avatar of sureshp

ASKER

Maneshr,
  I am maintaining the tree structure sothat i can get information about root-parent-child relationship.
  My page is divided into two frames(left & right).
I should get the left frame structure into the rightframes combobox...

For eg:leftframe structure

  ONE
     TWO
        THREE
     FOUR
     FIVE
       SIX
          SEVEN      
        ...

generation number for
 ONE         ---- is 0
 TWO         ----is 1
THREE      -----is  2
FOUR       -----is  1
FIVE        ----- is 1
SIX         ----- is  2
SEVEN    ----  is 3

 I should get this structure into my combobox..
 may i send the code to your mail id?
Regadrs
Suresh
 
Avatar of sureshp

ASKER

Maneshr,
  I am maintaining the tree structure sothat i can get information about root-parent-child relationship.
  My page is divided into two frames(left & right).
I should get the left frame structure into the rightframes combobox...

For eg:leftframe structure

  ONE
     TWO
        THREE
     FOUR
     FIVE
       SIX
          SEVEN      
        ...

generation number for
 ONE         ---- is 0
 TWO         ----is 1
THREE      -----is  2
FOUR       -----is  1
FIVE        ----- is 1
SIX         ----- is  2
SEVEN    ----  is 3

 I should get this structure into my combobox..
 may i send the code to your mail id?
Regadrs
Suresh
 
here is a simple perl script that shows you how to print the tree structure, based on the results that you have given me.

for the purpose of this sample, i have used a text-based data file which has the results stored in it. the PERL script reads this file & prints out the tree.

NOTE: in the data file :: is the delimiter between the various columns.
Also remember to change the PERL script and update the path to your date file.

run this script from your browser.

======tree_data.txt
ONE::0
TWO::1
THREE::2
FOUR::1
FIVE::1
SIX::2
SEVEN::3

======tree_data.pl
!/usr/local/bin/perl

$|++;

print "Content-type: text/html\n\n";
print "<pre>\n";
open(TREE,"/tmp/tree_data.txt") || die $!;
while(<TREE>){
  chomp;
  ($tree_name,$tree_num)=split(/::/,$_);
  print "\t" x $tree_num,$tree_name,"\n";
}
close(TREE);
print "</pre>\n";
Avatar of sureshp

ASKER

maheshr,
 Thanks a lot.That's fine. Using my query(pls check),values i am getting from leftframe is not in the order.
 One change i made in the loop, instead of 'i' replaced by 'j'; so that i am getting values inside the combobox
(Individual combobox for each genno).

 How can i combine these values into my combobox?
 I am expecting One more help from you, some modification need on squery stmt.

At present condition, if my leftframe data is in the form..
 
  Maneshr
    Manesh
       Mane
    Mash
       Ma
        M
    Mas  

USING my query, I am getting values in the combobx as
 
   Maneshr ------for gno=0
 
   Manesh
   Mash        for  gno = 1
   Mas

   Mane
   Ma         for gno=2

   M          for gno=3


How can write query to get the same sructure from leftframe, so that i can put these values into the txtfile as you said early.

i am expecting reply from maneshr.

Regards
Suresh

 
   
 
"...One change i made in the loop, instead of 'i' replaced by 'j'; so that i am getting values inside the combobox

(Individual combobox for each genno). ..."

can you please post the latest code? its difficult for me to trace back those variables and then make the change.

Also can you give me a URL that i can look at, so that i can have a better picture of what is happening?


here is a brief of what i have understood so far.

if you find anything that is not correct, do let me know.

* You have 2 vertical frames in your HTML page.
* The frame on the left side is ok and the values there are displayed properly.
* The frame on the right hand side has the combobox.
* The same structure on the left frame should be shown in the right frame in a combobox.

if all of the above is right, i would like to know how is the structure shown properly on the left side frame?

it that frame being displayed by a seperate script??


".....so that i can put these values into the txtfile as you said early...."

i used the textfile as a sample, because i dont have the DB and the tables that you are using in your SQL statement.

in your case all that you have to do is get the output from the SQL statement in the same format as it is in the text file and then use the PERL script that i gave you to display them in a combobox.


"...USING my query, I am getting values in the combobx as
                       
                         Maneshr ------for gno=0
                       
                         Manesh
                         Mash        for  gno = 1
                         Mas

                         Mane
                         Ma         for gno=2

                         M          for gno=3 ......"


i have a question for the above.

why do only some values have a gno associated with them??

earlier you had said that every value has a gno associated with it.

i am referring to the following comment you made....

generation number for
                       ONE         ---- is 0
                       TWO         ----is 1
                      THREE      -----is  2
                      FOUR       -----is  1
                      FIVE        ----- is 1
                      SIX         ----- is  2
                      SEVEN    ----  is 3


i can provide you a working solution based on the answers that you give me.

Avatar of sureshp

ASKER

maneshr,
last day i quoted
 
"One change i made in the loop, instead of 'i' replaced by 'j'; so that i am getting values inside the combobox
(Individual combobox for each genno)".

what i meant was ,using my query i am getting values inside the combobox and each value inside one combobox having same generation number.

I am prepared for your questions, so please send your mail id so that i can forward to your mail id.
Regards
Suresh
maneshr@hotmail.com
Avatar of sureshp

ASKER

maneshr,
last day i quoted
 
"One change i made in the loop, instead of 'i' replaced by 'j'; so that i am getting values inside the combobox
(Individual combobox for each genno)".

what i meant was ,using my query i am getting values inside the combobox and each value inside one combobox having same generation number.

I am prepared for your questions, so please send your mail id so that i can forward to your mail id.
Regards
Suresh
Avatar of sureshp

ASKER

i will mail within 10 min
suresh
Avatar of sureshp

ASKER

Please send a solution
sureshp,

"Please send a solution"

without a URL, i cannot see the exact problem that you have.

since i dont have a web server on my local PC, i cant even run your HTML and CGI files.

Also all the paths in your HTML files are absolute, therefore its a lot of additional work in order to just see the files working.

like i told you before, can you give me the output of your SQL statements, so that i can link it to the script i gave you earlier?

Let me know.
Avatar of sureshp

ASKER

maneshr,
I told you before that all codes are kept it on our local server. Can i upload my files to some other location?
 If possible, where to upload?

I can send the output of my SQL statements.

These are my fields and values ....
uu_user_no | uu_folder_no |   uu_folder_uid   | uu_folder_name | uu_folder_desc
 |    uu_folder_path     | uu_gen_no
------------+--------------+-------------------+----------------+---------------
-+-----------------------+-----------
 220576     |            0 | 220576            | MyFavorite     | nothing
 | root                  |         0
 220576     |            2 | 220576k           | k              | k
 | /MyFavorite           |         1
 220576     |            3 | 220576l           | l              | l
 | /MyFavorite           |         1
 220576     |            4 | 220576ln          | cricket        | ball
 | /MyFavorite/l         |         2
 220576     |            5 | 220576lmanesh     | manesh         | expert
 | /MyFavorite/l         |         2
 220576     |            6 | 220576lmaneshperl | perl           |
 | /MyFavorite/l/manesh  |         3
 220576     |            7 | 220576lnone       | one            | 1
 | /MyFavorite/l/cricket |         3


My leftframe structure will be like this..
 
   MyFavorite
        k
        l
            Cricket
                 One
            Manesh
                 Perl  



Here MyFavorite ---- 0th generation
         k & l          ----- 1st
         Cricket & Manesh  --2nd
         One & Perl      ==== 3rd

while querying i should get the same structure from    leftframe and put this names into the combobox.

Pls check your mail id.... I am going to send the html which contains the combobox.
Regards
Suresh          
sureshp,

can you also send me the output of your SQL command as a text file?

the one you have posted here is all mangled up due to the way its displayed by EE.

Thanks
Avatar of sureshp

ASKER

maneshr,

I wrote code like this:

 for ($i=0;$i<=$gno;$i++)
 {
   $j=0;
    $sql = "select uu_folder_name,uu_folder_uid,     uu_folder_path,uu_gen_no,uu_folder_no from     uu_folder where uu_user_no='$user_no' ";
   $result = $conn->exec($sql);
   while (@value = $result->fetchrow)
  {
    @$arrayname[$i] = "$value[0]";
    @$popval[$i] ="$value[1]";
   $i++;            
  }
}

--------------------
 I am getting output like this:
 
 MyFavorite
 k
 l
 Cricket
 Manesh
 Perl            
 One


Regards
Suresh                                  
                                           
Avatar of sureshp

ASKER

manesh,
It's not maintaining the order..  one you created at the last will be added in the combobox at last value..

How can write SQL to get the same stucture into the combobox?
Regards
Suresh
sureshp,

"...How can write SQL to get the same stucture into the combobox?.."

here is what i am thinking.

we can approach the problem in two ways.

1) we can write a pretty complicated SQL statement that will get the results in exactly the way you want to present it in the combo box.

Adv: one SQL statement, with little logic at PERL side will work.
Disadv: Big, complex SQL statement. therefore, difficult to maintain.

OR

2) we can use the SQL as it is right now and then re-arrange the results, using some PERL based logic, and then present it in the combo box.

Adv: simple SQL statement.
Disadv: lot of the processing and display logic in PERL.


i personally prefer the 2nd method, since we can do a lot more processing in PERL, without making the code complex.

let me know your thoughts.


Avatar of sureshp

ASKER

maneshr,

Thanks...We can take the 2nd method.
Regards
Suresh
"...We can take the 2nd method. ."

Excellent!! we have a good start here.

can you send me the output of the SQL statement, that you have currently, as a text file?

the zip file you send me yesterday had one .gif file & that was broken too.

let me know.
sureshp,

i took the file that you sent me and renamed it as suresh.txt.
then i removed the first 2 lines from the file (column leading and ----)

Finally i wrote this script that would read the txt file and print out the result as tree. the tree is exactly as you want it.

i want you to test this script first from your command prompt using suresh.txt file.

let me know if the output is exactly as you want and we can then proceed to the next part viz printing the results in a combox box and integrating this code with your SQL statement.

Let me know as soon as possible.

==========suresh.pl

#!/usr/local/bin/perl

$|++;

open(S,"suresh.txt") || die $!;
@lines=<S>;
close(S);

foreach (@lines){
  chomp;
  ($one,$two,$three,$four,$five)=split('\|',$_);
  $one=~ s/^\s+//;
  $three=~ s/^\s+//;

  $one=~ s/\s+$//;
  $three=~ s/\s+$//;

  push (@final,$three."/".$one);
}

foreach $element ($[ .. $#final){
  $final[$element]=~ s/^root//g if $element == $[;
  $indent=($final[$element]=~ s/(\/)/$1/g);
  $final[$element]=~ s/.*\///g;
  print "   " x $indent," ",$final[$element],"\n";
}
Avatar of sureshp

ASKER

maneshr,
Excellent...
Still facing problem.. still it is not maintaining the exact structure..
pls check your mai id.. i am going to send another txt file pls check it... see the path..
Regards
Suresh
Avatar of sureshp

ASKER

maneshr,
Excellent...
Still facing problem.. still it is not maintaining the exact structure..
pls check your mai id.. i am going to send another txt file pls check it... see the path..
Regards
Suresh
ASKER CERTIFIED SOLUTION
Avatar of maneshr
maneshr

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sureshp

ASKER

manesh,
 Excellent .....
 It's working... points will be in your pocket for your Excellent performance.
 Please write the remaining solution(to put these values into the combobox).
Thanks a lot.
Regards
Suresh
sureshp,

"..(to put these values into the combobox). ..."

here is the modified code. checkit from your browser and remember to use the same data file as before.

Also remember to put the full path to the data file in the open sub-routine.

====suresh.pl
#!/usr/local/bin/perl

$|++;

open(S,"/full_path_to/suresh.txt") || die $!;
@lines=<S>;
close(S);

$ctr=0;

foreach (@lines){
  chomp;
  ($one,$two,$three,$four,$five)=split('\|',$_);
  $one=~ s/^\s+//;
  $three=~ s/^\s+//;

  $one=~ s/\s+$//;
  $three=~ s/\s+$//;

  $three=~ s/^root//g if !$ctr;
  ++$ctr;
  push (@final,$three."/".$one);
}



@final=sort byalp @final;

print "Content-type: text/html\n\n";

print qq{<FORM METHOD=POST ACTION="">
<SELECT NAME=popup>
};

foreach $element ($[ .. $#final){
  $final[$element]=~ s/^root//g if $element == $[;
  $indent=($final[$element]=~ s/(\/)/$1/g);
  $final[$element]=~ s/.*\///g;
  #print "   " x $indent," ",$final[$element],"\n";
  print qq{<OPTION VALUE="$final[$element]">},'&nbsp;' x $indent,qq{$final[$elem
ent]\n};
}

print qq{</SELECT>
</FORM>
};

sub byalp{ $a cmp $b;}
Avatar of sureshp

ASKER

manesh,
 Thanks for your immediate reply.
I will check this code and tell the status.
Regards
Suresh
sureshp,

"..I will check this code and tell the status. .."

good. waiting for your reply.....
Avatar of sureshp

ASKER

manesh,
I am writing  my previou code. In that where should i make these changes.
Before that may i ask you a doubt---
-----------------------------------
 where can i add the code to create a text file?
--------------------------------------

My previous code that display the combobox and related values(not in the leftframe structure) as i told you.

This tag <!--Combobox--> will be replaced in the html page(popup)...

Pls check this:

#!/usr/bin/perl

 #common cgi
require "UU_Favorite_Subroutines.cgi";
require "UU_Constants.cfg";
require "UU_Favorite_Constants.cfg";

      ## Declaring constants  
    $http_referer                        =      $ENV{'HTTP_REFERER'};
      $content_length                  =      $ENV{'CONTENT_LENGTH'};
      $request_method            =      $ENV{'REQUEST_METHOD'};
      
      ## Check the validity of http referer from where the request has come.
      &http_Referer_Check($http_referer);
      
       ## Connect to database
    &db_Connect;
      
        $user_id                                    = $FORM{'user_id'};
        $user_domain                        = $FORM{'user_domain'};
        $user_no                                    = $FORM{'user_no'};
        $uu_folder_uid                        = $FORM{'folder_uid'};
        $uu_folder_path                  = $FORM{'folderpath'};
        $genno                                    = $FORM{'genno'};
        $flag                                          = $FORM{'f_flag'};
      
        
        &fv_Display_Moving_Html($user_id,$user_domain,$user_no,$uu_folder_uid,$uu_folder_path);
        
         sub fv_Display_Moving_Html($$$$$)
        {
               
             my ($user_id,$user_domain,$folder_no,$uu_folder_uid,$genno)=@_;
             my @File;
            
             $sql="select uu_user_no from uu_user where uu_user_id ='$user_id' and uu_user_domain='$user_domain'";
             $result=$conn->exec($sql);
             $user_no = $result->fetchrow;
      
             $sql = "select uu_folder_no  from uu_folder where uu_user_no='$user_no' and uu_folder_uid= '$uu_folder_uid'";
             $result =$conn->exec($sql);
             $uu_folder_no = $result->fetchrow;
                                     
             $sql = "select uu_link_uid from uu_link where uu_folder_uid='$uu_folder_uid'";
             $result = $conn->exec($sql);
             $link_uid = $result->fetchrow;
                         
             $sql = "select uu_folder_path from uu_folder where uu_folder_uid='$uu_folder_uid'";
             $result = $conn->exec($sql);
             $uu_folder_path = $result->fetchrow;
             # print $uu_folder_path;
             $sql = "select uu_folder_name from uu_folder where uu_folder_uid='$uu_folder_uid'";
             $result = $conn->exec($sql);
             $folder_name = $result->fetchrow;
             
             $sql = "select uu_link_name from uu_link where uu_folder_uid='$uu_folder_uid'";
             $result = $conn->exec($sql);
             $link_name = $result->fetchrow;
                         
             $sql = "select uu_gen_no from uu_folder where uu_folder_uid='$uu_folder_uid'";
             $result = $conn->exec($sql);
             $genno = $result->fetchrow;
             
             $sql = "select max(uu_gen_no) from uu_folder where uu_user_no='$user_no'";
             $result = $conn->exec($sql);
             $gno = $result->fetchrow;
             
             
             open(RIGHT,"$fvroot/fv_Move_Folder_Link_Html.htm");
             @File = <RIGHT>;
             close(RIGHT);
             
      
            my $no1=0; my $counter1=0;
            my $no2=0; my $counter2=0;
             foreach $keys (@arrKeys)
             {
                  if ($keys =~ /bdlcheckbox/)                                      
                  {
                         @linkarr[$no1] = $FORM{$keys};
                        $no1++;
                        $counter1++;
                  }
             
              elsif ($keys =~ /notlink/)                        
              {
               @folderarr[$no2] = $FORM{$keys};
                  $no2++;
                  $counter2++;
              }
            }
      

      foreach  (@File)
      {    
             if($_ =~  /<form/i)
             {
                  print $_;
                  print "<input type=\"hidden\" name=\"user_id\" value=$user_id>";
                print "<input type=\"hidden\" name=\"user_domain\" value=$user_domain>";
                  print "<input type=\"hidden\" name=\"user_no\" value =$user_no>";
              print "<input type=\"hidden\" name=\"folder_uid\" value =$uu_folder_uid>";
                  print "<input type=\"hidden\" name=\"folderpath\" value=$uu_folder_path>";
                  print "<input type=\"hidden\" name=\"genno\" value=$genno>";
                  print "<input type=\"hidden\" name=\"folderno\" value=$uu_folder_no>";
                  print "<input type=\"hidden\" name=\"foldername\" value=$folder_name>";
                  print "<input type=\"hidden\" name=\"linkname\" value=$link_name>";
            }
               
                elsif($_ =~ /<!--Move foldername-->/)
             {
              foreach $folderarr (@folderarr[$no2])
              {
                    for ($no2=0;$no2<$counter2 ;$no2++)
                  {
                             
            print <<_NAME;
                        <tr>      <td><img src=\"/Images/commu/FolderClosed.gif\" width="16" height="16" alt="$folder_desc">$folderarr[$no2]<br></td>
                               
                        </tr>
_NAME
             
              }
            }
        }      
          
            
             elsif($_ =~ /<!--Move linkname-->/)
             {
              foreach $linkarr (@linkarr[$no1])
              {
                    for ($no1=0;$no1<$counter1;$no1++)
                  {
                      
            print <<_NAME;
                        <tr>      
                                <td><image src=\"/Images/commu/Link.gif\" width="16" height="16" alt="$link_desc">$linkarr[$no1]<br></td>
                        </tr>
_NAME
             
               }
             }
        }  
             
             
               elsif ($_ =~ /<!--Combobox-->/)
            {
                   for ($i=0;$i<=$gno;$i++)
                  {
                   $j=0,$n=0;
                   $arrayname = "array".$i;
                   $codearrayname = "codearray".$i;
                   @$arrayname = ();
                   @$popval = ();
                   @$codearrayname =();
                   $sql = "select uu_folder_name,uu_folder_uid, uu_folder_path,uu_gen_no,uu_folder_no from uu_folder where uu_user_no='$user_no' ";
                   $result = $conn->exec($sql);
                   while (@value = $result->fetchrow)
                   {
                          @$arrayname[$i] = "$value[0]";
                          @$popval[$i] ="$value[1]";
                  
                        $i++;            
                   }
                    
                    $$codearrayname[$n] = &fv_code_to_add($_,$i,$user_no);
                    $n++;
                  }
            
      }

      
       else
        {
         print $_;
         }

      }
       return 1;
}


sub fv_code_to_add($$$)
 {
   my ($uu_folder_path,$noofnbsp,$user_no) = @_;
   my  $nbspstring;
   for ($l=0;$l<$noofnbsp;$l++)
   {
       $nbspstring .= "&nbsp;&nbsp;&nbsp;";
         print <<"EOF";
      <table>
      <tr>
            <th width="73%">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Select the destination folder</th>
                   <td>&nbsp;&nbsp;&nbsp;<select name="MyFavorites">
EOF
      
                  foreach $arrayname(@$arrayname)
                   {
                        print "<option value=\"@$popval[$l]\">$nbspstring$arrayname</option>";
                        $l++;
                   }
                  
                              
                  print  <<"EOF";
                  </select>
                        
                  
                  </td> </tr>
                  </table>
EOF
   
 }
}


Pls check the code after this <!--combobox--> tag.

regards
Suresh
sureshp,

"where can i add the code to create a text file? ..."

like i told you earlier, the only reason i am using a text file i because i dont have the DB tables that you are using.

in your case all that you need to do is get the results of the SQL statement in an array and add the code i gave you right after it and you should have the combo box with you!!
Avatar of sureshp

ASKER

manesh,
 ok...If i didn't get soln, pls help.
Regards
Suresh
sureshp,

"If i didn't get soln, pls help. ..."

are you saying that you dont have a solution now or that if you dont get a solution later??

please calrify.
Avatar of sureshp

ASKER

manesh,
Hope you might have read my mail.
What you wrote is correct and some error in displaying the tree structure(Please check my attachment).
I will give full credit to you.

 Making use of your code, i dodn't get these into the combobox.. That's why i wrote  
  "If i didn't get soln, pls help. ..."

and one more help---

print qq{<OPTION VALUE="$final[$element]">},'&nbsp;' x $indent,qq{$final[$element]\n};

In this code i need to get the field value--folder_uid.
 ie instead of Value ="$final[$element]"
     should get "$two" value.


Waiting for your comment.
Regards
Suresh
sureshp,

"Hope you might have read my mail. .."

yes i have and i have replied to the same.


"..and one more help---

print qq{<OPTION VALUE="$final[$element]">},'&nbsp;' x $indent,qq{$final[$element]\n};

In this code i need to get the field value--folder_uid.
ie instead of Value ="$final[$element]"
should get "$two" value...."

ok. let me modify the code to take care of this new requirement.

i will post the code here once i have it ready.
Avatar of sureshp

ASKER

manesh,
"in your case all that you need to do is get the results of the SQL statement in an array and add the code i gave you right after it and you should have the combo box with you!! "

I followed this step..somehow i am not getting Combobox and values.. I can send the code. Today i will accept your answer.

Before that pls help me to find a soln.
Waiting for your help.


Avatar of sureshp

ASKER

manesh,
I am waiting for your code.
I have posted another question.
Regards
Suresh
Avatar of sureshp

ASKER

manesh,
Excellent Performance!!!!
 I am accepting your code. It's working.
Pls send the modified code to my mail or here.
Once again expressing my thanks.

Waiting for your code.
pls mail to psk_suresh@yahoo.com
Avatar of sureshp

ASKER


manesh,
Excellent Performance!!!!

Once again expressing my thanks.


pls mail to psk_suresh@yahoo.com
suresh_p,

i dont think you should have awarded the points before i posted the final change to your script.

Anyway, i shall send you the script tomorrow.

do let me know when you have your full site working, as i would like to see the actual script in action.

Rgds
Avatar of sureshp

ASKER

manesh,
I am a beginnerin this perl programming field. That's why i am aking each and every step.(Really i don't like to disturb you). Here is no chance to clarify my doubt.
I will inform you when site is ready.
Regards
Suresh
sureshp,

"That's why i am aking each and every step.(Really i don't like to disturb you). ..."

That is absolutely fine. i will help you in anyway i can.

Meanwhile, i am working on modifying the above script so that you have the 2nd column in the option value.

will keep you updated.
sureshp,

here is the modified code i have.


NOTE: the additional lines have been commented so that you will find it much easier to understand.


====suresh.pl
#!/usr/local/bin/perl

$|++;

open(S,"/home/manrao/suresh.txt") || die $!;
@lines=<S>;
close(S);

$ctr=0;

foreach (@lines){
  chomp;
  ($one,$two,$three,$four,$five)=split('\|',$_);
  $one=~ s/^\s+//;
  $two=~ s/^\s+//;  ##  Remove Leading space from the 2nd column
  $three=~ s/^\s+//;

  $one=~ s/\s+$//;
  $two=~ s/\s+$//;  ##  Remove trailing space from the 2nd column
  $three=~ s/\s+$//;

  $three=~ s/^root//g if !$ctr;
  ++$ctr;
 push (@final,$three."/".$one);
  push (@value,$two); ##  Store the 2nd column in an array
}

@final=sort byalp @final;

print "Content-type: text/html\n\n";

print qq{<FORM METHOD=POST ACTION="">
<SELECT NAME=popup>
};

foreach $element ($[ .. $#final){
  $final[$element]=~ s/^root//g if $element == $[;
  $indent=($final[$element]=~ s/(\/)/$1/g);
  $final[$element]=~ s/.*\///g;
  #print qq{<OPTION VALUE="$final[$element]">},'&nbsp;' x $indent,qq{$final[$element]\n};
  ##  Print the second column as the value to the combox item
  print qq{<OPTION VALUE="$value[$element]">},'&nbsp;' x $indent,qq{$final[$element]\n};

}

print qq{</SELECT>
</FORM>
};

sub byalp{ $a cmp $b;}



let me know if the script works for you using the data file i posted earlier.
Avatar of sureshp

ASKER

manesh,
Thanks for sending the code.
I will check this code and tell the result.
Regards
Suresh
sure.

let me know.
Avatar of sureshp

ASKER

manesh,
Yes...It's working...
Thanks a lot.

Request:--

This is text file---manesh.txt
MyFavorite |220576     |root       |0 |0
k          |220576k    |/MyFavorite|1|2
l          |220576l    |/MyFavorite|1|3
cricket    |220576ln  |/MyFavorite/l| 2 |4

manesh   |220576lmanesh |/MyFavorite/l |2 |5

demo |220576lndemo |/MyFavorite/l/cricket |3 |10

one       |220576one |/MyFavorite|1|9

check |220576lncheck |/MyFavorite/l/cricket |3|12


 I should get the structure in the combobox like:

 MyFavorite
   k
   l
     Cricket
       demo
       check
     manesh
   one

But i am getting the structure as

  MyFavorite
   k
   l
     Cricket
       check  
       demo            
     manesh
   one

## Anyway its maintaing genno and parent child relationship.
## in the place of demo getting value check and viceversa

If you gets time pls write to me why it happens?

Regards
Suresh
Avatar of sureshp

ASKER

manesh,
  The important message regarding the code is that, not getting proper folder_uid(value in 2nd column.
   Pls check the text i previously wrote.
   If i create one folder inside demo, the corresponding folder_uid value(ie column 2) shows someother folder_uid.

 I will post the text file and getting output as a text file.
Pls check your mail id.

Waiting for your message.
Regards
Suresh

sureshp,

yes, you are right. i had a bug in the code that came up because i sorted final array.


i have fixed that problem & tested it out.

Try it out at your end and let me know how it works.

====suresh.txt
MyFavorite |220576     |root       |0 |0
k          |220576k    |/MyFavorite|1|2
l          |220576l    |/MyFavorite|1|3
cricket    |220576ln  |/MyFavorite/l| 2 |4
manesh   |220576lmanesh |/MyFavorite/l |2 |5
demo |220576lndemo |/MyFavorite/l/cricket |3 |10
one       |220576one |/MyFavorite|1|9
check |220576lncheck |/MyFavorite/l/cricket |3|12

===suresh.pl
#!/usr/local/bin/perl

$|++;

open(S,"/home/manrao/suresh.txt") || die $!;
@lines=<S>;
close(S);

$ctr=0;

foreach (@lines){
  chomp;
  ($one,$two,$three,$four,$five)=split('\|',$_);
  $one=~ s/^\s+//;
  $two=~ s/^\s+//;  ##  Remove Leading space from the 2nd column
  $three=~ s/^\s+//;

  $one=~ s/\s+$//;
  $two=~ s/\s+$//;  ##  Remove trailing space from the 2nd column
  $three=~ s/\s+$//;

  $three=~ s/^root//g if !$ctr;
  ++$ctr;
  $value=$three."/".$one;
  push (@final,$value);
  $final{$value}=$two;
}

print "Content-type: text/html\n\n";

print qq{<FORM METHOD=POST ACTION="">
<SELECT NAME=popup>
};

foreach $element ($[ .. $#final){
  $final[$element]=~ s/^root//g if $element == $[;
  $indent=($final[$element]=~ s/(\/)/$1/g);
  $key=$final[$element];
  $final[$element]=~ s/.*\///g;
  ##  Print the second column as the value to the combox item
  print qq{<OPTION VALUE="$final{$key}">},'&nbsp;' x $indent,qq{$final[$element]\n};
}


print qq{</SELECT>
</FORM>
};

sub byalp{ $a cmp $b;}


Avatar of sureshp

ASKER

manesh,
 Thank you very much for your immediate response.
 Your answering method(approach) is very good[not ozo's method]. So you will become the toper of this site.
I once again congratulating your approach.
 I am going to write the ralated coding. If any doubt occurs, i will post the question in this site.
Thanks a lot.
Regards
Suresh
sureshp,

".. Your answering method(approach) is very good[not ozo's method]. .."

Thank you for your kind words. Although at times i find ozo's comment a bit cryptic, i am sure you will appreciates ozo's a lot better as you become more familiar with PERL.

"..So you will become the toper of this site. .."

if at the same time i can help other with their problem, that would be worth it. Thanks again.

"..I am going to write the ralated coding. If any doubt occurs, i will post the question in this site. ...."

Excellent! Wish you all the very best.

i have some very good PERL documents with me. Totally the documents are about 250 MB is size as a .zip file!!

i wish there was some way i could send them to you, so that you would have a very good source of reference at your fingertips.

Meanwhile, let me know how this script works.
Avatar of sureshp

ASKER

manesh,
Yes...Code is working and provide a best solution.
Thanks a lot.

"..i have some very good PERL documents with me. Totally the documents are about 250 MB is size as a .zip file!!

i wish there was some way i could send them to you, so that you would have a very good source of reference at your fingertips. "

 Thanks for your these words. You can publish one perl book, it will worth to other users. I couldn't purchase any good perl book.
 
 You can send perl tips to my yahoo id.
I will do onething, if you don't mind i can send Demand Draft/Check to your address, the needed documents write it into the CD and send to my address.

Once again expressing my thanks and Congratulating your participation(it starts from 07-08 to 22-08).
Regards
Suresh


sureshp,


"...I couldn't purchase any good perl book...."

is that because you are not aware of any good book for PERL or some other reason? if its the former, i can tell you of some books that helped me when i was a beginner.

"...I will do onething, if you don't mind i can send Demand Draft/Check to your address, the needed documents write it into the CD and send to my address. ."

that's fine. i dont need the money. Do you have a Zip drive on your system or on any other system??

Although, i can't cut a CD for you, i can definately send you a Zip disk.

if not, then maybe i will send you small parts of the document everyday and you can re-assemble them at your end to get the complete set.

NOTE: it will take at least 200-300 emails to get the entire document!!

let me know.
Avatar of sureshp

ASKER

manesh,
Thanks for your reply.
"..Do you have a Zip drive on your system or on any other system?? "

I hearing it first time. What's Zip drive? How much it cost?

If you are having sufficient time, pls send the doc parts to my id.

"....i can tell you of some books that helped me when i was a beginner"

  Pls note it here.
Take yourown time and send to my id.
Regards,
Suresh
 


sureshp,

"..What's Zip drive? How much it cost? .."

Zip drive looks exactly like a regular 1.44 MB Floppy disk drive, only the Zip disk (which has the same dimensions as a floppy disk, but is a lot thicker) has a capacity of 100MB and upwards.

In India i think i might cost around Rs. 3000-4000 and the best brand is by a company called IOmega.

check out the foll page...
http://www.iomega.com/zip/products/index.html

"..If you are having sufficient time, pls send the doc parts to my id. ..."

i will start sending you files from tomorrow. pl. send me an email so that i know your yahoo id.

"..Pls note it here. ..."

You can start with ....

* Learning Perl (2nd Edition) 302 pages Cost: US$25 (approx Rs 1200)

once you are at an intermediate level you can refer to...

* Programming Perl (2nd Edition) 645 pages Cost: US$40 (around Rs. 1800).

Hope that helps.
Avatar of sureshp

ASKER

manesh,
Thanks for your help.
 "Learning Perl (2nd Edition) 302 pages Cost: US$25 (approx Rs 1200)"
 Published by :..
 Author:...
 
Hope you are engaged with other questions. I am not waisting your time.
Regards
Suresh

Sory for not haing mentioned that before :-o

"Learning Perl (2nd Edition) 302 pages Cost: US$25 (approx Rs 1200)"
                       Published by : O'Reilly & Associates;
                       Author:.Randal L. Schwartz, Tom Christiansen, Larry Wall
Avatar of sureshp

ASKER

manesh,
Thanks a lot.
I couldn't reply to your message intime because of server error.
Regards
Suresh
Also if you can email me so that i have your email id.

i have one set of files ready to send to you.
Avatar of sureshp

ASKER

manesh,
Thank you very much.
Just now i post a question in this site. Title for this question is "Parent-child relationship".
Regards
Suresh
sureshp,

"..Just now i post a question in this site. Title for this question is "Parent-child relationship". .."

i have posted my comments/questions to it.
Avatar of sureshp

ASKER

manesh,
Again i am not getting the exact structure.
 s.txt

pls check this txt file..MyFavorite     | 220576        | root               |         0 |            0
1000           | 2205761000    | /MyFavorite        |         1 |            1
wer            | 220576wer     | /MyFavorite        |         1 |            2
g              | 2205761000g   | /MyFavorite/1000   |         2 |            3
f              | 220576f       | /MyFavorite        |         1 |            4
j              | 2205761000gj  | /MyFavorite/1000/g |         3 |            5
1              | 220576wer1    | /MyFavorite/wer    |         2 |            6


I should get the structure:

 MyFavorite
    1000
        g
           j
    wer
        1
    f


pls check it and tell me your suggestion.


I used your previous code:
#!/usr/bin/perl

$|++;

open(S,"$fvroot/s.txt") || die $!;
@lines=<S>;
close(S);

$ctr=0;

foreach (@lines){
  chomp;
  ($one,$two,$three,$four,$five)=split('\|',$_);
  $one=~ s/^\s+//;
  $two=~ s/^\s+//;  ##  Remove Leading space from the 2nd column
  $three=~ s/^\s+//;

  $one=~ s/\s+$//;
  $two=~ s/\s+$//;  ##  Remove trailing space from the 2nd column
  $three=~ s/\s+$//;

  $three=~ s/^root//g if !$ctr;
  ++$ctr;
  $value=$three."/".$one;
  push (@final,$value);
  $final{$value}=$two;
}

print "Content-type: text/html\n\n";

print qq{<FORM METHOD=POST ACTION="">
<SELECT NAME=popup>
};

foreach $element ($[ .. $#final){
  $final[$element]=~ s/^root//g if $element == $[;
  $indent=($final[$element]=~ s/(\/)/$1/g);
  $key=$final[$element];
  $final[$element]=~ s/.*\///g;
  ##  Print the second column as the value to the combox item
  print qq{<OPTION VALUE="$final{$key}">},'&nbsp;' x $indent,qq{$final[$element]\n};
}


print qq{</SELECT>
</FORM>
};

sub byalp{ $a cmp $b;}


Waiting for your reply
Regards
Suresh

Avatar of sureshp

ASKER

manesh,

pls check this txt file..

MyFavorite| 220576| root | 0 | 0

1000 | 2205761000| /MyFavorite|1|1

wer  |220576wer|/MyFavorite |1| 2

g  | 2205761000g|/MyFavorite/1000|2|3

f   | 220576f |/MyFavorite |1|4

j |205761000gj|/MyFavorite/1000/g|3|5

1| 220576wer1|/MyFavorite/wer| 2 |6


The structure should be look like:

    MyFavorite
    1000
        g
           j
    wer
        1
    f

Pls try to solve it.
Regards
Suresh






sureshp,

the problem is not with the script. the script merely processes the records in the *same sequence* as returned by the SQL statement.

so you need to fix the SQL statement, so that the results are displayed in the proper order.

unless that is done, the script will not print the results the way you are expecting it to.
Avatar of sureshp

ASKER

manesh,
 
Thanks for you reply.
 I can use only this query to get the value from the database.
  $sql = "select uu_folder_name, uu_folder_uid, uu_folder_path, uu_gen_no,uu_folder_no from uu_folder where uu_user_no='$user_no' ";

 "so you need to fix the SQL statement,"
Can you please tell me some hint to fix the Sql Statement?

Regards
Suresh


sureshp,

"..Can you please tell me some hint to fix the Sql Statement? ."

try adding the Order By clause to your statement, as follows

$sql = "select uu_folder_name, uu_folder_uid, uu_folder_path, uu_gen_no,uu_folder_no from uu_folder where uu_user_no='$user_no'  Order By uu_folder_path";
Avatar of sureshp

ASKER

manesh,
Using Order clause, I tried my best. Finally i am getting the structure(not same  as left) better than the previous one.
I used
$sql = "select uu_folder_name, uu_folder_uid, uu_folder_path, uu_gen_no,uu_folder_no from uu_folder where uu_user_no='$user_no' Order by uu_folder_uid";
 
If you have any idea to get the exact structure, pls inform me.
Thanks for your help.
Regards
Suresh
sureshp,

"..If you have any idea to get the exact structure, pls inform me. ."

sure i will do that.

in the meanwhile, i would suggest you post a new question so that other users can post their comments too and you might get the answer you are looking for.
Avatar of sureshp

ASKER

manesh,
I accept your comment. I was planning to do that.
I will post it within 30 minutes
Regards
Suresh
sureshp,

"..I will post it within 30 minutes .."

sounds good.

menawhile, i have sent you the .zip file across.