I have a a php website with some code on it to pull from a database after the user has defined some search terms and then show them a table with all their information in it
The problem is even when i do a select * from the tables, i am only getting the first row back.
Code:
$result = mysql_query("SELECT trees.*
FROM trees
INNER JOIN price
ON trees.ID=price.treeid
");
$num_rows = mysql_num_rows($result);
if($num_rows == 0) {
echo "No rows retrieved";
} else {
echo $num_rows;
}
i have 2 rows in my database:
Spruce El Sorbeous Sprucious Green Green Green 100 200
its a tree ma! true NULL NULL NULL
Mayday el daymay red green white 10 4000000
GOING DOWN true Grey true false
when i print out the $num_rows up there, it is only one.
When i print out my table below, there is only one row:
echo '<table border = 0 cellpadding=0 >';
echo '<tr>';
echo '<td><b><u>Name</b></u></td>
<td><b><u>Latin Name</b></u></td>
<td><b><u>Primary Color</b></u></td>
<td><b><u>Secondary Color</b></u></td>
<td><b><u>Fall Color</b></u></td>
<td><b><u>Trunk Color</b></u></td>';
echo '<td><b><u>Description</b></u></td>
<td><b><u>Height</b></u></td>
<td><b><u>Spread</b></u></td>
<td><b><u>Drought Resistant?</b></u></td>
<td><b><u>Flowering?</b></u></td>
<td><b><u>Fruit Producing?</b></u></td>';
echo '</tr>';
while ($row = mysql_fetch_assoc($result)) {
echo '<tr>';
echo '<td>';
echo $row['name'];
echo '</td>';
echo '<td>';
echo $row['latinname'];
echo '</td>';
echo '<td>';
echo $row['primarycolor'];
echo '</td>';
echo '<td>';
echo $row['secondarycolor'];
echo '</td>';
echo '<td>';
echo $row['fallcolor'];
echo '</td>';
echo '<td>';
echo $row['trunkcolor'];
echo '</td>';
echo '<td>';
echo $row['description'];
echo '</td>';
echo '<td>';
echo $row['height'];
echo '</td>';
echo '<td>';
echo $row['spread'];
echo '</td>';
echo '<td>';
echo $row['droughtresistant'];
echo '</td>';
echo '<td>';
echo $row['flowering'];
echo '</td>';
echo '<td>';
echo $row['fruitproducing'];
echo '</td>';
echo '</tr>';
}
echo '<table>';
Since there’s no example of the data in the PRICE table, I’m guessing that only one row was joined.
The question remains, why are you doing that JOIN? You’re not collecting any data from the PRICE table, so what’s the point.
BTW, where in the data is the ID?