Page 1 of 1

Trouble with code

Posted: Fri May 30, 2003 6:47 pm
by nigma
Hey, I am trying to make a mysql class that will make it real easy for me to work with mysql data. Anyway, I got started and I got this error:

Parse error: parse error, unexpected T_VARIABLE, expecting '(' in C:\Program Files\Apache Group\Apache2\mc0\classes\mysqlClass.php on line 46

I tracked down line 46 and saw no problem with it? I looked a few lines up, no errors there. But maybe that is why there is an error, I just don't know what the hell I am doing.

Here is the code that seems to not be working:

Code: Select all

function PrintRows()
		{
			for ($this->counter = 0; $this->counter <= $this->totalRows; $this->counter++)
			&#123;
				mysql_data_seek($this->result, $this->counter) or die("<p>Unable to seek out row: $this->counter</p><br>");
				$this->data = mysql_fetch_array($this->result);

				print '<tr>'; #line 46
				for $this->col ($this->data)
				&#123;
					print '<td>$this->col</td>';
				&#125;
				print '</tr>';
			&#125;
		&#125;
Anyone spot the problem?

Posted: Fri May 30, 2003 6:57 pm
by nigma
Spotted one. Sorry. You cannot print a variable if its inside the single quotes. But I am still having trouble with line 46.

Posted: Fri May 30, 2003 7:00 pm
by m3mn0n
You would need to show more of the source and possible an error messege for us to help.

Posted: Fri May 30, 2003 7:02 pm
by nigma
God DAMMIT! Nother error I spotted, but I am sure this is the last one. Instead of for, I meant to use foreach :(

Posted: Fri May 30, 2003 7:03 pm
by nigma

Code: Select all

<?php

	class MySQL
	&#123;
		var $host;
		var $database;
		var $table;
		var $query;
		var $result;
		var $totalRows;
		var $data;
		var $counter;
		var $col;

		function Connect($host = "localhost")
		&#123;
			$this->conn = mysql_connect($host, "user", "pass");
			if (!$this->conn)
			&#123;
				die("<p>Unable to establish a connection with database server.</p><br>");
			&#125;
		&#125;

		function GetRows($database, $table)
		&#123;
			if ($database == 0 || $table == 0)
			&#123;
				die("<p>No arguments passed to function 'GetRows'.</p><br>");
			&#125;

			mysql_select_db($database, $this->conn) or die ("<p>Unable to select the database: $database</p><br>");

			$this->query = "select * from $table";

			$this->result = mysql_query($this->query, $this->conn);
			if (!$this->result)
			&#123;
				die("<p>Unable to query database.</p><br>");
			&#125;

			$this->totalRows  = mysql_num_rows($this->result);
		&#125;

		function PrintRows()
		&#123;
			for ($this->counter = 0; $this->counter <= $this->totalRows; $this->counter++)
			&#123;
				mysql_data_seek($this->result, $this->counter) or die("<p>Unable to seek out row: $this->counter</p><br>");
				$this->data = mysql_fetch_array($this->result);

				print '<tr>';
				foreach $this->col ($this->data)
				&#123;
					print "<td>$this->col</td>";
				&#125;
				print '</tr>';
			&#125;
		&#125;

		function Disconnect();
		&#123;
			mysql_close($this->conn);
		&#125;
	&#125;
?>