Nabeel Basheer
Nabeel Basheer

Reputation: 75

How can I produce more than one result in sql ?

The following is a query from which I have taken the result.But right now only one result is printing. I have more than one result in the database.. what should i do in order to print more than one result in header tag

<?php
    $sqlcategories = $ilance->db->query("SELECT q.title_spa FROM " . DB_PREFIX . "categories q LEFT 
                                        JOIN " . DB_PREFIX . "profile_categories a ON (q.cid = a.cid)
                                        WHERE a.user_id = '" . $res_vendor['user_id'] . "'");
        if ($ilance->db->num_rows($sqlcategories) > 0)
        {
            while ($rows = $ilance->db->fetch_array($sqlcategories))
            {  
            $categories='<h3>'.$rows['title_spa'].'</h3>';
            }
         }
?>

Upvotes: 0

Views: 112

Answers (5)

user1248752
user1248752

Reputation:

$categories = '<h3>';    
while ($rows = $ilance->db->fetch_array($sqlcategories))
    {  
       $categories .= $rows['title_spa'];
    }
$categories .= '</h3>';

Upvotes: 0

Rufinus
Rufinus

Reputation: 30773

$categories='';
while ($rows = $ilance->db->fetch_array($sqlcategories))
{  
    $categories.='<h3>'.$rows['title_spa'].'</h3>';
}

Upvotes: 0

Mark Byers
Mark Byers

Reputation: 839144

You probably want to change this line:

$categories = '<h3>'.$rows['title_spa'].'</h3>';

to for example:

$categories .= '<h3>'.$rows['title_spa'].'</h3>';

Upvotes: 1

antyrat
antyrat

Reputation: 27765

Before your query write:

$categories = "";

And then in while operator use concatenation (note the dot . before = operator)

$categories .= '<h3>'.$rows['title_spa'].'</h3>';

After that print $categories variable

echo $categories;

Upvotes: 0

Saiyam Patel
Saiyam Patel

Reputation: 1161

do like this... append string with .= operator

while ($rows = $ilance->db->fetch_array($sqlcategories))
{  
   $categories .='<h3>'.$rows['title_spa'].'</h3>';
}
echo $categories;

OR need to store in array then

while ($rows = $ilance->db->fetch_array($sqlcategories))
{  
   $categories[] ='<h3>'.$rows['title_spa'].'</h3>';
}
printr($categories);

thanks

Upvotes: 0

Related Questions