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
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'

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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>";
}
?>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.