0

Hi All,

I am developing a website in which i am selecting some values form database by a query When i am running query on PHPMyAdmin i am getting desired results but when i am using this query in actual PHP code, i am getting value of Last row. Can any one tell me , whats happening wrong?

3
Contributors
6
Replies
18
Views
2 Years
Discussion Span
Last Post by gabrielcastillo
0
<?php 
$projectname = $_GET['type'];
echo $projectname;

include('config.php');
            $sql = "SELECT 
            fld_projectname,fld_projectline,fld_projectpunchline,fld_projectbestimage,fld_projecttype,fld_projectdesp,
            fld_projectfeature1,fld_projectfeature2,fld_projectfeature3,fld_projectfeature4,fld_locationmap,fld_googlemap,
            fld_sitemap,fld_projectimage1,fld_projectimage2,fld_projectimage3,fld_projectimage4,fld_projectimage5,fld_projecttype,fld_projectlocation

         FROM tbl_allproject WHERE fld_encryptname = '$projectname'";

        // echo $sql; exit;



            $rs = mysql_query($sql);
            if(mysql_affected_rows()>0)
            {
            while($row = mysql_fetch_array($rs))
            {
                $projectname = $row['fld_projectname'];
                $projectline = $row['fld_projectline'];
                $projectpunchline = $row['fld_projectpunchline'];
                $propertbestimage = $row['fld_projectbestimage'];

                $projectdesp = $row['fld_projectdesp'];
                $projectfeature1 = $row['fld_projectfeature1'];
                $projectfeature2 = $row['fld_projectfeature2'];
                $projectfeature3 = $row['fld_projectfeature3'];
                $projectfeature4 = $row['fld_projectfeature4'];

                @$projetlocationmap = $row['fld_locatonmap'];
                $projectgooglemap = $row['fld_googlemap'];
                $projectsitemap = $row['fld_sitemap'];
                $projectimage1 = $row['fld_projectimage1'];
                $projectimage2 = $row['fld_projectimage2'];
                $projectimage3 = $row['fld_projectimage3'];
                $projectimage4 = $row['fld_projectimage4'];
                $projectimage5 = $row['fld_projectimage5'];
            }   

            }
            else
            {
                header('location: 404.php');
            }

?>
0

You set your variables in the loop, but you do nothing with them. So what's remembered after the loop are the last results. Either use the variables inside the loop, or store them in an array (probably not necessary).

0
SELECT fld_projectname,fld_projectline,fld_projectpunchline,fld_projectbestimage,fld_projecttype,fld_projectdesp, fld_projectfeature1,fld_projectfeature2,fld_projectfeature3,fld_projectfeature4,fld_locationmap,fld_googlemap, fld_sitemap,fld_projectimage1,fld_projectimage2,fld_projectimage3,fld_projectimage4,fld_projectimage5,fld_projecttype,fld_projectlocation FROM tbl_allproject WHERE fld_encryptname = '84db7b5d4ddff5fb9afffc07d5fe6669'

If i run this query i get desired results, but when i used the varialbes i m getting values of last entry of database.

0

What @pritaeas is saying to you, is that you are setting the results in the while loop to variable names, but you are not printing out the results.

So for instance you would echo out the row in the while loop:

 while($row = mysql_fetch_array($rs))
{
    echo $row['fld_projectname'];
    echo $row['fld_projectline'];
    echo $row['fld_projectpunchline'];
    echo $row['fld_projectbestimage'];
    echo $row['fld_projectdesp'];
    echo $row['fld_projectfeature1'];
    echo $row['fld_projectfeature2'];
    echo $row['fld_projectfeature3'];
    echo $row['fld_projectfeature4'];
    echo $row['fld_locatonmap'];
    echo $row['fld_googlemap'];
    echo $row['fld_sitemap'];
    echo $row['fld_projectimage1'];
    echo $row['fld_projectimage2'];
    echo $row['fld_projectimage3'];
    echo $row['fld_projectimage4'];
    echo $row['fld_projectimage5'];
} 

This will print out the results on to the screen. Or if you wanted to use outside the loop you could store them in a array()

$results = array();

 while($row = mysql_fetch_array($rs))
    {
        $results[] = $row;
    } 
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.