Jump to content

[SOLVED] Select statement help


twilitegxa

Recommended Posts

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?

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

<?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 :D

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.