Hi all.. really need a help. this is looks easy peasy but I can't solve it :(

I want to make a link from lesson ID to a details of the selected lesson ID. <td> "<a href='details.php?lessonID=". $lessonID ."'> </a>" </td> when I run the coding the following error appear on that line.

Parse error: parse error, expecting `','' or `';'' in C:\xampp\htdocs\lina\resultlink.php on line 65.

How the details page should be constructed so that the lessonID can be passed to it.?

many thanks for your help.
-tulip

Recommended Answers

All 22 Replies

try this

echo "<td bgcolor=#9B5DCA><a href='link_page.php?id={$lessonID'>".stripslashes(delete)."</a>
	   </td>";
<?php

$lessonID =2;

?>
<td><a href='details.php?lessonID=<?php echo $lessonID; ?>'> </a></td>
Member Avatar for diafol
<?php

$lessonID =2;

?>
<td><a href='details.php?lessonID=<?php echo $lessonID; ?>'> </a></td>
<?php
$lesson = 2;
echo "<td><a href='details.php?lessonID={$lessonID}'</a></td>";
?>

If you need to stripslash/escape the value, do it beforehand:

$lesson = stripslashes($other_var);
...

Rather than mess around with the "html output".

Thanks all, for your input..
I have tried all but none is success..the same error still appear on the same line.

thanks

Thanks all, for your input..
I have tried all but none is success..the same error still appear on the same line.

thanks

Then show all of the code, not just one line.

ShawnCplus,
many thanks for your kind help.
this is the full code..
I have the details page ( details.php) to be linked from the selected ID).

thanks,

<?php

mysql_connect("localhost","root","");

mysql_select_db("student") or die("Unable to select database"); 
?>

<form name="form" action="result.php" method="get">

Subject   <input type="text" name="q" />
Topic <input type="text" name="r" />
Ability <input type="text" name="s" />

  <input type="submit" name="Submit" value="Search" />
</form>

<?php
  // Get the search variable from URL
 $q = $_GET['q'] ;

  $r = $_GET['r'] ;

  $s = $_GET['s'] ;

// Build SQL Query  
 $myquery = "select * from lesson where subject like '%".$q."%'  AND learningArea like '%".$r."%'  AND  ability like '%".$s."%'";
//echo $myquery ;
 $result = mysql_query ($myquery); 


 echo "<table>"  ;
echo "<tr><th>Lesson ID</th>";
echo "<th>Subject</th>";
echo "<th>Learning Area</th>";
echo "<th>No of Students</th>";
echo "<th>Time Period</th>";
echo "<th>Class</th>";
echo "<th>Ability</th></tr>";

while ($row= mysql_fetch_array($result)) 
 {
$lessonID = $row["lessonID"];  
  $subject = $row["subject"];
  $learningArea= $row["learningArea"];
    $noofstudent= $row["noofstudents"];
    $minutes= $row["minutes"];
    $class= $row["class"];
    $ability= $row["ability"];

//display the row
   
echo "<tr>
<td><a href='details.php?lessonID=<?php echo $lessonID; ?>'> </a></td>
<td>$subject</td> 
<td>$learningArea</td> 
<td>$noofstudents</td> 
<td>$minutes</td>  
<td>$class</td>  
<td> $ability</td>  
</tr>" ;
}
echo "</table>";
  
?>

I think the problem is here

$myquery = "select * from lesson where subject like '%".$q."%' AND learningArea like '%".$r."%' AND ability like '%".$s."%'";

it should be:

$myquery = "select * from lesson where subject like '%'.$q.'%' AND learningArea like '%'.$r.'%' AND ability like '%'.$s.'%'";

Try this and let me know it is working or not?

Hi, I have tried the one that you suggested.
It doesn't work.
I don't have any problem to listed down the result..just to make a link to a detail page based on the lessonID chosen. Error on the same line
<td><a href='details.php?lessonID=<?php echo $lessonID; ?>'> </a></td>

please use echo in start of
<td><a href='details.php?lessonID=<?php echo $lessonID; ?>'> </a></td>

this line and terminator at the end

echo "<tr>
<td><a href='details.php?lessonID=$lessonID'>Details</a></td>
<td>$subject</td>
<td>$learningArea</td>
<td>$noofstudents</td>
<td>$minutes</td>
<td>$class</td>
<td> $ability</td>
</tr>" ;

this is a typo error in your SQL query then:-O

..........
it should be:

$myquery = "select * from lesson where subject like '%'.$q.'%' AND learningArea like '%'.$r.'%' AND ability like '%'.$s.'%'";

........

and,
the SQL save version is this:

$q = isset($_GET['q'])? mysql_real_escape_string($_GET['q']):'';
$r = isset($_GET['r'])? mysql_real_escape_string($_GET['r']):'';
$s = isset($_GET['s'])? mysql_real_escape_string($_GET['s']):'';

// Build SQL Query
$myquery = "select * from lesson where subject like '%{$q}%' AND learningArea like '%{$r}%'
 AND ability like '%{$s}%'";

try this:

