0

In Table, If the cell value of row is "Undelivered" , then I want to hide complete row. Below table is displaying in .php page

enter image description here

Original code :

<tr>
  <td><?php echo $orderrecords[$k]["order_id"]; ?></td>

  <td>
<?php
$url = 'https://plapi.ecomexpress.in/track_me/api/';
$ch = curl_init();                    
curl_setopt($ch, CURLOPT_URL,$url);
$output = curl_exec ($ch); 
curl_close($ch);

$res = explode("\n",$output);
echo $res[13];
?> 
 </td>  

</tr>

Initially I tried with CSS as Jsfiddle :

<tr>
  <td><?php echo $orderrecords[$k]["order_id"]; ?></td>


  <td>
 <input type='text'  value=
"<?php
$url = 'https://plapi.ecomexpress.in/track_me/api/';
$ch = curl_init();                    
curl_setopt($ch, CURLOPT_URL,$url);
$output = curl_exec ($ch); 
curl_close($ch);

$res = explode("\n",$output);
echo $res[13];
?> "/>
 </td>  

</tr>


<style>
input[type='text'][value='Undelivered'] {
  display: none;
}
</style>

Than I tried with Javascript as below :

<tr>
  <td><?php echo $orderrecords[$k]["order_id"]; ?></td>

  <td class="sold">
<?php
$url = 'https://plapi.ecomexpress.in/track_me/api/';
$ch = curl_init();                    
curl_setopt($ch, CURLOPT_URL,$url);
$output = curl_exec ($ch); 
curl_close($ch);

$res = explode("\n",$output);
echo $res[13];
?> 
 </td>  

</tr>

<script>
$("td.sold").filter(function() {         
     return +$(this).text().trim() === 'Undelivered';         
}).parent().hide();
</script>

Finally I tried with PHP as below, but i did't got solution :

<tr class="<?= $res[13] == 'Undelivered' ? 'hidden' :'';?>">
  <td><?php echo $orderrecords[$k]["order_id"]; ?></td>

  <td>
<?php
$url = 'https://plapi.ecomexpress.in/track_me/api/';
$ch = curl_init();                    
curl_setopt($ch, CURLOPT_URL,$url);
$output = curl_exec ($ch); 
curl_close($ch);

$res = explode("\n",$output);
echo $res[13];
?> 
 </td>  

</tr>

Please help me to find solution....

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
fresher
  • 917
  • 2
  • 20
  • 55
  • 1
    I don't know curl but some idea maybe : add a class to your row when it's "undelivered" and in css make a "display:none" for this class, in PHP you can test the result for each row you build and when "undelivered" you just don't build the row and in JS you can just check the result of each row for the column status and when it's "undelivered" you hide() the row maybe? – Mickaël Leger Feb 16 '18 at 10:13
  • @MickaelLeger Thanks for suggestions, in css , i can't add a `class` to row when it's `undelivered` because i am getting values dynamically.... – fresher Feb 16 '18 at 10:23
  • You can't make a test in php for your status value for each row? for example `` ? I don't know how you can get this status value, but if you can just test and create the row only if not "undelivered". You can add your html in your php so you won't have empty in you do so – Mickaël Leger Feb 16 '18 at 10:29
  • @MickaelLeger i got this result : https://prnt.sc/ifj4is – fresher Feb 16 '18 at 11:05
  • About your php error : https://stackoverflow.com/questions/9869150/illegal-string-offset-warning-php – Mickaël Leger Feb 16 '18 at 11:27
  • And if you want the row to not be build, you should make your test if (status !== "Undelivered") BEFORE the . Try to loop throught your $orderrecord with a foreach and make some var_dump($key) / var_dump($value), find where and how get your "status" value and when you know it, make the test before starting a new row (tr). Is it clear enough? – Mickaël Leger Feb 16 '18 at 11:30
  • I tried to post an anwser, but it's hard because we can't see the value of `$orderrecords[$k] ` ! – Mickaël Leger Feb 16 '18 at 11:48
  • @MickaelLeger thanks , i am fetching order records status through api..... – fresher Feb 16 '18 at 11:50
  • i got this result : http://prntscr.com/ifjt55 – fresher Feb 16 '18 at 11:55
  • As I said, I can't write your code for you since I can't test it with your database, etc. So FIRST : try to get your status value and be sure of the exact output ("Undelivered"? other?), SECOND : get this value BEFORE creating a new row and test it. If you get "Undelivered" you just do nohting. THIRD : build a normal row as you do. BUT CARE : you have some PHP error with "res['13']" so solve this too – Mickaël Leger Feb 16 '18 at 12:03
  • @MickaelLeger Thanks a lot for your valuable time, JoeP's solution worked for me..... – fresher Feb 16 '18 at 12:08
  • Ok cool ! Sad I couldn't find it myself :( ++ – Mickaël Leger Feb 16 '18 at 12:33

3 Answers3

1

Am not sure if am understanding your problem statement, to sail clear, you mean you have a table: eg

