Jump to content

[SOLVED] mysql_fetch_array in dedicate while


Emran

Recommended Posts

hi all

i am new in PHP.

think i have 2 table

category(ID, name, type)

feature(ID, categoryID, sentence)

 

    mysql_connect("localhost", "root", "");
    mysql_select_db("cost");
    $categories = mysql_query("SELECT * FROM category") or die(mysql_errno()." : ".mysql_error());
    while($catRow = mysql_fetch_array($categories)) {
        echo("<B>$catRow[name]</B><BR />");
        $features = mysql_query("SELECT * FROM feature WHERE categoryID = $catRow[iD]") or die(mysql_errno()." : ".mysql_error());
        while ($featureRow = mysql_fetch_array($features))
        {
            if ($catRow[type] == 0)
            {
                echo("<input type=\"radio\" id=\"_$featureRow[iD]\" /><lable for=\"_$featureRow[iD]\">$featureRow[sentence]</lable>");
            }
            else
            {
                echo("<input type=\"checkbox\" id=\"_$featureRow[iD]\" /><lable for=\"_$featureRow[iD]\">$featureRow[sentence]</lable>");
            }
            echo ("<BR />");
        }
    }
    
    mysql_close();

 

i use code blow, but when i have 2 category, it will show first category content and second category content will not show. i debug code and i see when second while finished when again want to start mysql_fetch_array($features) will returen false, why?

 

note : category.ID is PK and feature.categoryID is FK

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.