Reputation: 1
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>
Upvotes: 0
Views: 60
Reputation: 885
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 "---";
}
?>
Upvotes: 1