<table>
            <tr><td>Name</td><td>Surname</td><td>Age</td></tr>
            <tr><td>John</td><td>Doe</td><td>33</td></tr>
            <tr><td>Undelivered</td><td>Piper</td><td>Age</td></tr>
            <tr><td>Yonna</td><td>Cheng</td><td>Age</td></tr>
        </table>

And you want to hide the whole row if there is and cell that has data in it like in the third row above? Or you want to hide an input textbox.

Mr Nsubuga
  • 300
  • 3
  • 7
1

Whilst it's not really clear how your application is working, presumably because a lot is omitted, the following will probably work for you, if your examples above do work other than hiding the row.

<?php
$hide = '';
$url = 'https://plapi.ecomexpress.in/track_me/api/';
$ch = curl_init();                    
curl_setopt($ch, CURLOPT_URL,$url);
$output = curl_exec ($ch); 
curl_close($ch);

$res = explode("\n",$output);
$status = $res[13];
if(strstr($status, "Undelivered") !== false)
    {
    $hide .= 'style="display: none;"';
    }
?>
<tr <?php echo $hide;?>>
  <td><?php echo $orderrecords[$k]["order_id"]; ?></td>
  <td><?php echo $status;?></td>  
</tr>

In your own attempt at the PHP solution, you're attempting check the value of $res[13] before it exists. At best, this would check the value of a previous explosion. You cannot get $res[13] until you've performed $res = explode("\n",$output), because it doesn't exist until then.

Edited to change = to strstr, as the returned value is a full XML tag and not just the word "Undelivered"

JoeP
  • 856
  • 4
  • 15
  • 29
  • Thanks , i tried your code as here : https://pastebin.com/5g9dwY4H still getting same result, seems i missed something , please check pastebin code..... – fresher Feb 16 '18 at 10:47
  • You are setting the `$hide` variable incorrectly. You have set to `echo` ` – JoeP Feb 16 '18 at 10:51
  • Change it to just ` class="table-row" id="table-row-" tabindex="">` – JoeP Feb 16 '18 at 11:00
  • This is because you're actually getting a full XML row, not just the word Undelivered, so you'll need to use `if(strstr($status, "Undelivered") !== false)` instead. I'll update the answer now. – JoeP Feb 16 '18 at 12:00
  • 1
    Use `if(strstr($status, "Undelivered") !== false || strstr($status, "Delivered / Closed") !== false)` – JoeP Feb 16 '18 at 12:26
  • You're welcome. By the way, I would suggest that you get rid of all of your shared paste pins from the discussions with me, and the other people that have been trying to help, because you've included your username and password in them – JoeP Feb 16 '18 at 12:42
  • sorry to disturb you again, one more help need, what i need to use to hide row if value is `empty` instead of `undelivered` as like here : https://prnt.sc/ifl3c6 , how to hide row of `99533`.... – fresher Feb 16 '18 at 13:44
  • You could use `if(strstr($status, "Undelivered") !== false || strstr($status, "Delivered / Closed") !== false || $status == "")`, but I think the reason that it's blank is that you are not getting a response for that one. If you have error reporting turned on, you'll see that it's actually caused by an error, not that it's blank. – JoeP Feb 16 '18 at 14:00
  • Thanks a ton , yes it working fine now, also as you said its getting blank because thats wrong order id.... – fresher Feb 16 '18 at 14:06
  • i need one more help, can you please help me ? – fresher Feb 28 '18 at 11:34
1

As I said in the comment I don't really know curl and don't know how you get your "status" value, but you can try somehting like this maybe to test if the status value is "undelivered" BEFORE you start building your row :

<table class="tbl-qa" border="1">
  <thead>
    <tr>            
      <th class="table-header">ID
      </th>
      <th class="table-header">ORDERID
      </th>            
      <th class="table-header">Status
      </th>          
    </tr>
  </thead>
  <tbody id="table-body">

<?php
  $tabindex=1;
  if(!empty($orderrecords))
  {
      foreach($orderrecords as $k=>$v)
  {

    $data['awb']='890927143';
    $url = 'https://plapi.ecomexpress.in/';
    $ch = curl_init();                    // initiate curl
    curl_setopt($ch, CURLOPT_URL,$url);
    curl_setopt($ch, CURLOPT_POST, true);  // tell curl you want to post something
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data); // define what you want to post
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // return the output in string format
    $output = curl_exec ($ch); // execute
    curl_close($ch);
    $res = explode("\n",$output);
    echo $res[13];
    if($orderrecords[$k]["order_id"][$res[13]] !== "Undelivered") // BE SURE TO GET YOUR STATUS VALUE HERE + check if you need to use U or u, etc.
    {
      <- you build your row ->
    }
  } // end foreach
} // end if
?>
        </thead>
    </tbody>
</table>
Mickaël Leger
  • 3,426
  • 2
  • 17
  • 36
  • The user is actually exploding an XML file, so the actual value of `$res[13]` is something along the lines of `Delivered / Closed` – JoeP Feb 16 '18 at 12:05