Jump to content

[SOLVED] echoing mysql_num_rows


contra10

Recommended Posts

I'm trying to echo the amount of members in a group in a search but i keep getting 0

 

<?php
if($type<>"any"){
mysql_query("select * from groups where name='$search_text'");
}else{
$kt=split(" ",$search_text);//Breaking the string to array of words
// Now let us generate the sql 
while(list($key,$val)=each($kt)){
if($val<>" " and strlen($val) > 0){$q .= " name like '%$val%' or ";}

}// end of while
$q=substr($q,0,(strLen($q)-3));

// this will remove the last or from the string. 

$query="select * from groups where $q ";
$queryacc="select * from groups where name='$search_text' and $q";

} // end of if else based on type value
$nt=mysql_query($query);
$ntacc=mysql_query($queryacc);
echo mysql_error();
$members = mysql_num_rows($ntacc);
while($row=mysql_fetch_array($nt)){
   $eid = "{$row['id']}";
echo "<tr><td valign='top' width='60' height='10'><img src='http://localhost/groupsio/imagereplace.php?id=$eid'></td>";
echo "<td valign='top'><a style='text-decoration:none' href='http://localhost/groupsio/index.php?grp=$eid'>$row[name]</a><br>";
echo "$members Members</td></tr>";
}
?>

Link to comment
https://forums.phpfreaks.com/topic/142903-solved-echoing-mysql_num_rows/
Share on other sites

Do you have access to PHPMyAdmin, or the like?

 

I'd suggest running that query in there until you find what you're looking for. I'm not really sure what you're parameters of your search are, and how your DB is setup.... but I'm going to guess you meant (and as suggested above):

select * from `groups` where `name`='$search_text' OR `name`='$q'

could i somehow run a query in a while statement?

 

<?php
while($row=mysql_fetch_array($nt)){
   $eid = "{$row['id']}";
   
   $qor= mysql_query("select * from groups where id='$eid'");
   $ntacc=mysql_query($qor);
   $members = mysql_num_rows($ntacc);
   
echo "<tr><td valign='top' width='60' height='10'><img src='http://localhost/groupsio/imagereplace.php?id=$eid'></td>";
echo "<td valign='top'><a style='text-decoration:none' href='http://localhost/groupsio/index.php?grp=$eid'>$row[name]</a><br>";
echo "$members Members</td></tr>";
?>

 

i'm trying to catch the eid

this echos the same number

 

<?php
$query="select * from groups where $q ";
$query2 ="select * from groups where $q ";

} // end of if else based on type value
$nt=mysql_query($query);
echo mysql_error();
$members = mysql_num_rows($nt);
while($row=mysql_fetch_array($nt)){
   $eid = "{$row['id']}";
echo "<tr><td valign='top' width='60' height='40'><img src='http://localhost/groupsio/imagereplace.php?id=$eid'></td>";
echo "<td valign='top'><a style='text-decoration:none' href='http://localhost/groupsio/index.php?grp=$eid'>$row[name]</a><br>";
echo "$members Members</td></tr>";
}
?>

A few things...

 

I'm trying to echo the amount of members in a group in a search but i keep getting 0

 

I never saw that part, just the code. Why not just use COUNT()?

 

this echos the same number

 

<?php
$query="select * from groups where $q ";
$query2 ="select * from groups where $q ";

} // end of if else based on type value
$nt=mysql_query($query);
echo mysql_error();
$members = mysql_num_rows($nt);
while($row=mysql_fetch_array($nt)){
   $eid = "{$row['id']}";
echo "<tr><td valign='top' width='60' height='40'><img src='http://localhost/groupsio/imagereplace.php?id=$eid'></td>";
echo "<td valign='top'><a style='text-decoration:none' href='http://localhost/groupsio/index.php?grp=$eid'>$row[name]</a><br>";
echo "$members Members</td></tr>";
}
?>

 

Mind showing what

$query="select * from groups where $q ";
$query2 ="select * from groups where $q ";

outputs? (echo both of those variables)

 

I think count will take care of what you're trying to accomplish, but maybe I'm still unsure of what you're wanting to do

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.