Jump to content

Probably a read dumb question, but...


walston

Recommended Posts

If I wanted to call something from a database with a php tag, how do I do it? I mean, I know how to do it, but something is wrong so I am asking here. Here's the exact problem.

 

I am trying to call some number values from an mls database (for example, actually exactly like www.utahrealestate.com the table showing the number of listings at the bottom of the main page). So in their documentation it says the name for calling the number of residential listings is countsrescounty, so I used 

<?=$countsres28?>

28 because that is the county code for the county we want the number for. But, that tag doesn't work. What am I doing wrong? Any help would be greatly appreciated.

 

Thanks!!

Link to comment
Share on other sites

you need to learn to use the SQL count statement

 

<?php

// Make a MySQL Connection

 

$query = "SELECT type, COUNT(name) FROM products GROUP BY type";

 

$result = mysql_query($query) or die(mysql_error());

 

// Print out result

while($row = mysql_fetch_array($result)){

echo "There are ". $row['COUNT(name)'] ." ". $row['type'] ." items.";

echo "<br />";

}

?>

Link to comment
Share on other sites

Thanks for the help kireol! I am totally confused by that, other than I can say that there is already a connection established. I just need to find out how to call it in the table cell. For example in other pages on the same site, information is called from tags like I specified

<?=$countsres28?>

and the database connection and all that is already established. For example here is some code from another page on the site (that works):

 

<tr>
                              <td valign="top"><span class="graytext">
                                <?=$this['house-num']?>
                                <?=$this['dir-pre']?>
                                <?=$this['street']?>
                                <?=$this['dir-post']?>
                                <?=$this['unit']?>
                              </span></td>
                            </tr>
                            <tr>
                              <td valign="top"><span class="graytext">
                                <?=$this['city']?>
                  ,
                  <?=$this['state']?>
                  <?=$this['zip']?>
                  <?=$this['county'] ?>
                  County</span></td>
                            </tr>

 

I did also try

<?=$this['countsres28']?>

and

<?=$this['countsres=28']?>

but neither of those worked. I just need to know how to put in one tag to call that number.

 

I hope that makes sense.

 

Thanks!!!

 

 

Link to comment
Share on other sites

I'm not 100% sure what you are asking so here's some code that would answer it in either way you are asking.

 

  $query = "SELECT count(*) from mytable";//this is a string containing SQL code that will check how many total records there are in your table

    $result = mysql_query ($query) or die ("select count failed: ".mysql_error()); // this line executes that SQL

    echo "total rows in this query = ".mysql_num_rows($result)."\n"; //this will print how many records were returned from the database,

                                                                                          //and in this case, that # will be 1, because that 1 row is the row showing how many records is our result

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.