0

Im having a problem with this.
I want to echo out the number of post from every city in N.C
Example:
Wilmington (24) <--*24 is the number of post.
Charlotte (35)
Raleigh (15)

include "connect.php";
$wil ='Wilmington';
$cnt = mysql_num_rows(mysql_query("SELECT add_city FROM dbAdd WHERE $add_city='$wil' "));
echo $cnt;

This is the database.

CREATE TABLE `dbAdd` (
`id` BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`add_user` TEXT NOT NULL ,
`add_city` VARCHAR( 100 ) NOT NULL
) ENGINE = MYISAM ;
2
Contributors
4
Replies
24
Views
3 Years
Discussion Span
Last Post by Cristianh21
1

Your query seems to be incorrect. You should probably not use WHERE $add_city but WHERE add_city (without the $).

Besides that, a COUNT() query might be more efficient here. E.g.:

<?php
$q = 'SELECT COUNT(add_city) AS c FROM dbAdd WHERE add_city = "' . mysql_real_escape_string($wil) . '"';
$rq = mysql_query($q);
$fetch = mysql_fetch_assoc($rq);
$count = $fetch['c'];
0

That worked. Thanks!
Now i want to view the posts only from Wilmington when i click on the link.

This is my wil.php

$wil ='Wilmington';
$add_posts_query = mysql_query("SELECT * FROM dbAdd ORDER BY add_city='$wil' DESC LIMIT 200");

Its seems not to echo out the Wilmington post.
It echos out all the post from all the cities.
I only want the Wilmington posts.

0

What about modifying your query just a little bit, to:

SELECT * FROM dbAdd WHERE add_city = '" . mysql_real_escape_string($wil) . "' ORDER BY add_city DESC LIMIT 200

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.