0

I want to do a a query to a mysql database that returns multiple rows and columns. I then want to assign the results to a variable and echo them out later in the page. However, the method I am using is long, tedious, and for this project impractical. here is what I am doing.

$result = mysql_query("SELECT * FROM people WHERE open_or_closed !='Closed' ORDER BY 
number",$c) or die("two");
$number=mysql_num_rows($result);
if($mynumber>0){
$data= mysql_fetch_array($result,MYSQL_ASSOC);
$full_name1=mysql_result($result,0, 'full_name');  
$phone_number1=mysql_result($result,0, 'phone_number');
$one=1;
}
if($mynumber>1){
$full_name2=mysql_result($result,1, 'full_name');  
$phone_number2=mysql_result($result,1, 'phone_number');
$two=2;
}

Later when I want to echo it, I will not know if there is a record there or not, so I will have to

<?php if($one==1){echo '<div id="blackline"></div>';}?>
<div id="titletext"><?php echo $full_name1; ?></div><br /> 
<div id="datetext"><?php echo $phone_number1; ?></div>
tshepang
  • 12,111
  • 21
  • 91
  • 136
Tim
  • 63
  • 1
  • 1
  • 10
  • [mysql functions are deprecated](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php) – Alexander Feb 04 '14 at 07:33

1 Answers1

0

Try this

 $result = mysql_query("SELECT * FROM people WHERE open_or_closed !='Closed' ORDER BY 
    number",$c) or die("two");
    $number=mysql_num_rows($result);    
    if($number>0)   
        {
            $i=0;
        while($row_result = mysql_fetch_array($result))
            {
            $full_name[$i][] = $row_result['full_name'];
            $phone_number[$i][] = $row_result['phone_number'];

            $i++;
            }

        }
Rahul Narhe
  • 181
  • 2
  • 14
  • Maybe you could explain a little more. I don't understand what you did but when I tried to still echo out $full_name1 etc, nothing was there. – Tim Feb 04 '14 at 07:53