Manipulating text columns in SQL tables using PHP to convert them into clickable URLs

I have a column in my database that stores the top gaining athletes on my fantasy sports website. I want to make each athlete's name a clickable link that directs users to their individual page on our site. Currently, the function in the code is calling the athlete's name as "companyname". Is there a way to turn this into a clickable link within the table? Should I create another function for generating URLs or add a new column for storing them? I'm concerned that the database may only display the URL text without making it an actual hyperlink. Can anyone advise on how to achieve this?

Below is the list of Top Gaining Athletes Today:

  • Jamaal Charles - 0.54%
  • Kyle Rudolph - 0.50%
  • A.J. Green - 0.48%
  • Michael Bush - 0.48%
  • Jared Cook - 0.47%
  • Christian Ponder - 0.45%
  • Alfred Morris - 0.45%
  • Nate Washington - 0.44%
  • Ryan Succop - 0.44%
  • DeMarco Murray - 0.43%
function getTopAthletes($connection){
$i=1;
$query = "SELECT b.companyname, (a.currentprice - a.open)/a.open as performance FROM jm_market a, jm_stocks b WHERE a.symbol = b.symbol AND active = 'Y' ORDER BY performance desc LIMIT 10";
$result=mysql_query($query,$connection) or die('Problem with obtaining top PLAYERS: ' . $query); 
$output = "<table class='tab1 bborder' cellspacing='0'>";
$output.= "<th colspan='4'>Top Gaining Athletes Today</th>";
while($row=mysql_fetch_array($result)){

  // Shorten really long names
  if (strlen($row['companyname']) > 20) {
     $short = explode (' ', $row['companyname']);
     $row['companyname'] = substr( $short[0],0,1 ) . ". ";
     unset($short[0]);
     foreach ($short as $n) {
        $row['companyname'] .= $n . " ";
     } 
     $row['companyname'] = rtrim($row['companyname']);         
  }

    $output .= "<tr ><td width='20px'><strong>" . $i.".</strong></td>";
    $output .= "<td ><strong><a href='" . $row['companyname']."-profile.html'>" . $row['companyname']."</a></strong></td>";
    $output .= "<td><strong>" . number_format(($row['performance']) * 100,2)." %</strong></td></tr>";
    $i++;

}
$output .= "</table>";
return $output;

}

Answer №1

Check out this solution

$output .="<td ><strong><a href='clients.php?name=" . $row['clientname']."'>". $row['clientname']."</a></strong></td>";

By implementing the above code, you will get

<a href='clients.php?name=Sarah'>Sarah</a>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Issue with Ajax Form Handling

I am struggling to get my ajax form post working correctly. It seems like there might be an issue with the $.ajax lines in my code. When the code reaches the $.ajax portion, the console.log() function stops working and the form redirects normally to the aj ...

What is the proper way to integrate a PHP variable containing an SQL query into an already existing SQL query using the $db->updatePhoneNumbers() method?

I'm currently developing a database for Users where each user can have multiple phone numbers. To accomplish this, I've implemented a JavaScript function in the form that generates new input fields and stores the information in a nested array. M ...

Troubleshooting issues with mail subscriptions using Ajax and PHP

My Idea for Implementation I successfully set up a subscription form using PHP initially. However, I wanted to enhance the user experience by implementing an Ajax feature that would display a nice image and a "thank you" message without reloading the pag ...

Getting a count value from the server and converting it into JSON format on an Android device

Seeking assistance with retrieving the number of rows from a server table using JSON parsing and PHP in an Android project. The PHP code shown below successfully fetches the value, but I am unsure about how to proceed with parsing the JSON data. Any guidan ...

Tips to position two shortcode elements next to each other horizontally

I have some code here and I am looking to align the two elements at the bottom, "php echo do_shortcode(wcas-search-form);" and "php do_action('hamzahshop_custom_min_cart');" on the same line horizontally. I am new to this and struggling to figure ...

PHP: Checking for IP addresses in a text file

