Page 1 of 2 12 LastLast
Results 1 to 10 of 16

Thread: looping in the table

  1. #1
    Join Date
    Jun 2009
    Posts
    8
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default looping in the table

    Code:
    <html> 
    <head><title>Your Page Title</title></head> 
    <body> 
    <?php
    $dbhost = 'localhost';
    $dbuser = 'root';
    $dbpass = 'hello';   
    $dbname = 'user';
    echo "hello";
    // make a connection to mysql here
    $conn = mysql_connect ($dbhost, $dbuser, $dbpass);
    if(!$conn)
    {
    die('could not connect: ' . mysql_error());
    }
    else
    echo "<BR>connected";
    //select database to use
    $conn = mysql_select_db ($dbname);
    echo "<BR>connected to db" ;
    
    $result = mysql_query("SELECT taxtype.taxtypeid,taxname,group_concat(formno),actid,taxtype.status as formnum  FROM taxtype,taxform where taxtype.taxtypeid=taxform.taxtypeid group by taxtypeid")or die(mysql_error());
    $num_rows = mysql_num_rows($result);
    echo "<BR>" . $num_rows;
    print "<table width=500 border=1>\n"; 
    while($row = mysql_fetch_row($result))
    {
         print "<tr>\n";
       
                    print "\t<td><font face=arial size=1/>$row[0]</font></td>\n"; 
                    print "\t<td><font face=arial size=1/>$row[1]</font></td>\n"; 
                    print "\t<td><font face=arial size=1/> <a href=\"http://localhost/.php\" target=\"_blank\">$row[2]</a> </font></td>\n";
                     
                                  
                    print "\t<td><font face=arial size=1/>$row[3]</font></td>\n"; 
                    print "\t<td><font face=arial size=1/>$row[4]</font></td>\n"; 
           
         print "</tr>\n"; 
     }
          print "</table>\n";  
    
    ?>
    </body> 
    </html>
    with this code i get an output(in the form of a table)
    Code:
    1	mst	 786	                                32543655768	true
    2	pst	 567                             	435604280349	true
    3	tat	 345,56	                                463139621081	true
    4	wat	form 12,form 24,form 14	                32649342018	true

    but then i want to have separate hyperlinks for the strings in the 2nd cell of each row i.e and i want them all in one cell only

    Code:
    1	mst	 786	                                32543655768	true
    2	pst	 567                           	435604280349	true
    3	tat	345,56	                                463139621081	true
    4	wat	form 12,form 24,form 14                  32649342018	true

    So .plz could someone help me wid this ...extremely urgent

  2. #2
    Join Date
    Jul 2006
    Posts
    497
    Thanks
    8
    Thanked 70 Times in 70 Posts

    Default

    Do the links go to separate URLs? If so, how are they defined?

    All you need to do if the links point to the same place is split the text, link the pieces, and put them back together. Separate URLs will probably involve str_replace.
    -- Chris
    informal JavaScript student of Douglas Crockford
    I like wikis - a lot.

  3. #3
    Join Date
    Jun 2009
    Posts
    8
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default

    well..yes all the links would be point to the same url..
    and i have been trying to do the same way as u have told me too.


    Code:
    $result = mysql_query("SELECT taxtype.taxtypeid,taxname,group_concat(formno),actid,taxtype.status as formnum  FROM taxtype,taxform where taxtype.taxtypeid=taxform.taxtypeid group by taxtypeid")or die(mysql_error());
    $num_rows = mysql_num_rows($result);
    echo "<BR>" . $num_rows;
    print "<table width=500 border=1>\n"; 
    while($row = mysql_fetch_row($result))
    {
         
         print "<tr>\n";
       
                    print "\t<td><font face=arial size=1/>$row[0]</font></td>\n"; 
                    print "\t<td><font face=arial size=1/>$row[1]</font></td>\n"; 
                   $forms=explode(",",$row[2]);
                   $size= count($forms);
                    echo "<BR>" . $size;
                                   
                     for ($i=0;$i<$size;$i++)
                       {
                           print "\t<td><font face=arial size=1/> <a href=\"http://localhost/.php\" target=\"_blank\">$forms[$i]</a> </font></td>\n";
                       }
                                  
                    print "\t<td><font face=arial size=1/>$row[3]</font></td>\n"; 
                    print "\t<td><font face=arial size=1/>$row[4]</font></td>\n"; 
           
         print "</tr>\n"; 
     }
          print "</table>\n";

    when i do this way i get an output(in the form of a table)i.e all of them displayed in different cells
    Code:
    1	mst	 786	         32543655768	      true
    2	pst	 567             435604280349	      true
    3	tat	 345             56	              463139621081	true
    4	wat	form 12          form 24              form 14           32649342018	true
    and please could also tell whther thr is any other way to split the text,and how to again combine them ?

  4. #4
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    if the problem is only that its writting multiple cells try this
    Code:
    print "\t<td>";
    for ($i=0;$i<$size;$i++)
                       {
                           print "\t<font face=arial size=1/> <a href=\"http://localhost/.php\" target=\"_blank\">$forms[$i]</a> </font>\n";
                       }
    print "</td>";

  5. The Following User Says Thank You to bluewalrus For This Useful Post:

    padmaharika (06-21-2009)

  6. #5
    Join Date
    Jul 2006
    Posts
    497
    Thanks
    8
    Thanked 70 Times in 70 Posts

    Default

    Why do you want another way to split the text? Anyway, see the See Also section here.

    As for putting the pieces back together, you've shown that to be unnecessary. I was thinking of how to build a function to call for this, outputting the same kind of value as was input. Printing the data directly removes this need.
    -- Chris
    informal JavaScript student of Douglas Crockford
    I like wikis - a lot.

  7. The Following User Says Thank You to Jesdisciple For This Useful Post:

    padmaharika (06-21-2009)

  8. #6
    Join Date
    Jun 2009
    Posts
    8
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default

    thank u a lot bluewalrus and jedisciple ,it am geting the output in the required form

    noe my o/p is

    Code:
    1	mst	 786	                                32543655768	true
    2	pst	 567                           	        435604280349	true
    3	tat	 345 56	                                463139621081	true
    4	wat	 form 12 form 24 form 14                 3649342018	true

    but how to i separate them with commas,like in the 3rd row ,3rd cell..i would like to have
    Code:
    345,56
    one way i know is using implode ,but i m not knowing how to use it in the hyperlink tag while printing

  9. #7
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    You can just put it in after the link like this I think no need for implode.

    PHP Code:
    print "\t<td>";
    for (
    $i=0;$i<$size;$i++)
                       {
                           print 
    "\t<font face=arial size=1/> <a href=\"http://localhost/.php\" target=\"_blank\">$forms[$i]</a>, </font>\n";
                       }
    print 
    "</td>"

  10. The Following User Says Thank You to bluewalrus For This Useful Post:

    padmaharika (06-21-2009)

  11. #8
    Join Date
    Jul 2006
    Posts
    497
    Thanks
    8
    Thanked 70 Times in 70 Posts

    Default

    If you don't want a comma after the last link...
    PHP Code:
    for($i 0$i count($forms); $i++)
        
    $forms[$i] = "<font face=arial size=1/><a href=\"http://localhost/.php\" target=\"_blank\">$forms[$i]</a></font>";

    echo 
    "\t" implode(', '$forms) . "\n"
    -- Chris
    informal JavaScript student of Douglas Crockford
    I like wikis - a lot.

  12. The Following User Says Thank You to Jesdisciple For This Useful Post:

    padmaharika (07-04-2009)

  13. #9
    Join Date
    Jun 2009
    Posts
    8
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default

    well ,i would like to have a little more help from u ..

    Code:
     print "\t<td>";
    for ($i=0;$i<$size;$i++)
                       {
                           print "\t<font face=arial size=1/> <a href=\"http://localhost/.php\" target=\"_blank\">$forms[$i]</a>, </font>\n";
                       }
    print "</td>";
    in this code when i click on one of the form no , it would direct me to another php page ,where i would like to retrive the value of the form number so that i can display the value.
    for example


    Code:
    1	mst	 786	                                32543655768	true
    2	pst	 567                           	        435604280349	true
    3	tat	 345  56	                            463139621081	true
    4	wat	 form 12  form 24 form 14                 3649342018	true
    So here if i click on any of the forms say 567,then when it redircts me to the another page i want to automatically display the value 567 in the next step.
    like


    Code:
    FORM no: 567
    NAME:.
    ADDRESS:
    ....
    so plz could you help me doing this.

  14. #10
    Join Date
    Jul 2006
    Posts
    497
    Thanks
    8
    Thanked 70 Times in 70 Posts

    Default

    Should links on lines with multiple links display different information when clicked?

    Either way, when you wrap the form's name in a link, change the target of the link to include a GET value. To put different forms behind different links, it could be .php?form=$form[$i].
    -- Chris
    informal JavaScript student of Douglas Crockford
    I like wikis - a lot.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •