highaspen Posted March 21, 2006 Share Posted March 21, 2006 I think I just need some help thinking through this. I'm using the query below but it's returning 0 and I knwo that to be innacurate.$sql='SELECT COUNT(*) FROM members WHERE owner="$valid_user"';Here is what I want it to do: count the number of times the $valid_user appears in the owner column in the members table. I'm wondering if I have a logic problem. I'm not getting any mysql errors during the query but when calling the aray in to the page using:<? echo ($rs['0']); ?>I'm getting zero. Below is the full code for my query (FYI). Thanks to all you smart people helping this dumb guy.--------------------------------include ("../global_vars.php");$valid_user = $_POST['userid'];$conn=@mysql_connect("$dbserver", "$dbuser","$dbpass") or die ('Could not connect. Error: ' . mysql_error());$rs = @mysql_select_db("$dbtable", $conn) or die ('Could not select database. Error: '. mysql_error()); $sql='SELECT COUNT(*) FROM members WHERE owner="$valid_user"'; #execute the query$rs=mysql_query($sql,$conn) or die('Could not execute query. Error: '. mysql_error()); $rs = mysql_fetch_array($rs); Quote Link to comment Share on other sites More sharing options...
micah1701 Posted March 21, 2006 Share Posted March 21, 2006 $sql='SELECT owner FROM members WHERE owner="$valid_user"';$rs=mysql_query($sql,$conn);$rows_returned = mysql_num_rows($rs);echo $rows_returned; Quote Link to comment Share on other sites More sharing options...
highaspen Posted March 21, 2006 Author Share Posted March 21, 2006 [!--quoteo(post=357005:date=Mar 21 2006, 09:31 AM:name=micah1701)--][div class=\'quotetop\']QUOTE(micah1701 @ Mar 21 2006, 09:31 AM) [snapback]357005[/snapback][/div][div class=\'quotemain\'][!--quotec--]$sql='SELECT owner FROM members WHERE owner="$valid_user"';$rs=mysql_query($sql,$conn);$rows_returned = mysql_num_rows($rs);echo $rows_returned;[/quote]Thanks man... lookis like it's working.Cheers. Quote Link to comment Share on other sites More sharing options...
txmedic03 Posted March 22, 2006 Share Posted March 22, 2006 I believe it is something like:[code]<?php echo mysql_query("SELECT count(*) as num FROM members WHERE owner='".$valid_user."'", $conn); ?>[/code]I would do it micah's way though so I could requisition the information from the database as well as the count. With this method you must do a query to get the count then query again to get what information you might wish to display or use. I only post this because it is the way you were attempting at first. I forget now if this is correct or not and I'm half asleep, but if this isn't exactly right it is pretty close if memory serves... 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.