Jump to content

BahBah

Members
  • Posts

    30
  • Joined

  • Last visited

    Never

Everything posted by BahBah

  1. nvm, the above does what you want.
  2. Did this work out for you ? I appreciate that it wasn't the most elegant solution, but should have achieved what you wanted. You didn't state if this was a regularly used function or if it was a one off ...
  3. Hi, I have setup what I hope to be a good working User class. Now I want to introduce group membership and group permissions. Before doing so, I have a couple of questions. Firstly, because users and groups have a relationship would you say that a user inherits a group and therefore group code should be in the User class ? vice versa ? or is it commonly implemented differently ? Secondly, and I am fairly sure I know the answer to this, but I'm guessing that groupID membership shouldn't be stored in the session right ? for security reasons ? Thanks (and Happy Christmas)
  4. That did it. Thank you ! I appreciate your not having seen all of my classes, but is there a common reason for having to access the array in that form ? because it wasn't my intention for it to read like that.
  5. Here's the var_dump: array(1) { [0]=> object(User)#4 (9) { ["id"]=> NULL ["username"]=> NULL ["password"]=> NULL ["title"]=> NULL ["firstname"]=> NULL ["surname"]=> NULL ["email"]=> NULL ["active"]=> NULL ["salt"]=> string(3) "M}8" } }
  6. I suspect this may be down to the actual method that invokes all of this is a public static function. So it doesn't have access to $this. I'm still not sure why I cannot access the array elements though.
  7. Thanks for your reply. When I try $result_array[0]['salt'] I get: Fatal error: Cannot use object of type User as array
  8. Thanks for your reply. This is the error I get when I try that: Notice: Trying to get property of non-object
  9. Hello My object looks like this: Array ( [0] => User Object ( [id] => [username] => [password] => [title] => [firstname] => [surname] => [email] => [active] => [salt] => M}8 ) ) This is the result of a SQL method from my SQL class. $result_array = self::find_by_sql($sql); Can you please tell me how I can access the 'salt' element of the object array above ? I've been trying: $result_array->salt but that doesn't work. Thanks for any assistance.
  10. array_count_values should do it. print_r( count_array_values($top10array) ); It should return as: [score] => [numOccurences]
  11. // while loop your recordset of all 3000 rows here $tempRow = arsort($currentDBrow); for ($i=0;$i<10;$i++) { $top10array[] = $tempRow[$i]; } // end while loop You should now have the top 10 scores over all 3000 records in a single array. You won't know who scored what, but you will know all the scores and will be able to say how many people got the same score. Hrm just tested it, and array_unique won't do it. I'll have a think.
  12. This is not the solution but it may help you debug it. <?php $con = mysql_connect("localhost","********","**********"); if (!$con) {die('Could not connect: ' . mysql_error());} mysql_select_db("bmvybfbk_website", $con); $result = mysql_query("SELECT * FROM templatesearch ORDER BY id"); while($row = mysql_fetch_array($result)) { $tid = $row['id']; $tprice = $row['price']; echo $row['tname'] . "<br>" . $row['preview'] . "<br>" . "Costs: " . $row['price'] . " points. "; echo '<a href="templatesearch.php?action=buy&temp='.intval($tid).'"><font face="Papyrus" size="3">Buy</font></a>'; echo "<br/><br/>"; if ($_GET['action'] == 'buy') { // You should not trust session data for database queries // When storing user login status you should store the userid. You can then easily intval() check it to ensure it's what you were expecting. // In addition a userid on a primary key field in your database is less expensive in terms of performance $result2 = mysql_query ("SELECT * FROM users WHERE username = '$session->username';"); while($row = mysql_fetch_array($result2)) { $totalpoints = $row['points'];} // // Uncomment the following 3 lines and try it. The purpose of this is to see if your SQL query is actually returning any data. If $totalpoints and $tprice return a value remove these lines and reply to your post // echo "tprice: $tprice<br/>\n"; // echo "totalpoints: $totalpoints<br/>\n"; // exit(); // if ($totalpoints >= $tprice) { $result2 = mysql_query ("SELECT * FROM items2 WHERE username = '$session->username';"); while($row = mysql_fetch_array($result2)) { $usedid = $row['name2']; if ($usedid <> $tid) { mysql_query ("UPDATE users SET points = points - '$tprice' WHERE CONVERT( `users`.`username` USING utf8 ) = '$session->username' LIMIT 1;"); mysql_query ("INSERT INTO `items2` (`username`, `name2`, `id2`) VALUES ('$session->username', '$tid', '1');"); mysql_query ("UPDATE users SET tempid = $tid WHERE username = '$session->username' LIMIT 1;"); echo" You bought it! "; echo '<meta http-equiv="refresh" content="1;url=/$session->username">'; } else { echo "You already own it!"; echo '<meta http-equiv="refresh" content="1;url=templateowned.php">'; } } } } } ?>
  13. I'm sorry I'm unclear what you mean. Do you mean you have 3000 sets of arrays containing 20 scores ? and you want to see how many of the same scores show up ? Are each set of 20 scores a row in the database ?
  14. It will be calling what it needs, and it's making that call by filtering/joining primary keys so should be as fast as it can be. It is filtering your members table by which members have an active session in the sessions table. It is also then getting the groups by users it has ascertained from the previous filter. If that isn't clear enough let me know.
  15. Without seeing IPB's database schema I couldn't tell you, but with that said I run a large forum (110,000+ members, 1million+ posts) on vbulletin and I am considering a switch to IPB. I rate them highly, and have confidence in their coding. If your host is complaining about cpu/memory usage because of that particular query it is likely you may have just outgrown their hosting package (assuming you're using a shared host). You can probably turn off WOL for topic views if you wanted. You can in vbulletin and it's often recommended when experiencing high server loads.
  16. It's probably because you're using the same name for your variables as you are your session variables.
  17. Explanation above. Posted the solution, and editted an explanation afterwards. As I mentioned in a previous post, please look into validating and escaping user input before launching this live as your script is open to SQL injection attacks.
  18. Replace $_xml = '<?xml version="1.0"?>'; $_xml = '<rss version="2.0">'; $_xml = '<channel>'; $_xml = '<title>'.'Kingfisher Trust'.'</title>'; $_xml = '<description>'.'The latest news about the charity'.'</description>'; $_xml = '<link>'.'http://www.2asmooth.com/Kingfisher_Trust/news/updatedNewsFeed.xml'.'</link>'; while($row = mysql_fetch_array($result)) { $_xml = '<item>'; $_xml = '<title>'.$row['Title'].'</title>'; $_xml = '<description>'.$row['Date'].'</description>'; $_xml = '<link>'.$row['Link'].'</link>'; $_xml = '</item>'; } $_xml = '</channel>'; $_xml = '</rss>'; with $_xml = '<?xml version="1.0"?>'; $_xml .= '<rss version="2.0">'; $_xml .= '<channel>'; $_xml .= '<title>'.'Kingfisher Trust'.'</title>'; $_xml .= '<description>'.'The latest news about the charity'.'</description>'; $_xml .= '<link>'.'http://www.2asmooth.com/Kingfisher_Trust/news/updatedNewsFeed.xml'.'</link>'; while($row = mysql_fetch_array($result)) { $_xml .= '<item>'; $_xml .= '<title>'.$row['Title'].'</title>'; $_xml .= '<description>'.$row['Date'].'</description>'; $_xml .= '<link>'.$row['Link'].'</link>'; $_xml .= '</item>'; } $_xml .= '</channel>'; $_xml .= '</rss>'; .= Appends 2 strings together. $a = 'hello'; $b = 'there'; $c = $a . ' ' . $b; echo $c; // returns "hello there" You had removed the append from most of the subsequent lines starting with $_xml. If you are appending to the same variable many times you only set the variable = to something once. Subsequent appendages should be $_xml .= 'whatever'; Wrong = $a = 'hello'; $a = 'there'; // overwriting your original assignment of $a = 'hello'; echo $a; // returns "there" Correct = $a = 'hello'; $a .= 'there'; echo $a; // returns "hellothere"
  19. Are you trying to customise an IPB forum ? or are you asking if a standard IPB query is written badly ? If it's the latter, I'd imagine IPB know enough about what they're doing and their database schema to write a well performing query.
  20. Can you repost the updated code that generates the RSS document please ? BTW you really need to look into escaping your variables before doing anything with a database. As you're using MySQL look into mysql_real_escape_string on the PHP site.
  21. What are you using the top 10 keys for ? You could just loop through the first 10 elements and do what you like with them. for ($i=0;$i<10;$i++) { $dosomething = array1[$i]; }
  22. Try changing: $_xml .= '<?xml version="1.0"?>'; for $_xml = '<?xml version="1.0"?>';
  23. Thank you for your replies
  24. Hello I am learning classes, as a long term procedural programmer. To do so I am trying to build myself a user class for authentication. I am finding myself doing error checking in my user class in for example: class User { function create ($userData) { if ( strlen($userData['username']) < MIN_LENGTH || strlen($userData['username']) > 255 ) { return true; } else { return false; } } } What concerns me, is should this error checking be done in the class ? Or should a class be used to perform the function, in this example to create a user. Then the actual error checking should be done either in a seperate class or in the same file as a form processor ? I think I've got myself confused having read up on exceptions. It sounded to me as if exceptions should be handled in classes, and error checking shouldn't be. It is very likely that my interpretation of that is wrong though. Thank you for any assistance.
  25. BahBah

    Using &

    Thank you for your replies. Very helpful
×
×
  • 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.