Echo the whole line mysql_num_rows

I have the following php

  $q=mysql_query("select SMILES from GeoAndEnergies where Weight='".$data."' ") or die(mysql_error());
 $n=mysql_num_rows($q); //not mysql_fetch_row, as that does not return count but an array
 if($n>0)
 {
   $info=mysql_fetch_row($q);
    echo $info[0];
  }
  else {
   echo "molecule not find";
  }

      

I would like to echo not just $ info [0], but $ info [0] + "<" + $ info [1] + "<" .... + $ info [n], what's the correct syntax?

thank

+3


source to share


3 answers


Use a loop while

to fetch all lines



$q=mysql_query("select SMILES from GeoAndEnergies where Weight='".$data."' ") or die(mysql_error());
 $n=mysql_num_rows($q); 

 if($n>0)
 {
   $val='';
   while($info=mysql_fetch_row($q))
    {
      if($val!='')
          $val.=' < ';
      $val.= $info[0];
    }
 }
  else {
   $val= "molecule not find";
  }
 echo $val;

      

+1


source


Ok, you are just printing one, so put it in a loop. I suggest:



$q=mysql_query("select SMILES from GeoAndEnergies where Weight='".$data."' ") or die(mysql_error());
$n=mysql_num_rows($q); //not mysql_fetch_row, as that does not return count but an array
$str = '';
if($n>0)
{
    while ($info=mysql_fetch_assoc($q)) {
        $str .= $info['SMILES'] .'<';
    }
echo substr($str, 0, -1);
} else {
    echo "molecule not found";
}

      

+1


source


Troubleshooting below. using echo ''; print_r ($ info); die; Or in another way, using a loop, you get all the data you need.

0


source







All Articles