tags:

views:

56

answers:

2

I an issue that has me completely stumped.

I am simply running a simple query with one parameter, putting the results in an array, and then looping through the array to display the information in a table.

I will post the code at the end, though it is kind of dense, but mostly I'd liek to know what would cause a php script to die with no error?

I would like to note that after the mysql info is put into an array, I print it out right before the foreach loop, and all the info displays.

I have error reporting turned on.

The error only occurs on queries with certain parameters, but not others.

The error does not always occur in the same place, but it does always occur. As it goes through the records, it stops at a random point after a few records have been drawn into the table.

I don't believe it could be an issue with my functions, as it would give an error.

Anyway, I hope I am making some stupid oversight. I'd appreciate any feedback.

<?php if(isset($_SESSION['submit']) && $_SESSION['search_param'] != ''){ ?>

<br />
<br />

<table id="results_box" cellpadding="0" cellspacing="0">

<?php $bg = 'alt2'; ?>

<?php //echo '<pre>',print_r($results['rows']),'</pre>'; ?>

<?php foreach( $results['rows'] as $row){ ?>

    <?php $podcasts = getRelatedPodcasts('item',$row['record_id']); ?>
    <?php $images = getRelatedImages('item',$row['record_id']); ?>
    <?php $main_image = getAndShowMainImage('item',$row['record_id'],'mini'); ?>
    <?php $color_class = str_replace(' ','-',$row['category']); ?>
    <?php $people = getRelatedPeople('item',$row['record_id']); ?>

    <?php $bg = ($bg == 'alt2' ? 'alt1' : 'alt2'); ?>

    <tr class="<?php echo $bg; ?>" onClick="Link('index.php?page=entry&permalink=<?=$row['record_id']; ?>')">
    <td class="leftrows <?=$color_class?>">
    <?=$main_image?>
    </td>
    <td class="next-to-leftrows " width="25%">
    <div class="text-headroom">
    <font class="title-medium">
    <?php echo highlight($row['name_title'],$_SESSION['search_param']); ?>
    </font>
    <br />
    <span class="small">
    <?=highlight($row['city'],$_SESSION['search_param'])?>, <?=$row['state']?> 
    &bull; <?=highlight($row['category'],$_SESSION['search_param'])?>
    </span>
    </div>
    </td>
    <td class="rows" width="25%">
    <div class="text-headroom">
    <ul class="small">
    <?php 
    foreach($people['record_ids'] as $key => $person){ ?>
        <li><?=highlight(getPersonName($person,'FL'),$_SESSION['search_param'])?></li>
    <?php } ?>
    </ul>
    </div>
    </td>
    <td class="rows small" width="45%"><?php echo constrainLongText($row['remarks'],150); ?></td>
    <td class="rightrows small" align="right" width="25">
    <?php if($podcasts['count'] > 0){ ?>
        <img src="ui/images/headphones.png" />
    <?php } ?>
    </td>
    </tr>

<?php }

} // end if submit for results ?>

</table>
+1  A: 

You say that no error is given, but you mention an error later on. Is the error "the rest of my table doesn't show up" or something like that?

Have you examined the output source to see where it ends?

Maybe there is some invalid characters being printed, which could in turn break the rest of the HTML. You might want to look into HTML sanitation (if you aren't elsewhere). Try looking at htmlspecialchars()

As a side note, your code is pretty difficult to read as it is. You don't need to use <?php and ?> so much, you can contain your PHP code within fewer sets of them instead of having them on every line.

You may also want to be more consistent with <?= and <?php echo. Personally I stay away from the shorthand version, shorthand could be not allowed by some web servers.

Edit: Here is a cleaned up version of your code. Every programmer has their own way to format code, so do as you wish with it...

<?php
if (isset($_SESSION['submit']) && (!empty($_SESSION['search_param'])) {
    echo <<<EOT
<br />
<br />
<table id="results_box" cellpadding="0" cellspacing="0">
EOT;
    $bg = 'alt2';
    //echo '<pre>',print_r($results['rows']),'</pre>';
    foreach ($results['rows'] as $row){
        $podcasts    = getRelatedPodcasts('item', $row['record_id']);
        $images      = getRelatedImages('item', $row['record_id']);
        $main_image  = getAndShowMainImage('item', $row['record_id'],'mini');
        $color_class = str_replace(' ', '-', $row['category']);
        $people      = getRelatedPeople('item', $row['record_id']);
        $bg          = ($bg == 'alt2' ? 'alt1' : 'alt2');

        $record_id            = $row['record_id'];
        $state                = $row['state'];
        $highlight_name_title = highlight($row['name_title'], $_SESSION['search_param']);
        $highlight_city       = highlight($row['city'], $_SESSION['search_param']);
        $highlight_category   = highlight($row['category'], $_SESSION['search_param']);
        echo <<<EOT

    <tr class="$bg" onClick="Link('index.php?page=entry&permalink=$record_id')">
        <td class="leftrows $color_class">
            $main_image
        </td>
        <td class="next-to-leftrows " width="25%">
            <div class="text-headroom">
                <font class="title-medium">$highlight_name_title</font>
                <br />
                <span class="small">
                    $highlight_city, $state &bull; $highlight_category
                </span>
            </div>
        </td>
        <td class="rows" width="25%">
            <div class="text-headroom">
                <ul class="small">
EOT;
            foreach ($people['record_ids'] as $key => $person) {
                $highlight_person = highlight(getPersonName($person, 'FL'), $_SESSION['search_param']);
                echo "<li>$highlight_person</li>";
            }

        $shortened_remarks = constrainLongText($row['remarks'], 150);
        echo <<<EOT

                </ul>
            </div>
        </td>
        <td class="rows small" width="45%">$shortened_remarks</td>
        <td class="rightrows small" align="right" width="25">
EOT;
        if($podcasts['count'] > 0){
            echo "<img src=\"ui/images/headphones.png\" />";
        }
        echo <<<EOT

        </td>
    </tr>
EOT;
    }
echo "</table>";
} // end if submit for results
?>
pferate
Cool, thank you for the help. I will give this a shot. I always appreciate seeing how others do it to help me along.thanks!
A: 

I had an issue in one of the functions, but the errors weren't appearing because of the fact that the functions were in another file. Unfortunately, my host sucks and I don't have access to the php.ini, but by eliminating each function and starting basically from scratch it became apparent where the issue was. Thank you for the pointers.