Jump to content
thenorman138

Creating a link within PHP output from database

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?

Share this post


Link to post
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 />";

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×

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.