1

I am following through this tutorial

http://www.1stwebdesigner.com/tutorials/infinite-scrolling-tutorial/

And it contains this code snippet:

<!--?php 
$con = mysql_connect("localhost", "username", "password"); 
mysql_select_db("database_name"); 
$result = mysql_query("select SQL_CALC_FOUND_ROWS * from scroll_images order by id asc   limit 12"); 
$row_object = mysql_query("Select Found_Rows() as rowcount"); 
$row_object = mysql_fetch_object($row_object); 
$actual_row_count = $row_object--->rowcount;
?>

The line $actual_row_count = $row_object--->rowcount; confuses me, what is --->rowcount supposed to do? When I have it in my PHP, I receive errors.

<?php
$sql_fetch = "SELECT * FROM articles ORDER BY time DESC limit 4;";
$dbresult = mysqli_query( $db, $sql_fetch );

$row_object = mysqli_query( $db, "Select Found_Rows() as rowcount" );
$row_object = mysqli_fetch_object( $row_object );
$actual_row_count = $row_object--->rowcount;
?>

Parse error: syntax error, unexpected T_OBJECT_OPERATOR in /Applications/MAMP/htdocs/index.php on line 14

JoshDM
  • 4,939
  • 7
  • 43
  • 72
Daniel
  • 357
  • 1
  • 2
  • 12

7 Answers7

5

<!-- Comment --> is the way you comment out things in HTML. That line is indeed not correct (stop reading the article this instant).

I would imagine that he meant

<?php 
$con = mysql_connect("localhost", "username", "password"); 
mysql_select_db("database_name"); 
$result = mysql_query("select SQL_CALC_FOUND_ROWS * from scroll_images order by id asc   limit 12"); 
$row_object = mysql_query("Select Found_Rows() as rowcount"); 
$row_object = mysql_fetch_object($row_object); 
$actual_row_count = $row_object->rowcount;
?>

On a different note:

Please, don't use mysql_* functions in new code. They are no longer maintained and are officially deprecated. See the red box? Learn about prepared statements instead, and use PDO or MySQLi - this article will help you decide which. If you choose PDO, here is a good tutorial.

Zoe
  • 27,060
  • 21
  • 118
  • 148
Madara's Ghost
  • 172,118
  • 50
  • 264
  • 308
2

I imagine it is suppose to be

$actual_row_count = $row_object->rowcount;

But that's not how you get the number of rows for mysqli.

So what ever that code is, it is pretty much 100% wrong.

Steven
  • 13,250
  • 33
  • 95
  • 147
1

It is just a mistake. Replace <!--?php with <?php and $row_object--->rowcount; with $row_object->rowcount;

Voitcus
  • 4,463
  • 4
  • 24
  • 40
1

---> is not an actual operator. The actual operator you need is -> lamely called, the "arrow operator", or T_OBJECT_OPERATOR.

Evaluating that php would result in -

$actual_row_count = $rowobject-- (which means decrement by 1)->rowcount;

which is not correct PHP as you can only use the arrow operator on an object, not an integer, which is what the "$rowobject--" would evaluate to. This explains your unexpected "T_OBJECT_OPERATOR".

What you are experiencing is poor php engineering. Change it to

$actual_row_count = $rowobject->rowcount

and your PHP will be set. Refer to other answers for the rest

ddavison
  • 28,221
  • 15
  • 85
  • 110
  • 1
    php doesn't work that way. You can't `$rowobject-- ->rowcount;` So where ever that code is from, it's just 100% wrong. And to top it all off, you can't decrement by 1 an object, and `$rowobject` is an object. – Steven Jul 09 '13 at 13:49
  • You're absolutely correct. hopefully i got that across in my answer – ddavison Jul 09 '13 at 13:52
1
  • ---> itself doenst do anything.

  • --> is used to close HTML comment (that you start on row1 with

  • -> is used to get the instance of an object (in your case, $row_object->rowcount)
Pokepoke
  • 41
  • 5
0

It's trying to get an instance of an object, just not correctly. Try this instead:

$row_object->rowcount
Casper André Casse
  • 573
  • 2
  • 8
  • 20
0

Its just wrong by user instead of

$rowobject--->rowcount;

Replace to

$rowobject->rowcount
Bikash Nayak
  • 187
  • 1
  • 2
  • 12