twilitegxa Posted August 17, 2009 Share Posted August 17, 2009 How do I write a statement that will display the records of the attributes table, displaying the attribute field, in this code? I want the attribute field listed where the id field matches the id field in the scout_attributes table. Here is what I have so far: // gather attributes and sub-attributes $get_attributes = "select * from scout_attributes where identity = 'Sailor Moon'"; $get_attributes_res = mysql_query($get_attributes, $conn) or die(mysql_error()); $display_block .= " <td valign=top> <table cellspacing=3 cellpadding=3 border=1> <th colspan=3>Character Attributes And Sub-Attributes</th> <tr> <td><b>Attribute/Sub-Attribute</b></td> <td><b>Level</td> <td><b>Points</b></td> </tr>"; while ($attributes_info = mysql_fetch_array($get_attributes_res)) { $attributes_id = $attributes_info['id']; $attribute_identity = $attributes_info['identity']; $attribute_id = $attributes_info['attribute_id']; $attribute_level = $attributes_info['level_id']; $display_block .= " <tr> <td>$attribute</td> <td>$attribute_level</td> <td> </td> </tr>"; } I tried to write another select statement and while statement, but it gave some error. I'm not sure how to do this. Can anyone help? Quote Link to comment Share on other sites More sharing options...
Catfish Posted August 17, 2009 Share Posted August 17, 2009 i dont understand what you want to do. please try to clarify. Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted August 17, 2009 Author Share Posted August 17, 2009 I have a table that will display: <td>$attribute</td> <td>$attribute_level</td> <td> </td> I have the code that is displaying the $attribute_level. What i need is to get the attribute from a table named "attributes". The table has two fields: id and attribute. What I want displayed is the "attribute" field when the "id" field matches the "id" field in the table named "scouts_attributes". The "scouts_attributes" table has 4 fields: id, identity, attribute_id, and level_id. Does that make any more sense? Quote Link to comment Share on other sites More sharing options...
DarkendSoul Posted August 17, 2009 Share Posted August 17, 2009 <?php // gather attributes and sub-attributes $get_attributes = "select * from scout_attributes where identity = 'Sailor Moon'"; $get_attributes_res = mysql_query($get_attributes, $conn) or die(mysql_error()); $display_block .= " <td valign=top> <table cellspacing=3 cellpadding=3 border=1> <th colspan=3>Character Attributes And Sub-Attributes</th> <tr> <td><b>Attribute/Sub-Attribute</b></td> <td><b>Level</td> <td><b>Points</b></td> </tr>"; while ($attributes_info = mysql_fetch_array($get_attributes_res)) { $attributes_id = $attributes_info['id']; $attribute_identity = $attributes_info['identity']; $attribute_id = $attributes_info['attribute_id']; $attribute_level = $attributes_info['level_id']; $display_block .= " <tr> <td>$attribute</td> <td>$attribute_level</td> <td> </td> </tr>"; $more_attrs = mysql_query("SELECT * FROM attributes WHERE id = '{$attribute_id}'"); while ($attr_info = mysql_fetch_array($more_attrs)) { $display_block .= " <tr> <td> </td> <td> </td> <td>{$attr_info["attribute"]}</td> </tr>"; } } ?> No idea how you want it displayed but that might work Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted August 17, 2009 Author Share Posted August 17, 2009 That worked! I don't know what I was doing wrong. I think I just needed to do the id = '$attribute_id'. For some reason I coudn't figure that out. Thanks! Quote Link to comment Share on other sites More sharing options...
Catfish Posted August 17, 2009 Share Posted August 17, 2009 You were only fetching data from one mysql table in the original one. Any how, you got it going, hope you learnt something from this. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.