Jump to content

Creating a link within PHP output from database


thenorman138
Go to solution Solved by cyberRobot,

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

  • Solution

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.