0

This is a MySQL PHP question...
how to count no of fields in a perticular database and in a perticular table??

I have three columns in a table :id , name , info
I have to print the unique persons.. how could I??
How to code it in php??
Can any one help..

Edited by kirtan_thakkar: n/a

3
Contributors
15
Replies
16
Views
7 Years
Discussion Span
Last Post by kirtan_thakkar
0
$query = "SELECT * FROM symbols";
// execute query 
$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); 
//Return number of fields based on your query and the table.
echo mysql_num_fields($result);

PHP have a function like returning rows. what do you want to know? counting no of fields or printing values whatever you have in the table. Anyway you have id as a primary key right? then you can directly print all the records.

Edited by rajarajan07: n/a

0

It is returning the columns..
But i have to count rows..

0
$query = "SELECT * FROM symbols";
// execute query 
$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); 
//Return number of rows based on your query and the table.
echo mysql_num_rows($result);

Edited by rajarajan07: n/a

0

Thanks..
And how to print Unique names from the name field???

Edited by kirtan_thakkar: n/a

0

did you have duplicate names in your column?

SELECT DISTINCT "column_name"
FROM "table_name"
SELECT DISTINCT names
FROM symbols

Edited by rajarajan07: n/a

0

Yes..

0

it is printing "Resource id #5"
i have used the code like this..

$q2 = "SELECT DISTINCT name FROM persons";
 $r2=mysql_query($q2) or die ("Error in query: $q2. ".mysql_error());
 echo $r2;

I have to print a name with a link on it..

0

it is printing "Resource id #5"
i have used the code like this..

$q2 = "SELECT DISTINCT name FROM persons";
$r2=mysql_query($q2) or die ("Error in query: $q2. ".mysql_error());
echo $r2;

I have to print a name with a link on it..

Edited by kirtan_thakkar: n/a

0
$query = "SELECT DISTINCT name FROM persons";
$result=mysql_query($query) or die ("Error in query: $q2. ".mysql_error());
if (mysql_num_rows($result) > 0) { 
 while($row = mysql_fetch_row($result)) {
    echo $row[0] + "<br/>;
 }
}

Try the code and get me back

0

output is "00"...

0

Much easier to just change the select statement in working code (i.e. rajarajan's):

$query = "SELECT DISTINCT name FROM persons";
// execute query 
$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); 
//Return number of rows based on your query and the table.
echo mysql_num_rows($result);
0

Much easier to just change the select statement in working code (i.e. rajarajan's):

$query = "SELECT DISTINCT name FROM persons";
// execute query 
$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); 
//Return number of rows based on your query and the table.
echo mysql_num_rows($result);

Thank you ..
But I want to print that distinct names....

Edited by kirtan_thakkar: n/a

0
SELECT DISTINCT name FROM persons;

Run this query in php admin sql editor and tell me whether it returns the rows.

0
SELECT DISTINCT name FROM persons;

Run this query in php admin sql editor and tell me whether it returns the rows.

Yes it returns rows..

This topic has been dead for over six months. 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.