Jump to content

Display Properties based on count


DrTrans

Recommended Posts

Heres my Code:

 

$query2 = "SELECT COUNT(*) FROM property WHERE Owner_ID = '$ownerid'";
$result2 = mysql_query($query2);
if ($row2 = mysql_fetch_array($result2)) print"<b>Total Properties Owned:</b> ".$row2[0];

 

This right now displays

Total Properties Owned: 3

 

now below it, how would i do a multiple select textarea box that shoes each property name. 

 

the column in the mysql database in the property table is "PropertyName"

 

This has stumped me..

Thanks for your help.

 

Link to comment
https://forums.phpfreaks.com/topic/171705-display-properties-based-on-count/
Share on other sites

Just query all the records first. You can then use mysql_num_rows() to get the count.

 

Also, any reason you are using $query2, $result2. Unless you are still using the previous query and result you are just creating more variables in memory

 

I would also suggest separating the logic from the output. I assumed that there was a unique ID for the property records as well.

 

PHP Logic

<?php

$query = "SELECT propertyID, PropertyName FROM property WHERE Owner_ID = '$ownerid'";
$result = mysql_query($query);

$propertyCount = mysql_num_rows($result);
$propertyOptions = '';

while ($row = mysql_fetch_assoc($result)
{
    $propertyOptions = "<option value="{$row['propertyID']}">{$row['propertyname']}</option> ";
}

?>

 

Output

Total Properties Owned: <?php echo $propertyCount; ?>
<br /><br />

Select a property:
<select name="property">
  <?php echo $propertyOptions; ?>
</select>

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.