1

Below is my Php code. Would anyone be able to tell me how to remove the hyperlinking of every single SQL entry in this code?

As I don't want my users to click into any of the entries and then directed to another web page. I just want a static table with entries from my sql database.

Thanks very much!

<?
 #Get the event id from $_GET
    $int_event_id = $_GET["EventID"];
    if((int)$int_event_id)
    {
        $pdo = new PDO('mysql:host=localhost;dbname=clubresults', 'root', '12345678');
    #Set Error Mode to ERRMODE_EXCEPTION.
    $pdo->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);  
$query = $pdo->query("SELECT EventName, Score, Place from results WHERE EventID ='$int_event_id' ORDER By EventID ASC");
$rowset = array();

if ($query) {
  while ($row = $query->fetch(PDO::FETCH_ASSOC)) {
    // Build array of rows
    $rowset[] = $row;
  }    

  // Output header first
  $headrow = $rowset[0];
  print("<table border=\"1\">\n<tr>\n");
  // Use $rowset[0] to write the table heading
  foreach ($headrow as $col => $val) {
    printf("<th>%s</th>\n", $col);
  }
  print("</tr>");

  // Then output table rows.
  // Outer loop iterates over row
  foreach ($rowset as $row) {
     print("<tr>");
     // Inner loop iterates over columns using $col => $val
     foreach ($row as $col => $val) {
        // We don't know your column names, but substitute the first column (the ID) for FIRSTCOL here
        printf("<td><a href=\"index.php?ID=%s\">%s</a></td>\n", $row['EventID'],$val);
     }
     print("</tr>");
  }
}}
print("</table>");
?>
2
  • remove <a> from your printf() Commented Jun 1, 2012 at 3:32
  • using printf to insert a var into a string is ... overkill. echo "<th>$col</th>\n"; works just as well. printf should only be used if you're using it to apply formatting to whatever you're inserting. Commented Jun 1, 2012 at 3:39

1 Answer 1

1

If you change this line:

printf("<td><a href=\"index.php?ID=%s\">%s</a></td>\n", $row['EventID'],$val);

To this you should be fine:

printf("<td>%s</td>\n", $val);
Sign up to request clarification or add additional context in comments.

2 Comments

ah terrific! i know it was that line but I just cant figure out what bit to delete haha thanks so much!
If you accept the answers that help you you're much more likely to get good answers in the future.

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.