Jump to content


Photo

Query Help


  • Please log in to reply
5 replies to this topic

#1 bernie.nmsu

bernie.nmsu
  • Members
  • PipPip
  • Member
  • 22 posts

Posted 25 January 2005 - 05:45 PM

Any help is appreciated.

I have not used dreamweaver in a while and I need some help with some code. I have a registration website, where folks can select a course from a course table. When they select the course, it takes them to a registration page. What I need to do now is not allow registration for a course if the course key is equal to 50. I'm getting the following error -


Parse error: parse error, unexpected '?' in c:\program files\apache group\apache\htdocs\training\index.php on line 205

Here is the code I have so far.

<?php
  while (!$Recordset1->EOF) {
?>
if ($Recordset1->Fields('CourseKey')=='50')
echo $Recordset1->Fields('CourseName');
echo $Recordset1->Fields('CourseDesc');
else
<td><a href="indexSelection.php?courseKey=<?php echo $Recordset1->Fields('CourseKey'); ?>"><?php echo $Recordset1->Fields('CourseName'); ?/a></a></td>
<td><?php echo $Recordset1->Fields('CourseDesc'); ?></td>
</tr>
<?php $Recordset1->MoveNext();
  }
?>


#2 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 25 January 2005 - 06:19 PM

Why are you continuing PHP statements in none-php mode! lol!

<?php
 while (!$Recordset1->EOF) {
?>
if ($Recordset1->Fields('CourseKey')=='50')
echo $Recordset1->Fields('CourseName');
echo $Recordset1->Fields('CourseDesc');
else
<td><a href="indexSelection.php?courseKey=<?php echo $Recordset1->Fields('CourseKey'); ?>"><?php echo $Recordset1->Fields('CourseName'); ?></a></a></td>
<td><?php echo $Recordset1->Fields('CourseDesc'); ?></td>
</tr>
<?php $Recordset1->MoveNext();
 }
?>

change above to:

<?php
 while (!$Recordset1->EOF) {

if ($Recordset1->Fields('CourseKey')=='50') {
echo $Recordset1->Fields('CourseName');
echo $Recordset1->Fields('CourseDesc');
  } else {
?>
<td><a href="indexSelection.php?courseKey=<?php echo $Recordset1->Fields('CourseKey'); ?>"><?php echo $Recordset1->Fields('CourseName'); ?></a></a></td>
<td><?php echo $Recordset1->Fields('CourseDesc'); ?></td>
</tr>
<?php $Recordset1->MoveNext();
  }
}
?>


#3 bernie.nmsu

bernie.nmsu
  • Members
  • PipPip
  • Member
  • 22 posts

Posted 25 January 2005 - 06:29 PM

That sends me into an infinite loop. Any other suggestions.

Why are you continuing PHP statements in none-php mode! lol!

<?php
 while (!$Recordset1->EOF) {
?>
if ($Recordset1->Fields('CourseKey')=='50')
echo $Recordset1->Fields('CourseName');
echo $Recordset1->Fields('CourseDesc');
else
<td><a href="indexSelection.php?courseKey=<?php echo $Recordset1->Fields('CourseKey'); ?>"><?php echo $Recordset1->Fields('CourseName'); ?></a></a></td>
<td><?php echo $Recordset1->Fields('CourseDesc'); ?></td>
</tr>
<?php $Recordset1->MoveNext();
 }
?>

change above to:

<?php
 while (!$Recordset1->EOF) {

if ($Recordset1->Fields('CourseKey')=='50') {
echo $Recordset1->Fields('CourseName');
echo $Recordset1->Fields('CourseDesc');
  } else {
?>
<td><a href="indexSelection.php?courseKey=<?php echo $Recordset1->Fields('CourseKey'); ?>"><?php echo $Recordset1->Fields('CourseName'); ?></a></a></td>
<td><?php echo $Recordset1->Fields('CourseDesc'); ?></td>
</tr>
<?php $Recordset1->MoveNext();
  }
}
?>

View Post



#4 WarpedNoodle

WarpedNoodle
  • Members
  • Pip
  • Newbie
  • 2 posts

Posted 25 January 2005 - 07:26 PM

Your loop logic is flawed. You have a while statement that says (by pseudo-coding) "So long as I don't have this condition met (while (!$Recordset1->EOF)), do this. Otherwise, do that. The problem is, you don't have any means of terminating the "if not" condition. Usually the "if not" condition is met by incrementing the variable in the "if it does" statement.

If this is not practical for your given situation, then the "while" loop is not the way to go. Rather, a nested "if, else" conditional might suit your needs.

Good luck,

Trev
Trevor Llewellyn
Webmaster, 247 Links
Owner, Downline Center
http://www.downlinecenter.com

#5 bernie.nmsu

bernie.nmsu
  • Members
  • PipPip
  • Member
  • 22 posts

Posted 25 January 2005 - 09:00 PM

I need my while statement to loop through, because I'm placing the course's into a field. I'm getting my data from a related table.

Any other suggestions.

#6 bernie.nmsu

bernie.nmsu
  • Members
  • PipPip
  • Member
  • 22 posts

Posted 25 January 2005 - 11:44 PM

**Closed** I was missing some brackets.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users