Solved

what is the function to count all the fields in a table?

Posted on 2008-06-09
6
236 Views
Last Modified: 2010-04-21
lets say i have a table named t1
and it have in this table
id -  place
1 -   india
2 -  florida
3 -  la
4 -  new dom

so when i use the function it will return the nmber 4 for me

so what is this function?
0
Comment
Question by:mgtm3
  • 3
  • 3
6 Comments
 
LVL 48

Expert Comment

by:hernst42
ID: 21745731
the SQL is
"SELECT count(*) FROM t1";
to count all rows in that table
mysql_connect("localhost", "mysql_user", "mysql_password") or

    die("Could not connect: " . mysql_error());

mysql_select_db("mydb");

$result = mysql_query("SELECT count(*) FROM t1");

$row = mysql_fetch_array($result, MYSQL_NUM);

echo $row[0];  

mysql_free_result($result);

Open in new window

0
 

Author Comment

by:mgtm3
ID: 21745791
i am trying to to what u told me
1-i am using mysqli to connect to the sever
2-
                     --this what it did and didnt work ---
$result = mysqli_query("SELECT count(*) FROM pollnames");
$row = mysqli_fetch_array($result, $link);
echo $row[0];  
-----------------------------------------------------------

i got this error


Warning: mysqli_query() expects at least 2 parameters, 1 given in C:\wamp\www\poll\222.php on line 29

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\wamp\www\poll\222.php on line
0
 
LVL 48

Expert Comment

by:hernst42
ID: 21745819
then its:

$result = mysqli_query($link, "SELECT count(*) FROM pollnames");
$row = mysqli_fetch_array($result, $link);
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:mgtm3
ID: 21745840
now i got this error
Warning: mysqli_fetch_array() expects parameter 2 to be long, object given in C:\wamp\www\poll\222.php on line 30
this is what i wrote
 

$result = mysqli_query($link, "SELECT count(*) FROM pollnames");

$row = mysqli_fetch_array($result, $link);

echo $row[0]; 

Open in new window

0
 
LVL 48

Accepted Solution

by:
hernst42 earned 500 total points
ID: 21745952
That was what I copied from your code. Not realy famliliar with mysqli usage. This way should now work:
$result = mysqli_query($link, "SELECT count(*) FROM pollnames");

$row = mysqli_fetch_array($result, MYSQLI_NUM);

echo $row[0]; 

Open in new window

0
 

Author Closing Comment

by:mgtm3
ID: 31465514
thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
PHP Healthcheck 2 86
PHP_POST() error message 9 44
How to keep line breaks when outputting data from database 4 17
Checking CSRF token within a function 36 14
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now