Jump to content

Recommended Posts

Non Object error

 

<?php echo '<a title="'. url_title($results->title) .'" href="' .base_url(). 'movies/review/' .$results->rid. '/' .url_title($results->title). '.html">' .$results->title. '</a> (' .$results->year. ')<br />';
//echo check_review_score($results->score);
?>

 

should I use foreach or for?

 

$results equals an array

 

where am I going wrong?

Link to comment
https://forums.phpfreaks.com/topic/96947-non-object-error/
Share on other sites

Tried your suggestions but they don't work either

 

$results['title'] gives me

A PHP Error was encountered

Severity: Notice

Message: Undefined index: title

 

$results

Array ( [0] => stdClass Object ( [rid] => 509 [title] => Fantastic Four - Rise of the Silver Surfer [year] => 2007 [score] => 4 ) [1] => stdClass Object ( [rid] => 273 [title] => Fear [year] => 1996 [score] => 8 ) [2] => stdClass Object ( [rid] => 456 [title] => Feast [year] => 2006 [score] => 9 ) [3] => stdClass Object ( [rid] => 264 [title] => Fifth Element, The [year] => 1997 [score] => 8 ) [4] => stdClass Object ( [rid] => 600 [title] => Firehead [year] => 1990 [score] => 0 ) [5] => stdClass Object ( [rid] => 181 [title] => Frailty [year] => 2002 [score] => 7 ) [6] => stdClass Object ( [rid] => 265 [title] => Frankenstein [year] => 1931 [score] => 8 ) [7] => stdClass Object ( [rid] => 75 [title] => Freddy vs Jason [year] => 2003 [score] => 8 ) [8] => stdClass Object ( [rid] => 77 [title] => Friday the 13th [year] => 1980 [score] => 9 ) [9] => stdClass Object ( [rid] => 78 [title] => Friday the 13th Part 2 (II) [year] => 1981 [score] => 7 ) [10] => stdClass Object ( [rid] => 79 [title] => Friday the 13th Part 3 (III) [year] => 1982 [score] => 7 ) [11] => stdClass Object ( [rid] => 80 [title] => Friday the 13th Part 4 (IV): The Final Chapter [year] => 1984 [score] => 7 ) [12] => stdClass Object ( [rid] => 81 [title] => Friday the 13th Part 5 (V): A New Beginning [year] => 1985 [score] => 4 ) [13] => stdClass Object ( [rid] => 82 [title] => Friday the 13th Part 6 (VI): Jason Lives [year] => 1986 [score] => 9 ) [14] => stdClass Object ( [rid] => 83 [title] => Friday the 13th Part 7 (VII): The New Blood [year] => 1988 [score] => 7 ) [15] => stdClass Object ( [rid] => 84 [title] => Friday the 13th Part 8 (VIII): Jason Takes Manhattan [year] => 1989 [score] => 6 ) [16] => stdClass Object ( [rid] => 537 [title] => From Beyond [year] => 1986 [score] => 5 ) [17] => stdClass Object ( [rid] => 85 [title] => From Dusk Till Dawn [year] => 1996 [score] => 8 ) [18] => stdClass Object ( [rid] => 86 [title] => From Dusk Till Dawn 2: Texas Blood Money [year] => 1999 [score] => 5 ) [19] => stdClass Object ( [rid] => 87 [title] => From Dusk Till Dawn 3: The Hangman's Daughter [year] => 2000 [score] => 8 ) [20] => stdClass Object ( [rid] => 88 [title] => Full Eclipse [year] => 1993 [score] => 7 ) )

 

I just want to loop through and echo out the title (year) and score

Link to comment
https://forums.phpfreaks.com/topic/96947-non-object-error/#findComment-496139
Share on other sites

If I print_r($results)

Array ( [0] => stdClass Object ( [rid] => 509 [title] => Fantastic Four - Rise of the Silver Surfer [year] => 2007 [score] => 4 ) [1] => stdClass Object ( [rid] => 273 [title] => Fear [year] => 1996 [score] => 8 ) [2] => stdClass Object ( [rid] => 456 [title] => Feast [year] => 2006 [score] => 9 ) [3] => stdClass Object ( [rid] => 264 [title] => Fifth Element, The [year] => 1997 [score] => 8 ) [4] => stdClass Object ( [rid] => 600 [title] => Firehead [year] => 1990 [score] => 0 ) [5] => stdClass Object ( [rid] => 181 [title] => Frailty [year] => 2002 [score] => 7 ) [6] => stdClass Object ( [rid] => 265 [title] => Frankenstein [year] => 1931 [score] => 8 ) [7] => stdClass Object ( [rid] => 75 [title] => Freddy vs Jason [year] => 2003 [score] => 8 ) [8] => stdClass Object ( [rid] => 77 [title] => Friday the 13th [year] => 1980 [score] => 9 ) [9] => stdClass Object ( [rid] => 78 [title] => Friday the 13th Part 2 (II) [year] => 1981 [score] => 7 ) [10] => stdClass Object ( [rid] => 79 [title] => Friday the 13th Part 3 (III) [year] => 1982 [score] => 7 ) [11] => stdClass Object ( [rid] => 80 [title] => Friday the 13th Part 4 (IV): The Final Chapter [year] => 1984 [score] => 7 ) [12] => stdClass Object ( [rid] => 81 [title] => Friday the 13th Part 5 (V): A New Beginning [year] => 1985 [score] => 4 ) [13] => stdClass Object ( [rid] => 82 [title] => Friday the 13th Part 6 (VI): Jason Lives [year] => 1986 [score] => 9 ) [14] => stdClass Object ( [rid] => 83 [title] => Friday the 13th Part 7 (VII): The New Blood [year] => 1988 [score] => 7 ) [15] => stdClass Object ( [rid] => 84 [title] => Friday the 13th Part 8 (VIII): Jason Takes Manhattan [year] => 1989 [score] => 6 ) [16] => stdClass Object ( [rid] => 537 [title] => From Beyond [year] => 1986 [score] => 5 ) [17] => stdClass Object ( [rid] => 85 [title] => From Dusk Till Dawn [year] => 1996 [score] => 8 ) [18] => stdClass Object ( [rid] => 86 [title] => From Dusk Till Dawn 2: Texas Blood Money [year] => 1999 [score] => 5 ) [19] => stdClass Object ( [rid] => 87 [title] => From Dusk Till Dawn 3: The Hangman's Daughter [year] => 2000 [score] => 8 ) [20] => stdClass Object ( [rid] => 88 [title] => Full Eclipse [year] => 1993 [score] => 7 ) )

 

I want to echo that into a two column table

Link to comment
https://forums.phpfreaks.com/topic/96947-non-object-error/#findComment-496170
Share on other sites

try

<?php
foreach($results as $result)
echo '<a title="'. url_title($result->title) .'" href="' .base_url(). 'movies/review/' .$result->rid. '/' .url_title($result->title). '.html">' .$result->title. '</a> (' .$result->year. ')<br />';
//echo check_review_score($results->score);
?>

Link to comment
https://forums.phpfreaks.com/topic/96947-non-object-error/#findComment-496190
Share on other sites

this is my current code

<?php
$results = $ltr->result();

$i = 0; $max_columns = 2;

$total = sizeof($results);
$num_rows = ($total/$max_columns);


foreach ($ltr->result() as $row):
if($i == 0): echo '<tr valign="top">'; endif;
?>
<td><?php echo '<a title="'. url_title($row->title) .'" href="' .base_url(). 'movies/review/' .$row->rid. '/' .url_title($row->title). '.html">' .$row->title. '</a> (' .$row->year. ')<br />';
echo check_review_score($row->score); ?></td>
<?
if(++$i == $max_columns): echo "</tr>"; $i=0; endif;
endforeach;

if($i < $max_columns)
{
    for($j=$i; $j<$max_columns;$j++)
        echo "<td> </td>";
}
?>

 

there is something wrong with my logic.

 

It works but errors out on some html validations depending on how many results.

 

Maybe someone can suggest a better method or maybe even a method with array_chunk

Link to comment
https://forums.phpfreaks.com/topic/96947-non-object-error/#findComment-496312
Share on other sites

try

<?php
$results = $ltr->result();
$i = 0; 
$max_columns = 2;
$total = sizeof($results);
$num_rows = ($total/$max_columns);

//foreach ($ltr->result() as $row){ you don't need to do same query again
foreach ($results as $row){
if($i == 0) echo '<tr valign="top">';
echo '<td><a title="'. url_title($row->title) .'" href="' .base_url(). 'movies/review/' .$row->rid. '/' .url_title($row->title). '.html">' .$row->title. '</a> (' .$row->year. ')<br />';
echo check_review_score($row->score),'</td>';
if(++$i == $max_columns){
	echo "</tr>"; 
	$i=0;
} // endif
}//endforeach;

if($i > 0)
{
    for($j=$i; $j<$max_columns;$j++) echo "<td> </td>";
    echo '</tr>';
}
?>

Link to comment
https://forums.phpfreaks.com/topic/96947-non-object-error/#findComment-496558
Share on other sites

try

<?php
$results = $ltr->result();
$i = 0; 
$max_columns = 2;
$total = sizeof($results);
$num_rows = ($total/$max_columns);

//foreach ($ltr->result() as $row){ you don't need to do same query again
foreach ($results as $row){
if($i == 0) echo '<tr valign="top">';
echo '<td><a title="'. url_title($row->title) .'" href="' .base_url(). 'movies/review/' .$row->rid. '/' .url_title($row->title). '.html">' .$row->title. '</a> (' .$row->year. ')<br />';
echo check_review_score($row->score),'</td>';
if(++$i == $max_columns){
	echo "</tr>"; 
	$i=0;
} // endif
}//endforeach;

if($i > 0)
{
    for($j=$i; $j<$max_columns;$j++) echo "<td> </td>";
    echo '</tr>';
}
?>

Does anyone know why I still get an extra </tr> at the end of the table??

Link to comment
https://forums.phpfreaks.com/topic/96947-non-object-error/#findComment-496787
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.