I'm working on a way to capture the IP address of a user and save it in a text file when they pay to access specific content. Once the IP is saved in the logFile.txt, I want to redirect the paying user to an exclusive content page. Additionally, I&apo ...

Error: Attempting to access the 'SearchBox' property of an undefined variable is not allowed

I have been working on a Google Maps code that displays both public and private schools with different markers for each category. However, when running the code, I encountered an error specifically on this line of code: var searchBox = new google.maps.pl ...

What is the process for sharing your website content on Google Blogger?

I am currently developing a dashboard for a small business website and I would like to implement a feature that allows users to post directly to their Blogger blog from the dashboard of their own website. This eliminates the hassle of having to switch betw ...

Is half of your important information disappearing during JSON conversion?

I have a mysql database of countries, containing 250 records that I want to integrate into an Android app. I understand that using PHP is necessary to convert the data into JSON format. Here is my implementation: <?php require_once('connection. ...

Retrieve just a fragment of the feedback by utilizing the .load directive

Hello there, I've been using Wordpress and I have a shortcode with a bunch of code to arrange my blogs in a specific layout. In addition, I've integrated the isotope plugin as well as the infinite scroll plugin. The infinite scroll feature utili ...

HHVM encountered a critical error and is displaying a 500 error

At the moment, I am in the process of setting up a HHVM server. While PHP applications are working perfectly, hack lang PHP files are not. Every request in my local sandbox returns an error log that looks like this: [Fri Jun 20 15:31:43.725292 2014] [pro ...

Tips for updating a column with just one button in AngularJS

On my list page, there is an Unapproved button. I am new to angular and struggling to figure out how to retrieve the post's id and update the corresponding column in the database to mark it as approved. Can someone provide guidance on how to accomplis ...

Split a string using the final closing parenthesis

I am trying to split a string based on a specific condition. I have attempted various methods, but I am unable to make it work correctly. String Thu Jul 13 10:45:37 2017 : rlm_perl: PPPoE.Auth.INFO: educationhome, NAS_IP 133.1.92.86, PAY_PLAN 0, CLIENT_ ...

Looping through a multidimensional array in $_POST variables

I have developed a form that sends me multiple values using the post function. The $_POST[groups] contains values 1, 2, 4, and 8 based on 4 different checkboxes. Similarly, $_POST[retailgroup] includes only the values 1, 2, and 4. I want to combine these v ...

Azure Function: Eliminate duplicate data in JSON from two many-to-many relationships into a single table

I am facing an issue where I have multiple many-to-many tables mapping to a single table, resulting in duplicate data that needs to be removed from the JSON output. Additionally, the Ingredients and Conditions are displayed as lists, causing duplication of ...

Modify the address fields settings for Checkout and My Account based on the country in Woocommerce

I've implemented code to adjust checkout address fields for more accurate formats in various countries. The segment that updates the labels for UK and New Zealand states is not functioning properly though. In the UK, the County (optional) field retain ...

Using PHP CURL to manually define the content-length header

Imagine I'm using PHP with CURL to upload a file: $postData = array(); $postData['file_name'] = "test.txt"; $postData['submit'] = "UPLOAD"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url ); curl_setopt($ch, CURLOPT_RETUR ...

Transform a JSON dataset into a visually appealing PDF document using mPDF

My current project involves converting a JSON file to a PDF using mPDF. However, I'm encountering an issue where the JSON table is not being displayed in the HTML after running the PHP code. Instead, only one empty PDF page is generated. UPDATE: I ha ...

Error when trying to access wamp

Struggling to set up Zend on Wamp Server, but all I keep getting is: Forbidden You are not authorized to access /blandit/public on this server. Is there a step-by-step guide available for configuring it? ...

tips for uploading image data using JavaScript

My HTML form sends POST data to my PHP script and uses AJAX for a live preview The issue arises with the image input field in the form Here's an example of the form structure: <form method="post" action="scripts/test.php" enctype="multipart/form ...