[SOLVED] Need Help!

This is a discussion on "[SOLVED] Need Help!" within the PHP Forum section. This forum, and the thread "[SOLVED] Need Help! are both part of the Program Your Website category.


 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices




Closed Thread
 
LinkBack Thread Tools
  #1  
Old Oct 24th, 2007, 19:06
Up'n'Coming Member
Join Date: Apr 2007
Location: Canada
Posts: 88
Thanks: 0
Thanked 0 Times in 0 Posts
[SOLVED] Need Help!

Hi Friends!

Here I am again, looking for some help. In my page I have people registered from different country. Now I want to show that in my page at a glance how many registered people from which country. And it should change the number automatically and should add the country name automatically for any new entry. Is it too complicated? If anyone would kind enough to show me the code and explain I would be graeful to you. Thanks
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!

  #2  
Old Oct 24th, 2007, 20:27
Highly Reputable Member
Join Date: Apr 2007
Location: Willich, Germany
Age: 20
Posts: 593
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Need Help!

What kind of a registration system do you have? A database? If so, which fields do you have in your users table?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
  #3  
Old Oct 24th, 2007, 20:42
Up'n'Coming Member
Join Date: Apr 2007
Location: Canada
Posts: 88
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Need Help!

Hi c010,
I am using MySQL and filed is userid(I user email address), password, Name , address, age, profession, tel, country, active. Hope that is you are asking.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
  #4  
Old Oct 25th, 2007, 06:14
Highly Reputable Member
Join Date: Apr 2007
Location: Willich, Germany
Age: 20
Posts: 593
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Need Help!

OK, then this should be relatively easy....

If you could explain a bit more in detail what kind of help you need (PHP code, or the mySQL query....). Or, even better, post some code....
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
  #5  
Old Oct 25th, 2007, 06:34
Up'n'Coming Member
Join Date: Jun 2007
Location: Germany
Age: 23
Posts: 50
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Need Help!

pMaybe i can add a simple demonstration for you:
PHP: Select all

<?php
// At this point, the connection to the database is already made (mysql_connect...)

// get all countries of the database, order by countryname
$allc_query mysql_query("SELECT DISTINCT country FROM registertable ORDER BY country");
while(
$allc_row mysql_fetch_array($allc_query))
{
  
// get the number of users from this country
  
$thisc_query mysql_query("SELECT id FROM registertable WHERE country LIKE '".$allc_row['country']."'");
  
$thisc_num mysql_num_rows($thisc_query);

  
// Print that!
  
echo("Users from country ".$allc_row['country'].": ".$thisc_num."<br />");
}
?>
Have fun!

Last edited by Lucleonhart; Oct 25th, 2007 at 15:08. Reason: Just changed your [ code ] to [ php ] ;)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
  #6  
Old Oct 25th, 2007, 13:47
Up'n'Coming Member
Join Date: Apr 2007
Location: Canada
Posts: 88
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Need Help!

Hi c010,
I need the full code for that as I am a novice in php. Your help woud be much appreciated. I want the result to be visible on my page in a text formant as
Country No. of User
Canada 10 Something like this. Thanks

Hi Lucleonhart,
Thanks for your code, but it is showing me only "Users from country: this nothing else....Pls let me know.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
  #7  
Old Oct 25th, 2007, 14:03
Up'n'Coming Member
Join Date: Apr 2007
Location: Canada
Posts: 88
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Need Help!

Hi Lucleonhart,

Sory it was my mistake. It give me the number of people but not the country name eg: it is like this

Users from country: 10 but no country name?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
  #8  
Old Oct 25th, 2007, 14:08
Up'n'Coming Member
Join Date: Jun 2007
Location: Germany
Age: 23
Posts: 50
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Need Help!

Oh! there was an mistake from me. just delete one "$" of $$allc_row['country'] in the display line.
I have edited my last post.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
  #9  
Old Oct 25th, 2007, 14:52
Up'n'Coming Member
Join Date: Apr 2007
Location: Canada
Posts: 88
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Need Help!

Great! it works fine. Now how we can show the result of the scripts on the page without manually running it. and I want that in two colum. first country and 2nd No. of user. Will it automatically update the info everytime you refresh the page ? Hope I am not asking too much?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
  #10  
Old Oct 25th, 2007, 15:08
Up'n'Coming Member
Join Date: Jun 2007
Location: Germany
Age: 23
Posts: 50
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Need Help!

Ehm.. it actually IS working automatically.. no?

So, you just place it at the position, where the results should appear:
PHP: Select all

<body>
~~
here is the head~~
~~
then some content~~
<
div>~a div maybe~</div>
<
table><tr><td>~now comes the stats:
*
INSERTSCRIPTHERE*
</
td></tr></table>
</
body
You see, it can be placed, whereever you want.

For a table style with two collums, you start the table before the script and end it afterwards. Also you have to edit the display a bit. Here comes the example:
PHP: Select all

<span style='font-weight:bold;'>The Country stats</span>
<table>
<?php
// At this point, the connection to the database is already made (mysql_connect...)