while ($row= mysql_fetch_array($result))
{
$lessonID = $row["lessonID"];
$subject = $row["subject"];
$learningArea= $row["learningArea"];
$noofstudent= $row["noofstudents"];
$minutes= $row["minutes"];
$class= $row["class"];
$ability= $row["ability"];

?>
//display the row

<tr>
<td><a href="details.php?lessonID=<?php echo $lessonID; ?>"> Details</a></td>
<td><?php echo $subject; ?></td>
<td><?php echo $learningArea; ?></td>
<td><?php echo $noofstudents; ?></td>
<td><?php echo $minutes; ?></td>
<td><?php echo $class; ?></td>
<td><?php echo $ability; ?> </td>
</tr>
<?php  } ?>
</table>

i am sure it works.

but its not printing the data from the database... you will see $minutes and other stuffs in the output...
.....
the shortest is the better...

it will print the data from the database.
i am sure.

commented: very helpful +1

it will print the data from the database.
i am sure.

i've seen your first version, and in that post i did not see the <?php echo $field... ; ?>
which needed to print the values.

if i saw it wrong then sorry about it.

commented: good suggestion +1

I have tried that as well..
please anyone who can identify the error...

thanks.

try this:

while ($row= mysql_fetch_array($result))
{
$lessonID = $row["lessonID"];
$subject = $row["subject"];
$learningArea= $row["learningArea"];
$noofstudent= $row["noofstudents"];
$minutes= $row["minutes"];
$class= $row["class"];
$ability= $row["ability"];

?>
//display the row

<tr>
<td><a href="details.php?lessonID=<?php echo $lessonID; ?>"> Details</a></td>
<td><?php echo $subject; ?></td>
<td><?php echo $learningArea; ?></td>
<td><?php echo $noofstudents; ?></td>
<td><?php echo $minutes; ?></td>
<td><?php echo $class; ?></td>
<td><?php echo $ability; ?> </td>
</tr>
<?php  } ?>
</table>

i am sure it works.

Hi Navi17.
thanks a lot..can be linked to details page.
however, the Id number is not shown in the result..
all show the same string..details..but the lesson Id that sent to details page is correct (the lessonID)
just the Id is not displayed in the table.
any idea to correct it?

thanks

i've seen your first version, and in that post i did not see the <?php echo $field... ; ?>
which needed to print the values.

if i saw it wrong then sorry about it.

djjjozsi, it does work for me..I mean the link.
the code that I posted before also print data from the database..
The problem is to make a link to the details page.
now, Navi17 has solved that problem..however the ID is not printed here..but the value is passed to the details page... I need both..the lessonID printed & the value passed.
ANy solution. Mny thanks for your respond

Thanks all for your help..
NAvi17 & djjjozsi i have corrected it now..
credits for both of you :)
It works perfectly now.

you can print the $lessonID after the Datails word...

I don't like saying this but my version still created the same output like navi17's example,

decide which is shorten or which comes earier :)

echo "<tr>
      <td><a href='details.php?lessonID=$lessonID'>Details for $subject( $lessonID )</a></td>
      <td>$subject</td>
      <td>$learningArea</td>
      <td>$noofstudents</td>
      <td>$minutes</td>
      <td>$class</td>
      <td> $ability</td>
      </tr>" ;
<?php

mysql_connect("localhost","root","");

mysql_select_db("student") or die("Unable to select database"); 
?>

<form name="form" action="result.php" method="get">

Subject   <input type="text" name="q" />
Topic <input type="text" name="r" />
Ability <input type="text" name="s" />

  <input type="submit" name="Submit" value="Search" />
</form>

<?php
  // Get the search variable from URL
 $q = $_GET['q'] ;

  $r = $_GET['r'] ;

  $s = $_GET['s'] ;

// Build SQL Query  
 $myquery = "select * from lesson where subject like '%".$q."%'  AND learningArea like '%".$r."%'  AND  ability like '%".$s."%'";
//echo $myquery ;
 $result = mysql_query ($myquery); 


 echo "<table>"  ;
echo "<tr><th>Lesson ID</th>";
echo "<th>Subject</th>";
echo "<th>Learning Area</th>";
echo "<th>No of Students</th>";
echo "<th>Time Period</th>";
echo "<th>Class</th>";
echo "<th>Ability</th></tr>";

while ($row= mysql_fetch_array($result)) 
 {
$lessonID = $row["lessonID"];  
  $subject = $row["subject"];
  $learningArea= $row["learningArea"];
    $noofstudent= $row["noofstudents"];
    $minutes= $row["minutes"];
    $class= $row["class"];
    $ability= $row["ability"];

//display the row
   
echo <<<EOD
<tr>
<td><a href="details.php?lessonID=$lessonID"> </a></td>
<td>$subject</td> 
<td>$learningArea</td> 
<td>$noofstudents</td> 
<td>$minutes</td>  
<td>$class</td>  
<td> $ability</td>  
</tr>
EOD;
}
echo "</table>";
  
?>

tulipputih if your problem is solved then mark this forum as solved.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.