Results 1 to 4 of 4

Thread: Should be simple

  1. #1
    Join Date
    Feb 2008
    Location
    Coventry
    Posts
    103
    Thanks
    5
    Thanked 8 Times in 8 Posts

    Default Should be simple

    Hi guys its time for me to ask a question now...

    Im trying to update many rows at once. My problem is of course how.

    Il show you.

    PHP Code:
    if (mysql_num_rows($insert_query) >) {
        
    //build headers
        
    $header .= "<table border='1' bordercolor='#cccccc' cellspacing='0' cellpadding='3'>";
        
    $header .= "<th bgcolor='#cccccc'>ID</th><th bgcolor='#cccccc'>First Name</th><th bgcolor='#cccccc'>Surname</th><th bgcolor='#cccccc'>Email</th><th bgcolor='#cccccc'>Paid?</th>";
        echo 
    $header;
        
    //display information
        
    while($row mysql_fetch_assoc($insert_query)) {
        echo 
    '<tr><td>'.$row['ID'].'</td>';
        echo 
    '<td>'.$row['first_name'].'</td>'
        echo 
    '<td>'.$row['surname'].'</td>';
        echo 
    '<td>'.$row['email'].'</td>';
        echo 
    '<td></td></tr>';
    }
    echo 
    "</table>";

    So now at the minute i want a tick box to go in that end space. So that requires me to have a form.
    That may mean i have a form for each loop, or i have a form for the whole thing and i set the checkbox to be an array and process it that way.

    Is it possible to do something like UPDATE SET Edited = 'Y' WHERE ID '1,3,5' ie the numbers that are in the value of the checkbox?

    Il be very grateful if anyone can just show me how, i know its completely possible, even if it requires a bit of javascript, but i would still prefer it to be php.

    Also i would like to be able to have a checkboxbox at the top that selects all of the other checkboxes, that i know can be done in simple javascript but requires one form right??
    The important thing is not to stop questioning. Curiosity has its own reason for existing.

  2. #2
    Join Date
    May 2007
    Location
    England, UK
    Posts
    235
    Thanks
    3
    Thanked 6 Times in 6 Posts

    Default

    You could just use one form if you put it outside the while statement

    e.g.
    PHP Code:
    <?php 
    if (mysql_num_rows($insert_query) >) { 
        
    //build headers 
        
    $header .= "<table border='1' bordercolor='#cccccc' cellspacing='0' cellpadding='3'>"
        
    $header .= "<th bgcolor='#cccccc'>ID</th><th bgcolor='#cccccc'>First Name</th><th bgcolor='#cccccc'>Surname</th><th bgcolor='#cccccc'>Email</th><th bgcolor='#cccccc'>Paid?</th>"
        echo 
    $header
        
    //display information 
    ?> 
    <form action="mypage.php" method="post">
     <?php   
    while($row mysql_fetch_assoc($insert_query)) { 
        echo 
    '<tr><td>'.$row['ID'].'</td>'
        echo 
    '<td>'.$row['first_name'].'</td>';  
        echo 
    '<td>'.$row['surname'].'</td>'
        echo 
    '<td>'.$row['email'].'</td>'
        echo 
    '<td><input type="hidden" value="'.$row['ID'].'" name="id[]" /><input type="checkbox" name="check[]" /></td></tr>'

    ?>
    </form>
    <?php
    echo "</table>"

    ?>
    If you use name="id[]" it will put each value into an array.

    This means when you submit this form you should have two arrays, one called id and one called check. you can then use those to enter into the database

  3. #3
    Join Date
    Apr 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Here is the checkbox update

    Code:
    <?  
      	include ("db1.php");
    	$cxn = @ConnectToDb($dbServer, $dbUser, $dbPass, $dbName);
    	$query1="select * from manufacturers";
     	$sqlres1 = mysql_query($query1);
      	 $count=mysql_num_rows($sqlres1);
    	 $i=0;
    	while($rows=mysql_fetch_array($sqlres1))
      	{
    	
     ?>
        <tr><td align="center"><input name="checkbox1<? echo $i;?>" type="checkbox"  value="<? echo $rows['manufacturers_id']; ?>"></td>
        <td><input type="text" name="manufacturer<? echo $i;?>" value="<? echo $rows['manufacturers_name']; ?>" /></td>
       <td><input type="checkbox<? echo $i;?>" name="AVAIL" value="" checked="checked" /></td> <td><a tabindex="-1"  class="style1" href="javascript:var popup2=window.open('getinfo.php?action=manufacturer&id=<? echo $rows[ 
    	                        'manufacturers_id']; ?>','Manufacturer','width=400, height=400,location=no,menubar=no,status=no, toolbar=no,  
                                scrollbars=yes,resizable=yes');">Details</a></td>
        <!--<td>< ? echo $fetch1['item_price'];?></td>--></tr>
        <? 
    	$i++;
    	}
    	if(isset($_POST['edit']) && ($_POST['edit']=='Edit'))
    {
    for($i=0;$i<$count;$i++)
    {
    if(isset($_POST['checkbox1'.$i]))
    {
     $y=$_POST['manufacturer'.$i];
     $ssql = "update manufacturers set manufacturers_name='".$y."' where manufacturers_id=".$_POST['checkbox1'.$i];
     $rresult = mysql_query($ssql);
    }
    }
    // if successful redirect to delete_multiple.php
    if($rresult){
    echo "<meta http-equiv=\"refresh\" content=\"0;URL=manufacturer.php\">";
    }
    }
    mysql_close();
    #--------------------- End of Updation ---------------
    ?>
    Last edited by tech_support; 04-25-2008 at 04:57 AM. Reason: Wrapped code in [code][/code] tags.

  4. #4
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    @ravi
    Please refer to our Posting Policies and Regulations especially in regards to #8

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
  •