// get all countries of the database, order by countryname
$allc_query mysql_query("SELECT DISTINCT country FROM registertable ORDER BY country");
while(
$allc_row mysql_fetch_array($allc_query))
{
  
// get the number of users from this country
  
$thisc_query mysql_query("SELECT id FROM registertable WHERE country LIKE '".$allc_row['country']."'");
  
$thisc_num mysql_num_rows($thisc_query);

  
// Print that!
  
echo("<tr><th>Users from country ".$allc_row['country'].":</th><td>".$thisc_num."</td></tr>");
}
?>
</table>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
  #11  
Old Oct 25th, 2007, 16:10
Up'n'Coming Member
Join Date: Apr 2007
Location: Canada
Posts: 88
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Need Help!

Hi,
I was just trying the basic one with following code and getting on page just "); } ?> any idea

PHP: Select all

<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>New Page 1</title>
</head>
<body bgcolor="#60B773">
<?php
// At this point, the connection to the database is already made (mysql_connect...)
include "include/z_db.php";
// get all countries of the database, order by countryname
$allc_query mysql_query("SELECT DISTINCT country FROM tbl_login ORDER BY country");
while(
$allc_row mysql_fetch_array($allc_query))
{
  
// get the number of users from this country
  
$thisc_query mysql_query("SELECT id FROM tbl_login WHERE country LIKE '".$allc_row['country']."'");
  
$thisc_num mysql_num_rows($thisc_query);
  
// Print that!
  
echo("country ".$allc_row['country'].": ".$thisc_num."<br />");
}
?></body>
</html>

Last edited by c010depunkk; Oct 25th, 2007 at 20:37. Reason: added [PHP] tags
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
  #12  
Old Oct 25th, 2007, 20:09
Up'n'Coming Member
Join Date: Jun 2007
Location: Germany
Age: 23
Posts: 50
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Need Help!

You have to consider, that this is a PHP script! You cannot open it like a normal document. Ithas to be parsed through a PHP server first.
To check it manually, you should install a package like xampp (http://www.apachefriends.org/de/xampp.html). It will install an Apache Webserver with PHP support and other additional featurs like MYSQL.

So after you installed it, put your file in the "htdocs" directory of xampp, start xampp using the "xampp-control.exe" and open your browser.
DO NOT simply open the file, instead type
http://localhost/yourfilename.php
localhost points to the "htdocs" folder of xampp. Now, the PHP script will be transmitted through the PHP server and will be executed.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
  #13  
Old Oct 25th, 2007, 20:54
Up'n'Coming Member
Join Date: Apr 2007
Location: Canada
Posts: 88
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Need Help!

Hi Lucleonhart,
Yes, I am using a php server where it works fine with your first code. It just not working after I put that in to a existing html file as you described. Thanks
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
  #14  
Old Oct 25th, 2007, 21:26
Highly Reputable Member
Join Date: Apr 2007
Location: Willich, Germany
Age: 20
Posts: 593
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Need Help!

How about posting the code you have. We can then have a look and see if we can spot the problem.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
  #15  
Old Oct 25th, 2007, 22:07
Up'n'Coming Member
Join Date: Apr 2007
Location: Canada
Posts: 88
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Need Help!

Hi,
Just see the three postings earlier , I have posted the code with error message, thanks
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
  #16  
Old Oct 25th, 2007, 23:42
Rob's Avatar
Rob Rob is offline
Webforumz Founder
Join Date: Jul 2003
Location: Southern UK
Age: 34
Posts: 3,188
Blog Entries: 7
Thanks: 27
Thanked 23 Times in 20 Posts
Re: Need Help!

can you upload the code in .txt format using an attachment?
__________________
Click the 'Thanks!' button if this post has helped you

Rob - Webforumz Founder
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
  #17  
Old Oct 26th, 2007, 00:06
Reputable Member
Join Date: Jun 2007
Location: uk
Posts: 459
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Need Help!

HTML: Select all
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>New Page 1</title>
</head>
<body bgcolor="#60B773">
<?php
// At this point, the connection to the database is already made (mysql_connect...)
include "include/z_db.php";
// get all countries of the database, order by countryname
$allc_query = mysql_query("SELECT DISTINCT country FROM tbl_login ORDER BY country");
while($allc_row = mysql_fetch_array($allc_query))
{
  // get the number of users from this country
  $thisc_query = mysql_query("SELECT id FROM tbl_login WHERE country LIKE '".$allc_row['country']."'");
  $thisc_num = mysql_num_rows($thisc_query);
  // Print that!
  echo("country ".$allc_row['country'].": ".$thisc_num."<br />");
}
?></body>
</html>
 
Sorry if I am pointing out the obvious, but have you opened your db connection on line one of the above page before the first <html> tag.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
  #18  
Old Oct 26th, 2007, 00:34
Up'n'Coming Member
Join Date: Apr 2007
Location: Canada
Posts: 88
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Need Help!

Hi dab42pat

PHP: Select all

include "include/z_db.php"

this is my db connection page
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!