SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Evangelist
    Join Date
    Dec 2004
    Posts
    419
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Just starting out with PHP - simple problem

    I'm used to working with old baby ASP, but have started to learn PHP.

    With this bit of PHP, I am listing the output from one table, and for each loop through it, am running an SQL to run an SQL COUNT statement.

    When I output the SQL statement from the loop, and run it in MySQL, it generates an output, but on the php page, when I echo the 'count_check' variable, it doesn't contain anything.

    No doubt that's because I'm making a stupid error, but I can't see what it is.

    This is the code:

    PHP Code:
    <?php

    $query 
    "SELECT fldID, fldCountry FROM fett_country_list ORDER BY 2";
    $result = @mysql_query($query);

    if (
    $result) {
        echo     
    "<p><table cellpadding='5' cellspacing='1' width='100%'>" .
                
    "<tr><th>Country Name</th><th>Count</th><th>Edit</th><th>Delete</a></th></tr>";

    while(
    $row mysql_fetch_array($resultMYSQL_ASSOC))
    {

        
    $CountryID =    $row['fldID'];
        
    $CountryName =  $row['fldCountry'];

        
    $query2 "select fett_country_list.fldCountry, count(*) AS count_check FROM fett_county_list, fett_country_list WHERE fett_county_list.fldCountryID = fett_country_list.fldID and fett_country_list.fldID = $CountryID GROUP BY fldCountryID;";
        echo 
    "<p>$query2</p>";
        
    $result2 = @mysql_query($query2);

        if (
    $result2) {
            
    $count_check $row['count_check'];
            echo 
    "<p>Count Check: $count_check</p>";
            }

        echo     
    "<tr>" .
                
    "<td>$CountryName</td>" .
                
    "<td>$count_check</td>" .
                
    "<td><a href='manage-country-edit.php?id=$CountryID'>edit</a></td>" .
                
    "<td><a href='manage-country-delete.php?id=$CountryID'>delete</a></td>" .
                
    "</tr>" ;
    }

        echo 
    "</table>";

        }
    else {
        echo 
    "<p>No data</p>";
        }

    ?>
    Thanks

  2. #2
    SitePoint Zealot mwasif's Avatar
    Join Date
    Apr 2007
    Location
    Pakistan
    Posts
    102
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You have to code like
    $row = mysql_fetch_array($result2);
    $count_check = $row['count_check'];

  3. #3
    SitePoint Evangelist
    Join Date
    Dec 2004
    Posts
    419
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you for your help. I see my error now.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •