John Davidson

html - Output 1 Row only of PHP Array as Bold Text

0 comments
Message:


I’m outputting the result of a MySQL query that contains information about users and chosen subjects. I would like to make one row only bold. I would like php to output this row only bold, but leave the rest as standard text. How do I do this?


$resultSet = $db->query ("...my query");  
echo $resultSet -> num_rows;
While($rows = $resultSet ->fetch_assoc())
{
$subject [1] = $rows['First_Name']; //make this row output bold for example
$subject [2] = $rows['Surname'];
$subject [3] = $rows['Email_Address'];
$subject [4] = $rows['Subject1'];
$subject [5] = $rows['Subject2'];
$subject [6] = $rows['Subject2'];

$subjectOutput = array_filter($subject, 'strlen');

$subjectString = implode($subjectOutput, '<br/>');

$output .= "<p> ". $subjectString." </p>";
}


My Answer:
To make only one row bold in the output, you can add a conditional statement inside the loop to check if it is the row you want to make bold. Here's an example of how you can achieve this:

php
$resultSet = $db->query("...my query");
echo $resultSet->num_rows;

while($rows = $resultSet->fetch_assoc())
{
$subject[1] = $rows['First_Name'];
$subject[2] = $rows['Surname'];
$subject[3] = $rows['Email_Address'];
$subject[4] = $rows['Subject1'];
$subject[5] = $rows['Subject2'];
$subject[6] = $rows['Subject2'];

$subjectOutput = array_filter($subject, 'strlen');

$subjectString = implode($subjectOutput, '
');

$output .= '

';

// Check if it is the row you want to make bold
if ($rows['First_Name'] == 'John') {
$output .= '' . $subjectString . '';
} else {
$output .= $subjectString;
}

$output .= '

';
}

echo $output;


In this example, I added a condition to check if the 'First_Name' is 'John' (you can change this to match the specific row you want to make bold). If it matches, the row will be wrapped in `` tags to make it bold. Otherwise, it will be displayed as standard text.

Rate this post

3 of 5 based on 8256 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us