How to find a variable that works?

Hi, I’m trying to remove the table head from this table if the customer hasn’t made a RMA request. I’ve been trying everything I know with no luck. Can someone take a look at it for me.

<?php $result = $this->getRmaList(); ?>
<div class="page-title title-buttons">
    <h2><?php echo $this->__('Request For Return Merchandise Authorization (RMA)') ?></h2>
</div>
<a href="<?php echo Mage::helper('core/url')->getHomeUrl(); ?>rma/index/request">
<h4 align="right"><?php echo $this->__('Add New RMA') ?></h4></a>

<table class="data-table" id="my-orders-table">
<thead>
<tr class="first last">
<th><?php echo $this->__('RMA') ?></th>
<th><?php echo $this->__('RMA #') ?></th>
<th><?php echo $this->__('Order #') ?></th>
<th><?php echo $this->__('Date') ?></th>
<th><span class="nobr"><?php echo $this->__('Status') ?></span></th>
<th><?php echo $this->__('Return Type') ?></th>
</tr>
</thead>
<tbody>
<?php while($resultn = $result->fetch(PDO::FETCH_ASSOC)){
	$dateTimestamp = Mage::getModel('core/date')->timestamp(strtotime($created_time));
    extract($resultn);
        echo "<tr class='first odd'>
		    <td><a href=". Mage::helper('core/url')->getHomeUrl() ."rma/index/view/rma_id/$rma_id>View Details</a></td>
            <td>$rma_id</td>
            <td><span class='nobr'><a href=". Mage::helper('core/url')->getHomeUrl() ."sales/order/view/order_id/$order_id>$increment_id<?a></span></td>
            <td>". date('F j, Y g:i a', $dateTimestamp) ."</td>
            <td><span class='price'>$adminstatus</span></td>
            <td class=''>
            <span class='nobr'>$return_type</span></td>
</tr>"; 
} ?>
</tbody>
</table>[/code]

How would I go about it? I've tried things like: [code]<?php if ($result): ?>[/code]that didn't work. I guess I need to find a variable that works, that's what I've been trying. 

Thanks

Try var_dump( $result ); and there should be a row count that can be tested before outputting the headers.

<?php var_dump( $result ); ?> <?php echo ( $result = ["multiline_count"] ); ?>

outputs Array. I must be doing it wrong?

well that’s assigning an array to $result so you’d expect it to echo that it is an Array.

Try wrapping the var_dump(…); inside echo '<pre>'; and echo '</pre>'; to make $result; easier to read then post the output.

Thanks for the help.

Here’s what I finally done. Still testing but seems to work well.

[code]

<?php echo $this->__('RMA') ?> <?php echo $this->__('RMA #') ?> <?php echo $this->__('Order #') ?> <?php echo $this->__('Date') ?> <?php echo $this->__('Status') ?> <?php echo $this->__('Return Type') ?> [/code]

Are you sure view-source doesn’t show a row of empty cells that are still in the DOM?

display: none to display: block will work.

But if you have subsequent CSS rules that target them you may have unexpected results.

@Mittineague

I’m just trying to hide it some way for anyone who doesn’t have a RMA.

On that first line of your code, there doesn’t seem to be any reason to keep jumping in and out of PHP like that. Can’t you just use:

<tr class="first last" style="display:none;<?php while($resultn = $result->fetch(PDO::FETCH_ASSOC)): extract($resultn); if ($rma_id) echo 'display:block'; endwhile; ?>">

Doesn’t running through the while() loop at that position ruin it for the lower section where you actually want those results to display in the table body?

Is there a way you can get the result count for the query before you start the table, and just wrap the entire table in an if() clause? So assuming the query has already run:

<?php $result = $this->getRmaList(); ?>
<div class="page-title title-buttons">
    <h1><?php echo $this->__('Request For Return Merchandise Authorization (RMA)') ?></h1>
</div>
<a href="<?php echo Mage::helper('core/url')->getHomeUrl(); ?>rma/index/request">
<h4 align="right"><?php echo $this->__('Add New RMA') ?></h4></a>

<?php if ($result->rowCount > 0) { ?>

<table class="data-table" id="my-orders-table">
<thead>
<tr class="first last">
<th><?php echo $this->__('RMA') ?></th>

and then close the if after the </table> tag? Or if it’s just the <thead> block you want to lose, then stick the if() around that part instead?

I finally got it or at least something that worked.

[code]<?php $result = $this->getRmaList(); ?>

<?php while($resultn = $result->fetch(PDO::FETCH_ASSOC)): ?> <?php extract($resultn); ?> <?php if(isset($rma_id)){ $hasReturns = 1; } ?> <?php endwhile; ?> <?php if (!$hasReturns): ?>

some stuff

<?php endif ?> <?php if ($hasReturns): ?>

other stuff

<?php endif ?>[/code]

then another while

[code]

<?php $result2 = $this->getRmaList(); ?>[/code]

Your abstraction is leaked. there should be no database layer related code in the presentation.Besides, I assume your code is running a query twice.

The getRmaList() method should return an array, and thus instead of

return $stmt;

it should return

return $stmt->fetchAll(PDO::FETCH_ASSOC);

while in the presentation code you can make it

<?php $result = $this->getRmaList(); ?>
<?php foreach ($result as $resultn: ?>

and then another foreach without calling getRmaList() again

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.