razorlegacy Posted March 19, 2008 Share Posted March 19, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/96947-non-object-error/ Share on other sites More sharing options...
treehugger88 Posted March 19, 2008 Share Posted March 19, 2008 foreach will work better in that instance, I think. Quote Link to comment https://forums.phpfreaks.com/topic/96947-non-object-error/#findComment-496095 Share on other sites More sharing options...
BlueSkyIS Posted March 19, 2008 Share Posted March 19, 2008 oh, use => instead of -> actually, i'd probably use this instead: $results['title'] Quote Link to comment https://forums.phpfreaks.com/topic/96947-non-object-error/#findComment-496096 Share on other sites More sharing options...
trq Posted March 19, 2008 Share Posted March 19, 2008 If 4results is an array you'll want to be using $results['title'] not $results->title. Quote Link to comment https://forums.phpfreaks.com/topic/96947-non-object-error/#findComment-496100 Share on other sites More sharing options...
razorlegacy Posted March 19, 2008 Author Share Posted March 19, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/96947-non-object-error/#findComment-496139 Share on other sites More sharing options...
BlueSkyIS Posted March 19, 2008 Share Posted March 19, 2008 turn off notices in error_reporting or you'll see the undefined index notice all the time. Quote Link to comment https://forums.phpfreaks.com/topic/96947-non-object-error/#findComment-496143 Share on other sites More sharing options...
razorlegacy Posted March 19, 2008 Author Share Posted March 19, 2008 ?? Quote Link to comment https://forums.phpfreaks.com/topic/96947-non-object-error/#findComment-496146 Share on other sites More sharing options...
BlueSkyIS Posted March 19, 2008 Share Posted March 19, 2008 try putting this at the top of your script: error_reporting(E_ERROR | E_WARNING | E_PARSE); Quote Link to comment https://forums.phpfreaks.com/topic/96947-non-object-error/#findComment-496153 Share on other sites More sharing options...
razorlegacy Posted March 19, 2008 Author Share Posted March 19, 2008 added it now how can i fix my problem ) Quote Link to comment https://forums.phpfreaks.com/topic/96947-non-object-error/#findComment-496159 Share on other sites More sharing options...
razorlegacy Posted March 19, 2008 Author Share Posted March 19, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/96947-non-object-error/#findComment-496170 Share on other sites More sharing options...
BlueSkyIS Posted March 19, 2008 Share Posted March 19, 2008 for loop. http://us3.php.net/foreach Quote Link to comment https://forums.phpfreaks.com/topic/96947-non-object-error/#findComment-496173 Share on other sites More sharing options...
sasa Posted March 19, 2008 Share Posted March 19, 2008 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); ?> Quote Link to comment https://forums.phpfreaks.com/topic/96947-non-object-error/#findComment-496190 Share on other sites More sharing options...
razorlegacy Posted March 19, 2008 Author Share Posted March 19, 2008 they are printing now but the table column script doesn't work so I have no column script for it. does anyone know how to incorporate the array_chuck into a script that I can just drop this into. i had problems implementing it Quote Link to comment https://forums.phpfreaks.com/topic/96947-non-object-error/#findComment-496304 Share on other sites More sharing options...
razorlegacy Posted March 19, 2008 Author Share Posted March 19, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/96947-non-object-error/#findComment-496312 Share on other sites More sharing options...
sasa Posted March 20, 2008 Share Posted March 20, 2008 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>'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/96947-non-object-error/#findComment-496558 Share on other sites More sharing options...
razorlegacy Posted March 20, 2008 Author Share Posted March 20, 2008 I get an extra </tr> at the end of the table Quote Link to comment https://forums.phpfreaks.com/topic/96947-non-object-error/#findComment-496760 Share on other sites More sharing options...
razorlegacy Posted March 20, 2008 Author Share Posted March 20, 2008 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?? Quote Link to comment https://forums.phpfreaks.com/topic/96947-non-object-error/#findComment-496787 Share on other sites More sharing options...
sasa Posted March 20, 2008 Share Posted March 20, 2008 where you ending table Quote Link to comment https://forums.phpfreaks.com/topic/96947-non-object-error/#findComment-496805 Share on other sites More sharing options...
razorlegacy Posted March 20, 2008 Author Share Posted March 20, 2008 I end the table right after this code Quote Link to comment https://forums.phpfreaks.com/topic/96947-non-object-error/#findComment-496870 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.