Jash Jacob
Jash Jacob

Reputation: 580

Passing a value through URL

Here is what i want to achieve ; sending ID's through URL's and printing it.

index.html

<a href="print.php?id=1">ID 1</a>
<a href="print.php?id=2">ID 2</a>

receive.php

<?php
    $id_q = $_GET['id'];
    print "The parameters passed through URL are $id_q";
?>

This above code works perfectly, I'm not able to do this with a list of ID's printed with a php command.

The below code is used to print all the PID's in the DB.How do i make every PID printed clickable ? When I add html tags inside PHP code it throws up an error.

print.php

$result = mysqli_query($con,"SELECT * FROM List");

while($row = mysqli_fetch_array($result))
{
  echo $row['PID'];
}

edit-query.php

$pid_q=$_GET[pid];
echo $pid_q;

Upvotes: 1

Views: 275

Answers (5)

Ben Fortune
Ben Fortune

Reputation: 32117

while($row = mysqli_fetch_array($result))
  {
  echo "<a href='receive.php?id=".$row['PID']."'>".$row['PID']."</a>";
  }

If you want to add your own text to a variable or echo, quote it and separate the variable with a "."

Upvotes: 2

dseibert
dseibert

Reputation: 1329

while($row = mysqli_fetch_array($result))
  {
  echo "<p id=".$row['PID']." class='clickable'>" . $row['PID'] . "</p>";
  }

$(document).ready(function(){
  $("#clickable").click(function(){
    $(this)...something...
  });
});

This is a little something you can do using JQuery if you wanted each PID to do something other than refer to another location. It will listen on any

with the clickable class.

Upvotes: 0

Adam
Adam

Reputation: 1975

I believe this is what you mean?

while($row = mysqli_fetch_array($result))
{
    echo '<a href="print.php?' . $row['PID'] . '">Print ID: ' . $row['PID'] . '</a>';
}

Upvotes: 0

StephenCollins
StephenCollins

Reputation: 805

How about...

echo '<a href="print.php?id='. $row['PID'] . '">' . $row['PID'] . '</a>';

Upvotes: 0

UnknownError1337
UnknownError1337

Reputation: 1222

echo '<a href="script.php?id='.$row['PID'].'">'.$row['PID'].'</a>';

you should do that like this

Upvotes: 0

Related Questions