0

I am trying to output a list of links based upon database query result. The query works fine but I need to get the information for the links to populated by the same results. In this example I need to create the following string to pass along to my loadXMLDoc() Function..

$ridesid
$catrating

This is the actual line of code that is giving me an issue:

echo "<a href='#' onmousedown='url1 ='attraction_page.php?rideid=$ridesid&catrating=$catrating onclick ='loadXMLDoc()'>$rides</a>";

I am pretty sure it is just an issue with the quotes but I have been searching and searching for a solution or an example of how to properly code this line but can't find anything. Can anyone help?

Thanks

Here is the complete PHP block:

<?php
    $sql3 = "SELECT `Record_ID`, `Name` FROM `rides` WHERE `Rating` = $catrating  ORDER BY `Name`";
    $result3=mysql_query($sql3)or die(mysql_error());
    //var_dump ($result3);
    $num = mysql_num_rows($result3);
    //WHILE ($row3 = mysql_fetch_array($result3)){
        echo "<table>";
        // Ride Category Heading
        if ($catrating == 1)
            echo "<span class='headertext'>Kiddie Rides</span><br \>";
        if ($catrating == 2)
            echo "<span class='headertext'>Family Rides</span><br \>";
        if ($catrating == 3)
            echo "<span class='headertext'>Thrill Rides</span><br \>";
        // end heading
        for ($i = 0; $i < $num; $i++){
            $row3 = mysql_fetch_array($result3);
            //var_dump($row3);
            $ridesid = $row3[0];
            $rides = $row3[1];


            //echo "<a href='attraction_page.php?rideID=". urlencode($ridesid) ."&catrating=". urlencode($catrating) ."'>$rides</a>";
            echo "<tr>";
            //echo "<a href='#' onmousedown='url1 ='attraction_page.php?rideID=$ridesid&catrating=$catrating' onclick='loadXMLDoc()'>$rides</a>";
            //echo "<a href='#' onmousedown='url1 ='attraction_page.php?rideID=30&catrating=1 onclick='loadXMLDoc()'>$rides</a>";
            //echo "<a href='attraction_page.php?rideID=". urlencode($ridesid) ."&catrating=". urlencode($catrating) ."'>$rides</a>";
            echo "<a href='#' onmousedown='url1 ='attraction_page.php?rideid=$ridesid&catrating=$catrating onclick ='loadXMLDoc()'>$rides</a>";
            echo "<br />";
            echo "</tr>";

        }

        echo '</table>';
//  }
    ?>
bblincoe
  • 2,393
  • 2
  • 20
  • 34
GMORROW
  • 5
  • 1

2 Answers2

0

You must escape your quotes.

echo "<a href='javascript:void(0);' onmousedown='url1 =\'attraction_page.php?rideid=$ridesid&catrating=$catrating\';' onclick ='loadXMLDoc()'>$rides</a>";

I would also replace the # in your href attribute with javascript:void(0)

Dutchie432
  • 28,798
  • 20
  • 92
  • 109
0

I would recommend to leave quotes when you want to use a var, or use the {$var} syntax

            echo "<a href='#' onmousedown='url1 =\'attraction_page.php?rideid=".$ridesid."&catrating=".$catrating."\'' onclick ='loadXMLDoc()'>".$rides."</a>";
  • I also used Dutchie432 quote escapes in here, as I didn't notice that. Credit is given when credit is due. :) – cPJerald Jan 20 '14 at 19:41