Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

unexpected T_STRING

Status
Not open for further replies.

dbaseboy

Programmer
Apr 24, 2002
48
0
0
GB
Hi,

Its me again! well I got my last problem sorted and am now rattling through this PHP but I've hit a strange problem. I know that you experienced people will spot it straight away but its got me lost!

Im getting:
Parse error: parse error, unexpected '/' in /home/peasepu/public_html/newads.php on line 21

heres my code, the idea is to create a table 3 columns wide with whatever it finds ie

Title Title Title
Text Text Text
Name Name Name
Comment Comment Comment

so heres my code: (I've marked line 21 in red)
Code:
<body>
<table><tr>
<?php
 $dbh=mysql_connect ("localhost","*****","*****") or die ('I cannot connect to the database because: ' . mysql_error());
 $sel=mysql_select_db ('peasepu_whowhere',$dbh) or die ('I cannot connect to the database because: ' . mysql_error());
$query="SELECT * FROM `alreetads`;
$result=mysql_query($query) or die ('Query error: ' . mysql_error());
$num=mysql_numrows($result);
$i=0;
$col=1;

while ($i < $num) {
	if ($col == 4) { 
		[COLOR=red]echo "</td></tr><tr><td>";[/color]
		$col = 1;
		}
	else {
		echo "<td>";
		}
	
$title=mysql_result($result,$i,"title");
$text=mysql_result($result,$i,"text");
$name=mysql_result($result,$i,"name");
$contact=mysql_result($result,$i,"contact");

echo "$title<br>$text<br>$name<br>$contact</td>";
$col++;
$i++;
}
?>
</td></tr>
</table>
</body>
</html>

I tried having:
echo "<table><tr>"; before the while statement but hit problems there so I put them after the <body>. I've checked for missing ; etc but cant see anything wrong. All I can imagine is that its seeing the </td> on the first pass and thinks "I havent opened a <td> yet"

Thanks again in advance.

Peter
 
i see one error:
mysql_numrows

should be
mysql_num_rows

-jeff
try { succeed(); } catch(E) { tryAgain(); } finally { rtfm(); }
i like your sleeves...they're real big
 
You're missing the closing quote in this line:
Code:
$query="SELECT * FROM `alreetads`[red][b]"[/b][/red];
PHP then got to line 21 where it found a double quote (and thought the query ended) and got confused as to what followed.
 
also try cleaning up your code a bit

Code:
...

$result=mysql_query($query) or die ('Query error: ' . mysql_error());

$i=0;
$col=1;
while ( $r = mysql_fetch_object($result) ) {
    if ($col == 4) {
        echo "</td></tr><tr><td>";
        $col = 1;
        } else {
        echo "<td>";
        }    

echo "$r->title<br>$r->text<br>$r->name<br>$r->contact</td>";
$col++;
$i++;
}

...
 
Gentlemen (and/or ladies),

Thank you all,

Jemminger - I've learnt something new although both syntaxes allegedly work.

Vragabond - Top man! spot on, its like the old saying goes "you can lead a horse to water but getting him to debug PHP at midnight is a no go".

Steven - Can I confirm that the mysql_fetch_object replaces the need for setting up an array and the $r->title tells it to use the field within $r called title? If so, a lot tidier I agree although it may be a good idea for me to get used to the basic idea first then move onto the other stuff.

For now Im just happy that it works,

Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top