contra10 Posted January 29, 2009 Share Posted January 29, 2009 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>"; } ?> Quote Link to comment Share on other sites More sharing options...
Philip Posted January 29, 2009 Share Posted January 29, 2009 What's this in your query? and $q I think you forgot the first part of and `col`='$q' ? Quote Link to comment Share on other sites More sharing options...
contra10 Posted January 29, 2009 Author Share Posted January 29, 2009 $q suppose to break down the group name from mysql...suppose to be a keyword search...it works...but when i put "name='$q'"; it doesn't work Quote Link to comment Share on other sites More sharing options...
MadTechie Posted January 29, 2009 Share Posted January 29, 2009 $queryacc="select * from groups where name='$search_text' and $q"; //AND ? shouldn't that be OR ? Quote Link to comment Share on other sites More sharing options...
contra10 Posted January 29, 2009 Author Share Posted January 29, 2009 with or it echos just one number in this case "2" i guess its echoing the number of groups this user is in Quote Link to comment Share on other sites More sharing options...
Philip Posted January 29, 2009 Share Posted January 29, 2009 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' Quote Link to comment Share on other sites More sharing options...
contra10 Posted January 29, 2009 Author Share Posted January 29, 2009 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 Quote Link to comment Share on other sites More sharing options...
contra10 Posted January 29, 2009 Author Share Posted January 29, 2009 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>"; } ?> Quote Link to comment Share on other sites More sharing options...
Philip Posted January 29, 2009 Share Posted January 29, 2009 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.