walston Posted September 12, 2007 Share Posted September 12, 2007 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!! Quote Link to comment https://forums.phpfreaks.com/topic/68960-probably-a-read-dumb-question-but/ Share on other sites More sharing options...
kireol Posted September 12, 2007 Share Posted September 12, 2007 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 />"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/68960-probably-a-read-dumb-question-but/#findComment-346623 Share on other sites More sharing options...
walston Posted September 12, 2007 Author Share Posted September 12, 2007 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!!! Quote Link to comment https://forums.phpfreaks.com/topic/68960-probably-a-read-dumb-question-but/#findComment-346627 Share on other sites More sharing options...
kireol Posted September 12, 2007 Share Posted September 12, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/68960-probably-a-read-dumb-question-but/#findComment-346631 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.