mcmuney Posted July 29, 2006 Share Posted July 29, 2006 PROBLEM: After the modification, I get this error, "Fatal error: Call to a member function on a non-object in /home/rateomet/public_html/code/stats_sex.php on line 7"I've started with this code, which is valid and functional. This results in showing a number for the various sexual orientation (ie 1,2,etc), because the labels are specified on a different table (ie 1=Straight, 2=Gay, etc):[code]<?php// grab the total count$total_query2 = "SELECT COUNT(sm_sex_orn) FROM sc_member_info";$res2 = mysql_query($total_query2) or die(mysql_error());$total_count = mysql_result($res2, 0, 0);// start the tableecho '<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor=orange><tr bgcolor=orange><td><b><font face=Verdana size=1>Sign</td><td width=50 align=right><b><font face=Verdana size=1>Count</td><td width=50 align=right><b><font face=Verdana size=1>P%</td></tr>';// go through each sexual orientation$sign_query = "SELECT sm_sex_orn, COUNT(sm_sex_orn) AS sex_count FROM sc_member_info GROUP BY sm_sex_orn";$res3 = mysql_query($sign_query) or die(mysql_error());while ($info = mysql_fetch_assoc($res3)){ echo '<tr><td><font face=Verdana size=1>'..$info['sm_sex_orn'].'</td><td align=right><font face=Verdana size=1>'.$info['sex_count'].'</td><td align=right><font face=Verdana size=1>'.round(($info['sex_count'] / $total_count)*100).' %</td></tr>';}// finish the table with the totalecho '<tr><td colspan=3 height=2></td></tr><tr><tr align=right bgcolor=orange><td align=left><b><font face=Verdana size=1>Total Members</td><td><b><font face=Verdana size=1>'.$total_count.'</td><td><b><font face=Verdana size=1>100 %</td></tr></table>';?>[/code]Now, I'm adding the following lines to the above code:[code]$sql = "select sc_sex_orien.sso_id, sc_sex_orien.sso_type, sc_member_info.sm_sex_orn from sc_member_info, sc_sex_orien where sc_sex_orien.sso_id=sc_member_info.sm_sex_orn";$reset3 =$db->select_data($sql);[/code]And, replacing:[code]echo '<tr><td><font face=Verdana size=1>'..$info['sm_sex_orn'].'</td>[/code]With:[code]echo '<tr><td><font face=Verdana size=1>'.$db->get_field("sc_sex_orien","sso_type","sso_id",$rcset[0]['sm_sex_orn']).'</td>[/code]The full modified codes looks like this. This was done so that instead of displaying 1,2, etc, it actually displayes, Straght, Gay, etc:[code]<?php// grab the total count$total_query2 = "SELECT COUNT(sm_sex_orn) FROM sc_member_info";$res2 = mysql_query($total_query2) or die(mysql_error());$total_count = mysql_result($res2, 0, 0);$sql = "select sc_sex_orien.sso_id, sc_sex_orien.sso_type, sc_member_info.sm_sex_orn from sc_member_info, sc_sex_orien where sc_sex_orien.sso_id=sc_member_info.sm_sex_orn";$reset3 =$db->select_data($sql);// start the tableecho '<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor=orange><tr bgcolor=orange><td><b><font face=Verdana size=1>Sign</td><td width=50 align=right><b><font face=Verdana size=1>Count</td><td width=50 align=right><b><font face=Verdana size=1>P%</td></tr>';// go through each sexual orientation$sign_query = "SELECT sm_sex_orn, COUNT(sm_sex_orn) AS sex_count FROM sc_member_info GROUP BY sm_sex_orn";$res3 = mysql_query($sign_query) or die(mysql_error());while ($info = mysql_fetch_assoc($res3)){ echo '<tr><td><font face=Verdana size=1>'.$db->get_field("sc_sex_orien","sso_type","sso_id",$rcset[0]['sm_sex_orn']).'</td><td align=right><font face=Verdana size=1>'.$info['sex_count'].'</td><td align=right><font face=Verdana size=1>'.round(($info['sex_count'] / $total_count)*100).' %</td></tr>';}// finish the table with the totalecho '<tr><td colspan=3 height=2></td></tr><tr><tr align=right bgcolor=orange><td align=left><b><font face=Verdana size=1>Total Members</td><td><b><font face=Verdana size=1>'.$total_count.'</td><td><b><font face=Verdana size=1>100 %</td></tr></table>';?>[/code] Link to comment https://forums.phpfreaks.com/topic/15966-code-check/ Share on other sites More sharing options...
Guest docseussman Posted July 29, 2006 Share Posted July 29, 2006 you are using $db as an object and calling one of it's member functions. In the code you posted you never created the object, $db = new objectname(). This would create the error you are experiencing. Link to comment https://forums.phpfreaks.com/topic/15966-code-check/#findComment-65591 Share on other sites More sharing options...
mcmuney Posted July 29, 2006 Author Share Posted July 29, 2006 I actually took that portion of the code from another working page, but I didn't see the $db being defined as an object. Link to comment https://forums.phpfreaks.com/topic/15966-code-check/#findComment-65608 Share on other sites More sharing options...
DocSeuss Posted July 29, 2006 Share Posted July 29, 2006 well $db-> is definatly the usage for calling a member function of an object(Class), double check the working page and see if you can find the definition of the class. If done correctly it will probably be done in a seperate page and then imported using an include or require near the top of the script. Maybe named database or something similar. If this is the case you can require it in your new script and use any of the functions it may contain. Link to comment https://forums.phpfreaks.com/topic/15966-code-check/#findComment-65621 Share on other sites More sharing options...
mcmuney Posted July 30, 2006 Author Share Posted July 30, 2006 Is there any other way of doing it? Link to comment https://forums.phpfreaks.com/topic/15966-code-check/#findComment-65667 Share on other sites More sharing options...
DocSeuss Posted July 30, 2006 Share Posted July 30, 2006 Absolutly, I just don't understand from the code given what the select_data function is supposed to do. You the code you have shown you never use the variable reset3 anywhere. The closest thing to it is res3 but it is assigned to another value on line 15 anyway. Now in looking line by line trying to figure the code out I see another call to a different function of the same $db object on line 18 ---- $db->get_field. What it looks like is that you are new pretty new to th scene and are trying to piece together some code that works from a different script to make it work with your site database. This is certainly a viable method of learning but I would suggest understanding the code that you are copying and pasting so that you know what it does and what needs to be modified so that it will work for your purpose.I would suggest some of the awsome tutorials phpfreaks has to offer. I don't want you to be discouraged from posting questions here but to answer your question would be pretty much to post a tutorial which I think is beyond the scope of the forum. Link to comment https://forums.phpfreaks.com/topic/15966-code-check/#findComment-65762 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.