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
https://forums.phpfreaks.com/topic/170599-solved-select-statement-help/
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?

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

 

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.