Ashish
Ashish

Reputation: 33

I have facing the issue in array

i have facing the problem in this code. i have written the code and also attached the screenshot which you have to clear more after looking the screenshot. when you have to see the screenshot please see the update query and showing sequence value is wrong.

But i think sequence value is showing which check-box is tick.

This is the sequence array:

Array
(
    [0] => 09
    [1] => 45
    [2] => 76
)

this is the checkbox value:

Array
(
    [0] => 1
    [1] => 3
)

when i am updating the query checkbox value is showing correct but sequence value is showing wrong.

     <table id="contentTable"> 

    													  <tr> 
                                                            <td  id="formCreateLabel">
                                                            <label for="learnTabname"><strong>Show on Home page</strong></label></td>
                                                            <td id="formCreateLabel" style="float: left"><strong>Testimonial Name</strong></td>
                                                            <td><strong>Sequence</strong></td>
                                                          </tr>

    <?php	for ($counter=1; $counter<=4; $counter++) {?>
    <tr>
                                                              <td  align="center" ><input type="checkbox" name="t1[]" value="<?php echo $counter;?>" id="t1[]" <?php if($row_getThisRecord['isFeatured']==1){ ?>  checked="checked"<?php } ?> /></td>
                                                              <td  style="float: left;margin-left:44px;"><?php echo "TEST a".$counter?></td>
                                                              <td><input type="text" style="width:30px" name="isSeq[]" value="0" id="isSeq[]"  /></td>
                                                            </tr>
             <?php }?>                                             

               </table>
[enter image description here][1] My Php code:- <?php $id = $_POST['t1']; $isSeq = $_POST['isSeq']; echo "This is the sequence array:"; echo "<pre>"; print_r($isSeq); echo "</pre>"; echo "<BR>"; echo "this is the checkbox value:"; echo '<pre>'; print_r($id); echo '<pre>'; for ($indx = 0 ; $indx < count($id); $indx ++) { $sregion=$id[$indx]; $isSequence=$isSeq[$indx]; echo $queryUpdate="update abc set isFeatured=1,isSequence='$isSequence' where abcID='$sregion'"; $updateAbc=mysql_query($queryUpdate,) or die(mysql_error()); } ?>

Upvotes: 0

Views: 66

Answers (1)

Ravi Hirani
Ravi Hirani

Reputation: 6539

Use one of below functions as per your need:-

sort() - sort arrays in ascending order
rsort() - sort arrays in descending order
asort() - sort associative arrays in ascending order, according to the value
ksort() - sort associative arrays in ascending order, according to the key
arsort() - sort associative arrays in descending order, according to the value
krsort() - sort associative arrays in descending order, according to the key

Refer this documentation for examples.

Upvotes: 0

Related Questions