0

I have a page which displays records in a table and I am able to do that but after adding a code so a highlighted table row will change color, I am now getting error instead.

$result = mysqli_query($con,"SELECT * FROM mydb WHERE `Main Type`='main1' AND `DB Type`='Active' ORDER BY `Record ID`");

echo "<table border='1' style='width:100%; font-family:arial,Serif;font-style:regular;font-size:12px; color:black' CELLPADDING='1' CELLSPACING='0'>
<tr>
<th>Record ID</th>
<th>Address</th>
<th>City</th>
<th>State</th>
<th>Zip Code</th>
<th>County</th>
<th>Price</th>
<th>Bed</th>
<th>Bath</th>
<th>Square Foot</th>
<th>Year Built</th>
<th>As Is Value</th>
<th>DB Type</th>
<th>Main Type</th>
</tr>";

while($row = mysqli_fetch_array($result))
  {
  echo "<tr onclick='toggle(this)'>";
  echo "<td>" . $row['Record ID'] . "</td>";
  echo "<td>" . $row['Address'] . "</td>";
  echo "<td>" . $row['City'] . "</td>";
  echo "<td>" . $row['State'] . "</td>";
  echo "<td>" . $row['Zip Code'] . "</td>";
  echo "<td>" . $row['County'] . "</td>";
  echo "<td>" . $row['Price'] . "</td>";
  echo "<td>" . $row['Bed'] . "</td>";
  echo "<td>" . $row['Bath'] . "</td>";
  echo "<td>" . $row['Square Foot'] . "</td>";
  echo "<td>" . $row['Year Built'] . "</td>";
  echo "<td>" . $row['As Is Value'] . "</td>";
  echo "<td>" . $row['DB Type'] . "</td>";
  echo "<td>" . $row['Main Type'] . "</td>";
  echo "</tr>";
  }
echo "</table><br>";

echo "<script type='text/javascript'>";
echo "function toggle(it) { if ((it.style.backgroundColor == 'none') || (it.style.backgroundColor == '')){it.style.backgroundColor = 'yellow';}}";
echo "</script>"


mysqli_close($con);

Basically my main goal is if the user clicks on a row, the entire row will change color to indicate it is being selected. My more advance goal is a mousemove instead of onclick. I'm looking for the easiest and less complicated way to do this, I have this feeling that the solution is simple. I hope you guys can help.

The error I'm getting is

Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/u560877965/public_html/hud.php on line 59

6
  • Where is line 59? Could you specify, please? Commented Dec 28, 2013 at 13:12
  • 2
    echo "</script>" < add a semicolon ; here. Commented Dec 28, 2013 at 13:13
  • 1
    Do you know you don't have to echo "blah"; echo "blah"; echo "blah"; and can just use a new line for readability? echo "<tr onclick='toggle(this)'> [new line] <td>" . $row['Record ID'] . "</td> [new line]... Commented Dec 28, 2013 at 13:15
  • Hello @popnoodles, I think you have a shorter, simpler suggestion, can I get more info on what you are trying to suggest? I'm a beginner in php by the way, I'm a VB Programmer but I need this done with php/javascript. Commented Dec 28, 2013 at 13:27
  • My comment doesn't answer the question, though it might have prevented the problem. See how your first chunk of echo just uses new lines, not echo echo echo, that's much tidier. oi42.tinypic.com/bgrcep.jpg Commented Dec 28, 2013 at 13:33

1 Answer 1

3

You have missed semicolon from after string in code.

Change this:

echo "</script>"

to this:

echo "</script>";
//              ^ here (for those who can't see it)
Sign up to request clarification or add additional context in comments.

3 Comments

so what is the difference between to echo ?
ahh sory i miss the semicolon :)
Ahhh back to the old days, programming.. debugging... where a single speck of dust can fail the entire program.:) Thanks much guys

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.