0

I have 2 php echo results from my mysql database. Their request is common and wrapped into one line :

$sql = "SELECT * FROM test WHERE id IN ('9','10')";

I want only the first result to be displayed in h3 style, and the second result to be displayed in normal p style. Using the code below the 2 results are displayed in h3 style.

How do I fix it ?

Thank you in advance.

enter code here

<div class="one-third wow fadeIn">
<span class="circle"><span class="ico pig"></span></span>
<h3>

<?php
$conn = new mysqli($dbhost,$dbuser,$dbpass,$dbname);
if ($conn->connect_error)
{
echo "connection error" ;
}

$sql = "SELECT * FROM test WHERE id IN ('9','10')";
$result = $conn->query($sql);

?>
<?php
if ($result->num_rows > 0) { while($data = $result->fetch_assoc())
{echo $data ['FR']."<br>"; }    } else {echo "---"; }?></h3>
<p>

1 Answer 1

1

Try this

    <?php
        $conn = new mysqli($dbhost,$dbuser,$dbpass,$dbname);
        if ($conn->connect_error)
        {
                echo "connection error" ;
        }
        $sql = "SELECT * FROM test WHERE id IN ('9','10')";
        $result = $conn->query($sql);
    ?>
    <?php
    $i = 0;
    if ($result->num_rows > 0) { 
            while($data = $result->fetch_assoc()){
                  if($i == 0){
                        echo "<h3>".$data ['FR']."<br></h3>"; 
                    }else{
                        echo "<p>".$data ['FR']."<br></p>"; 
                    }
                     $i++;
            }    
    } else {
        echo "---"; 
    }
    ?>
Sign up to request clarification or add additional context in comments.

1 Comment

Yes, it's working, kranthi ! You're a chief ! Thank you. very much !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.