简体   繁体   中英

Using a GET Id from mysql query

I am trying to run a mysql query within some php and have the results echoed as HTML. I got it working but now I would like to insert an id into the links so I can use a page to GET the id. Does anyone know how to do this. What I have tried (and is not working) is below. And at the bottom of the post is what was working originally, but without an id on the link...

    <?
    echo "<tr bgcolor=\"#CCCCCC\" style=\"border-bottom:1px solid gray;\"><td> Team </td><td>Correct Picks</td><td>Points</td></tr>";
    while($row = mysql_fetch_array($memberslist)) {
        if ($row['User_ID'] == $id) {
            echo "<tr bgcolor=\"#F0F0F0\"><td>" . "<a href=\"2012week1.php?id=\"$row['User_ID']\"\">$row[User_ID]</a>" . "</td><td><b>" . $row['Correct_Picks'] . " </b> /" . $maxcorrectpicks . "</td><td>" . $row['Points'] . "</td></tr>";
        } else {
            echo "<tr><td>" . "<a href=\"2012week1.php?id=\"$row['User_ID']\"\">$row[User_ID]</a>" . "</td><td><b>" . $row['Correct_Picks'] . " </b> /" . $maxcorrectpicks . "</td><td>" . $row['Points'] . "</td></tr>";
    }
    }
    ?>

 $uniqueid = $_GET["$row['User_ID']"];
 echo $uniqueid;

This is from the first page that worked...

    <?
    echo "<tr bgcolor=\"#CCCCCC\" style=\"border-bottom:1px solid gray;\"><td> Team </td><td>Correct Picks</td><td>Points</td></tr>";
    while($row = mysql_fetch_array($memberslist)) {
        if ($row['User_ID'] == $id) {
            echo "<tr bgcolor=\"#F0F0F0\"><td>" . "<a href=\"2012week1.php\">$row[User_ID]</a>" . "</td><td><b>" . $row['Correct_Picks'] . " </b> /" . $maxcorrectpicks . "</td><td>" . $row['Points'] . "</td></tr>";
        } else {
            echo "<tr><td>" . "<a href=\"otherteam.php\">$row[User_ID]</a>" . "</td><td><b>" . $row['Correct_Picks'] . " </b> /" . $maxcorrectpicks . "</td><td>" . $row['Points'] . "</td></tr>";
    }
    }
    ?>

The problem that you are having is that you are trying to access an array element from within double quotes. You could make this work by wrapping it in curly braces {$row['User_ID']} .

To make your code more readable, and to avoid this problem, just concatenate or use a list of values for echo. I also recommend the usage of htmlspecialchars() to ensure you are creating valid HTML.

echo '<tr><td>',
  '<a href="2012week1.php?id=',
  htmlspecialchars($row['User_ID']),
  '">',
  htmlspecialchars($row[User_ID]),
  '</a>',
  '</td><td>'
  //etc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM