Jump to content

Creating a link within PHP output from database


thenorman138

Recommended Posts

I have a search function that works perfectly by matching database values and displaying the records on my page. However, I want to make my serial number field in the output a "href " link to open a new page that uses the serial number in the code. I had it working previously with dropdowns but I'm trying to make it work with the search function. 

 

Here's the working code:

 

$search = $connect->real_escape_string($_POST['search']);
 
$resultSet = $connect->query("SELECT * FROM staging WHERE serialNumber LIKE '%$search%'");
 
if($resultSet->num_rows > 0){
while($rows = $resultSet->fetch_assoc())
{
$date = $rows['date'];
$utility = $rows['utility'];
$address = $rows['address'];
$sn = $rows['serialNumber'];
 
$output .= "Date: $date <br />Utility: $utility<br />Address: $address<br />Serial Number: $sn<br /><br />";
 
}
}else{
$output = "No Results";
}

 

}
 
Now, when I try to add the link to the serial number variable, like this:

 

$output .= "Date: $date <br />Utility: $utility<br />Address: $address<br />Serial Number: <a href=\\'/dashboard-display?id='.$row['serialNumber'].''>$sn</a><br /><br />";

 

The page doesn't load. I'm using a PHP reference but I think I may have syntax wrong in the href section. How can I get this to display the info with the link tag around $sn?

Link to comment
Share on other sites

Try changing this

$output .= "Date: $date <br />Utility: $utility<br />Address: $address<br />Serial Number: <a href=\\'/dashboard-display?id='.$row['serialNumber'].''>$sn</a><br /><br />";
 
To this
$output .= "Date: $date <br />Utility: $utility<br />Address: $address<br />Serial Number: <a href='/dashboard-display?id=".$row['serialNumber']."'>$sn</a><br /><br />";
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.