0

I am using this code to search my sql database, it works but if there are more then one result it will just display them next to each over

Example:

echo "".$row['nick'].""; //would be NAME1NAME2NAME3NAME4

i would like to display

NAME1
MORE INFO

NAME2
MORE INFO

NAME3 
MORE INFO

.

<?php 
 $conn = mysql_connect ("*****", "battlefield", "*****") or die ('I                            
 cannot connect to the database because: ' . mysql_error()); 
 $selected = mysql_select_db ("battlefield") 
or die ("Could not select database"); 


// PHP Search Script 

$sql = "SELECT * FROM loadout WHERE nick LIKE '%".$_POST['find']."%'"; 
$result = mysql_query($sql,$conn)or die (mysql_error()); 


if (mysql_num_rows($result)==0){ 
echo "Theres no one here called that!"; 
}else{ 
while ($row = mysql_fetch_array($result)){ 
echo "".$row['nick']."";
} 
} 

mysql_close(); 
?>

If you need the html or more info please ask xD

Thanks in advance!

Strawberry
  • 33,750
  • 13
  • 40
  • 57

1 Answers1

0

Just add <br> :) !

while ($row = mysql_fetch_array($result)){ 
     echo "".$row['nick']." <a href='link'>MORE INFO</a><br>";
} 

Or if you want to display it somewhere else in the page, add all results to ann array and then iterate through them wherever you want:

Store them:

while ($row = mysql_fetch_array($result)){ 
     $results[] =  $row['nick']." <a href='link'>MORE INFO</a><br>";
} 

Display them:

foreach ($results as $result) {
     echo $result;
}
Dor Moshkovitz
  • 371
  • 1
  • 3
  • 9