Forum Moderators: coopster
I have the script presented below which returns the message:
Parse error: parse error, unexpected $ in ......../demo.php on line 1
I can not understand where is the fault and i have tried lots of things to locate it and fix it....
ANY SUGGESTIONS?
the paradox is that the fault is located in line 1 by the browser which means that either the fault is in line 1, or it is somewhere else and it cant be located by browser........confusing
<?
include "dbconnect.php";
$type = ($_REQUEST ['type']);
if (!$db_conn) {
echo '<p> </p>';
echo '<p> </p>';
echo '<div align="center" class="greeka">An error has occured, Database can not be reached, please try again later. <p>';
echo '<p> </p>';
echo '<p> </p>';
} else {
// Set some variables for script
// To show each page by number set to Y. Set to N for prev-next links only
$showpages = "Y";
// Set number of records to be displayed per page $limit=somenumber
$limit=5;
if (empty($offset)) $offset=0;
$query = 'select * from Hotels '
."where type = '$type'";
$result = mysql_query($query);
$numrows = mysql_num_rows($result);
if ($numrows==0) {
echo '<p> </p>';
echo '<p> </p>';
echo '<div align="center"> We are sorry, there is not any available record to display! </div>';
echo '<p> </p>';
echo '<p> </p>';
} else
?>
<div align=center>
<strong><? echo $type?></strong>
</div>
<?
echo '<p> </p>';
echo '<p> </p>';
{
$query = 'select * from Hotels '
."where type = '$type' limit $offset,$limit";
$result2 = mysql_query($query2);
while ($row=mysql_fetch_assoc($result2)) {
$ID = $row['ID'];
$name = $row['name'];
$hoteldescr = $row['hoteldescr'];
$location = $row['location'];
$town = $row['town'];
$url = "http://www.example.gr/nikos/bestour/";
$url2 = "http://www.example.gr/nikos/bestour/pictures/";
$querypicture = "select * from Gallery where HotelID = '$ID'";
$resultpicture = mysql_query($querypicture);
while ($rowpicture=mysql_fetch_assoc($resultpicture)) {
$picture = $rowpicture['picture'];
$descritpion = $rowpicture['descritpion'];
?>
<table width="73%" border="3" align="center" cellpadding="0" cellspacing="0" bordercolor="#FFFFFF">
<tr bgcolor="#FFFFFF">
<td width="21%" rowspan="2" bordercolor="#FFFFFF" bgcolor="#0d9aef"><div align="center"><img src="<? echo $url2?><? echo $picture?>" alt="<? echo $descritpion?>" width="150" height="113"></div></td>
<td width="43%" height="45" bordercolor="#FFFFFF"><div align="center">Location: <? echo $location?> </div></td>
<td width="36%" bordercolor="#FFFFFF"><div align="center">Town: <? echo $town?></div></td>
</tr>
<tr>
<td height="78" colspan="2" bordercolor="#0d9aef"><div align="justify"><? echo $hoteldescr?></div></td>
</tr>
</table>
<?
};
};
//determine number of pages needed
$pages=intval($numrows/$limit);
//if number of records isn't evenly divisible by the number of pages above, add another page.
if ($numrows%$limit) {
$pages++;
}
//set value of first record to be displayed
$first_record = $offset + 5;
echo "<br />";
//see if we're on the last page
if (!((($offset)/$limit)+1==$pages)) {
$last_record = $offset + $limit;
//is last page
echo " <strong>$last_record</strong> of <strong>$numrows</strong> $type(s). Click on image to view the $type <br />";
} else {
//is NOT last page - send this to browser
echo " <strong>$numrows</strong> of <strong>$numrows</strong> $type(s). Click on image to view the $type<br>";
}
echo "<br />\n";
//prepare and display links to other results in browser
if ($offset!= 0) {
$prevoffset=$offset-$limit;
//create a previous link - if we're not on the first page
echo "<a class='nav' href='$PHP_SELF?offset=$prevoffset'><< Prev</a> \n";
}
//construct that shows just prev-next or all page numbers
if ($showpages == Y) {
if ( $pages!= 1 ) {
for ($i=1;$i<=$pages;$i++) {
$newoffset=$limit*($i-1);
if ( ((($offset)/$limit)==($i-1)) ) {
echo "$i \n";
} else {
echo "<a class='nav' href='$PHP_SELF?offset=$newoffset'>$i</a> \n";
}
}
}
}
if (!((($offset)/$limit)+1==$pages) && $pages!=1) {
$newoffset=$offset+$limit;
//create a next link - if we're not on the last page
echo ("<a class='nav' href='$PHP_SELF?offset=$newoffset'>Next >></a><p>\n");
}
} else {
echo "No more $type(s) to display!";
}
}
?>
[edited by: jatar_k at 4:41 pm (utc) on July 8, 2005]
[edit reason] examplified urls and compressed code [/edit]
<?
include "dbconnect.php";
$type = ($_REQUEST ['type']);
if (!$db_conn)
{
echo '<p> </p>';
echo '<p> </p>';
echo '<div align="center" class="greeka">An error has occured, Database can not be reached, please try again later. <p>';
echo '<p> </p>';
echo '<p> </p>';
}
else
{
// Set some variables for script
// To show each page by number set to Y. Set to N for prev-next links only
$showpages = "Y";
// Set number of records to be displayed per page $limit=somenumber
$limit=5;
if (empty($offset))
{
$offset=0;
}
$query = 'select * from Hotels '
."where type = '$type'";
$result = mysql_query($query);
$numrows = mysql_num_rows($result);
if ($numrows==0)
{
echo '<p> </p>';
echo '<p> </p>';
echo '<div align="center"> We are sorry, there is not any available record to display! </div>';
echo '<p> </p>';
echo '<p> </p>';
}
else
?>
<div align=center>
<strong><? echo $type?></strong>
</div>
<?
echo '<p> </p>';
echo '<p> </p>';
{
$query = 'select * from Hotels '
."where type = '$type' limit $offset,$limit";
$result2 = mysql_query($query2);
while ($row=mysql_fetch_assoc($result2))
{
$ID = $row['ID'];
$name = $row['name'];
$hoteldescr = $row['hoteldescr'];
$location = $row['location'];
$town = $row['town'];
$url = "http://www.example.gr/nikos/bestour/";
$url2 = "http://www.example.gr/nikos/bestour/pictures/";
$querypicture = "select * from Gallery where HotelID = '$ID'";
$resultpicture = mysql_query($querypicture);
while ($rowpicture=mysql_fetch_assoc($resultpicture))
{
$picture = $rowpicture['picture'];
$descritpion = $rowpicture['descritpion'];
?>
<table width="73%" border="3" align="center" cellpadding="0" cellspacing="0" bordercolor="#FFFFFF">
<tr bgcolor="#FFFFFF">
<td width="21%" rowspan="2" bordercolor="#FFFFFF" bgcolor="#0d9aef"><div align="center"><img src="<? echo $url2?><? echo $picture?>" alt="<? echo $descritpion?>" width="150" height="113"></div></td>
<td width="43%" height="45" bordercolor="#FFFFFF"><div align="center">Location: <? echo $location?> </div></td>
<td width="36%" bordercolor="#FFFFFF"><div align="center">Town: <? echo $town?></div></td>
</tr>
<tr>
<td height="78" colspan="2" bordercolor="#0d9aef"><div align="justify"><? echo $hoteldescr?></div></td>
</tr>
</table>
<?
}
}
//determine number of pages needed
$pages=intval($numrows/$limit);
//if number of records isn't evenly divisible by the number of pages above, add another page.
if ($numrows%$limit)
{
$pages++;
}
//set value of first record to be displayed
$first_record = $offset + 5;
echo "<br />";
//see if we're on the last page
if (!((($offset)/$limit)+1==$pages))
{
$last_record = $offset + $limit;
//is last page
echo " <strong>$last_record</strong> of <strong>$numrows</strong> $type(s). Click on image to view the $type <br />";
}
else
{
//is NOT last page - send this to browser
echo " <strong>$numrows</strong> of <strong>$numrows</strong> $type(s). Click on image to view the $type<br>";
}
echo "<br />\n";
//prepare and display links to other results in browser
if ($offset!= 0)
{
$prevoffset=$offset-$limit;
//create a previous link - if we're not on the first page
echo "<a class='nav' href='$PHP_SELF?offset=$prevoffset'><< Prev</a> \n";
}
//construct that shows just prev-next or all page numbers
if ($showpages == Y)
{
if ( $pages!= 1 )
{
for ($i=1;$i<=$pages;$i++)
{
$newoffset=$limit*($i-1);
if ( ((($offset)/$limit)==($i-1)) )
{
echo "$i \n";
}
else
{
echo "<a class='nav' href='$PHP_SELF?offset=$newoffset'>$i</a> \n";
}
}
}
}
if (!((($offset)/$limit)+1==$pages) && $pages!=1)
{
$newoffset=$offset+$limit;
//create a next link - if we're not on the last page
echo ("<a class='nav' href='$PHP_SELF?offset=$newoffset'>Next >></a><p>\n");
}
else
{
echo "No more $type(s) to display!";
}
}
}
?>
[edited by: jatar_k at 4:49 pm (utc) on July 8, 2005]
[edit reason] examplified url [/edit]
however...my script still has a prob:
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /....../demo.php on line 56
2 of 2 hotel(s). Click on image to view the hotel
which is located in a query....it can be fixed....thx all of you for helping me....i ll try to work it out now and fix the whole thing.