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

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.