SQL
Moderator: General Moderators
-
prasadharischandra
- Forum Commoner
- Posts: 57
- Joined: Thu May 09, 2002 2:19 am
- Location: sri lanka
- Contact:
SQL
sql=mysql_query("select count(name)as name1 from ip where name='$ip1' orderby name")
while(row=mysql_fetch_array(sql){
name_real=row['name1'];
}
echo name_real;
this code is not working how to use count sql ???
while(row=mysql_fetch_array(sql){
name_real=row['name1'];
}
echo name_real;
this code is not working how to use count sql ???
-
prasadharischandra
- Forum Commoner
- Posts: 57
- Joined: Thu May 09, 2002 2:19 am
- Location: sri lanka
- Contact:
sql
it's a not a problem i correct it i want to know how is COUNT is using php
thank u
$sql=mysql_query("select count(name)as name1 from ip where name='$ip1' orderby name")
while($row=mysql_fetch_array($sql){
$name_real=$row['name1'];
}
echo $name_real;
this code is not working how to use count sql ???
thank u
$sql=mysql_query("select count(name)as name1 from ip where name='$ip1' orderby name")
while($row=mysql_fetch_array($sql){
$name_real=$row['name1'];
}
echo $name_real;
this code is not working how to use count sql ???
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
-
prasadharischandra
- Forum Commoner
- Posts: 57
- Joined: Thu May 09, 2002 2:19 am
- Location: sri lanka
- Contact:
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
-
prasadharischandra
- Forum Commoner
- Posts: 57
- Joined: Thu May 09, 2002 2:19 am
- Location: sri lanka
- Contact:
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
Then what exactly is not working in your initial code (aside from the semi-colon missing at the end of the $sql line and the closing parenthesis for the while conditions)?
Mac
Mac
Last edited by twigletmac on Wed Jul 24, 2002 3:54 am, edited 1 time in total.
- hob_goblin
- Forum Regular
- Posts: 978
- Joined: Sun Apr 28, 2002 9:53 pm
- Contact:
-
prasadharischandra
- Forum Commoner
- Posts: 57
- Joined: Thu May 09, 2002 2:19 am
- Location: sri lanka
- Contact:
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
I think this is what you are trying to do:
I haven't tested this but it should be something along those lines - you really should read http://www.mysql.com/doc/C/o/Counting_rows.html to see what SQL statements look like for the result you are trying to achieve.
Mac
Code: Select all
$sql = "SELECT name, COUNT(*) as num_rows FROM ip WHERE name='$ip1' GROUP BY name ORDER BY name";
$result = mysql_query($sql) or die(mysql_error().'<p>'.$sql.'</p>');
echo 'Name | Num Rows';
while ($row = mysql_fetch_assoc($sql)) {
$name = $rowї'name'];
$num_rows = $rowї'num_rows'];
echo $name.' | '.$num_rows;
}Mac