Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 4 of 4
  1. #1
    Member Anant's Avatar
    Join Date
    Feb 2005
    Location
    Indore , India
    Posts
    50
    Member #
    9049
    hello..

    i have this code ..which display me the content i ahve in my table ...


    <?php
    // Make a MySQL Connection
    mysql_connect("localhost", "root", "anant") or die(mysql_error());
    mysql_select_db("couns") or die(mysql_error());

    // Get all the data from the "example" table
    $result = mysql_query("SELECT * FROM coun group by RANK")
    or die(mysql_error());

    echo "<table border='0' cellpadding='1' align=center>";
    echo "<tr> <th bgcolor='#808080'><font size=4 color=black font=verdana>Serial No.</font></th> <th bgcolor='#808080'><font size=4 color=black font=verdana>Name</font></th> <th bgcolor='#808080'><font size=4 color=black font=verdana>Status</font></th><th bgcolor='#808080'><font size=4 color=black font=verdana>Roll Number</font></th> <th bgcolor='#808080'><font size=4 color=black font=verdana>Rank</font></th><th bgcolor='#808080'><font size=4 color=black font=verdana>Gender</font></th> <th bgcolor='#808080'><font size=4 color=black font=verdana>Category</font></th> <th bgcolor='#808080'><font size=4 color=black font=verdana>Sub Category</font></th> <th bgcolor='#808080'><font size=4 color=black font=verdana>Course Offered</font></th><th bgcolor='#808080'><font size=4 color=black font=verdana>Allotment</font></th></tr>";
    // keeps getting the next row until there are no more to get
    while($row = mysql_fetch_array( $result )) {
    // Print out the contents of each row into a table
    echo "<tr bgcolor='#ffa642'><td bgcolor='#ffa642' align=center><font size=3 color=black font=verdana>";
    echo $row['id'];
    echo "</font></td><td align=center><font size=3 color=black font=verdana>";
    echo $row['Name'];
    echo "</td><td align=center><font size=3 color=black font=verdana>";
    echo $row['Status'];
    echo "</td><td align=center><font size=3 color=black font=verdana>";
    echo $row['Roll_no'];
    echo "</td><td align=center><font size=3 color=black font=verdana>";
    echo $row['Rank'];
    echo "</td><td align=center><font size=3 color=black font=verdana>";
    echo $row['Gender'];
    echo "</td><td align=center><font size=3 color=black font=verdana>";
    echo $row['category'];
    echo "</td><td align=center><font size=3 color=black font=verdana>";
    echo $row['sub_cat'];
    echo "</td><td align=center><font size=3 color=black font=verdana>";
    echo $row['course'];
    echo "</td><td align=center><font size=3 color=black font=verdana>";
    echo $row['allotment'];
    echo "</td></tr>";
    }
    echo "</table>";

    ?>



    my problem is that ...i want to have a check box before each row ...and if i check that box , then all the checked content must go in some other table ...all this must happen after i click a submitt button...

    pls help me out

  2.  

  3. #2
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    Im not sure on this because there could be say 5 or 50 checkboxex checked.

    But what you would do is name all your checkboxes the same name, such as copy (as your copying content from one table to another[/b].

    And set each checkboxes value to the value of that row in the database table. So if your table has 5 rows, the first checkbox would be of id 1, and so on upto 5.

    Then, you would check that $_POST['copy'] or $_GET['copy'] is set and is not empty. If its set and not empty, extract the row with that id.

    As I say I am not sure on how to go about the multiple checked.

  4. #3
    Senior Member rosland's Avatar
    Join Date
    Jul 2003
    Location
    Norway
    Posts
    1,944
    Member #
    2096
    Quote Originally Posted by Anant
    my problem is that ...i want to have a check box before each row ...and if i check that box , then all the checked content must go in some other table ...all this must happen after i click a submitt button...
    With "some other table", do you mean a new HTML table (that is presented on-screen) or do you want to transfer that particular row to another (mysql)table?

    -------

    BTW, to make your code less verbose, you should let PHP analyze your table and draw up the table headers, instead of hardcoding them with fixed header text like you've done ("Name", "Status", "Roll number", "Rank"... etc).

    The best way is to give the different HTML elements distinct names, that way you can utilize CSS to do the formatting/presentation for you.
    If you're unfamiliar/uncomfortable with CSS, you can use old-school element formatting like you've done.
    However, you will only have to write your "<font size="X" color="X"...> " ONCE, as the script will regurgitate this for each loop you ask it to perform.

    That also makes your code more portable. With your present code you can only select a predefined table, as all the table headers are predefined in your code. With a more flexible code, you could re-use that code to fit any table.

    A short example on how to draw up a randomly selected table:
    PHP Code:
                 for ($i 0$i mysql_num_fields($result); $i++) 
                 {
                     
                     echo(
    "<th><HTML-formating-stuff>" mysql_field_name($result,$i) . 
                     
    "<closing-tags></th>");
                 }
         echo 
    "</tr>"
    S. Rosland

  5. #4
    Senior Member
    Join Date
    Jun 2005
    Location
    Atlanta, GA
    Posts
    4,146
    Member #
    10263
    Liked
    1 times
    I think, with PHP, you'd have to name it copy[] in order to move it into an array. I can't be 100% sure, I know this is how it works with select boxes that allow multiple selection.


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 07:24 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com