Jump to content

ignace

Moderators
  • Posts

    6,457
  • Joined

  • Last visited

  • Days Won

    26

Everything posted by ignace

  1. Maybe you could both just hire a mercenary and let them duke it out
  2. Has this something to do with you thinking everyone else besides you is incapable of helping? Such arrogance
  3. If he will do that for all your friends he'll soon be out of business plus it ain't fair to give it away to someone for free while another should pay for it? Creating this kind of situations will screw you sideways
  4. <?php function user_get_friends($id, $limit = 0, $orderby = 'rand()', $sort = 'ASC') { $id = intval($id); if (0 === $id) return array(); $result = mysql_query("SELECT * FROM friends WHERE user_id = $id ORDER BY $orderby $sort"); if (!$result) return array(); $friends = array(); $i = 1; while ($row = mysql_fetch_assoc($result)) { $friends[] = $row; if ($limit > 0 && $i === $limit) break; ++$i; } mysql_free_result($result); return $friends; } function html_template_apply($template, $data) { $keys = array_keys($data); foreach ($keys as $key) { $template = str_replace('{' . $key . '}', $data[$key], $template); } return $template; } function html_friends($id) { $friends = user_get_friends($id); $friends_count = sizeof($friends); $html_friends_amount = $friends_count > 1 ? '<a href="#" style="float:right; margin-right:5px;">' . $friends_count . ' Friends</a><br />' : ($friends_count === 1 ? '<a href="#" style="float:right; margin-right:5px;">1 Friend</a><br />' : 'This user has no friends'); $html_template_friends = '{friends_count} Friends ' . '<a href="profile.php?uid={friend_id}">' . '<img src="resize_image.php?file={avatar}&size=60" title="" border="0" />' . '</a>'; $html_friends = ''; foreach ($friends as $friend) { $friend = array_merge($friend, array('avatar' => user_get_avatar($friend['friend_id'])), array('friends_count' => $friends_count)); $html_friends = html_template_apply($html_template_friends, $friend); } return '<div style="float:left; width:400px; margin-top:10px;">' . '<div style="background:#e11919; text-align:center; color:#fff; font-size:14px; font-weight:bold; padding:5px;">' . $html_friends_amount . '</div>' . '<div style="border:1px solid #000; text-align:center; padding-bottom:10px;">' . $html_friends . '</div>' . '</div>'; } function user_get_avatar($id, $default_avatar_path = '') { static $avatars = array(); $id = intval($id); if (0 === $id) return $default_avatar_path; if (!isset($avatars[$id])) { $result = mysql_query("SELECT id, avatar FROM avatars WHERE user_id = $id"); if (!$result) return $default_avatar_path; list($id, $avatar) = mysql_fetch_row($result); $avatars[$id] = $avatar; } return $avatars[$id]; } My 2 cents
  5. Your question was I showed you how you can split your code into multiple functions for added flexibility and better maintainability. My code was not intended to be just copy-pasted to your editor I'm quite frankly amazed that it works I used $_SESSION to show you that the added parameters $profile and $user had no value and could be replaced with something more easier to maintain the same functionality Just add anything you want added to html_profile() Like for example: return '<div style="display:' . ($id == $_SESSION['id'] ? 'block' : 'none') . '; color:#0C0;">THIS IS YOU!</div>' . '.. PS The code I wrote is really powerful like: user_is_friend($user_id, $friend_id, $table_rows = array()) Can be used like: user_is_friend(1, 1); user_is_friend(1, 1, array('user_id' => 1, 'friend_id' => 1)); user_is_friend(1, 1, array(array('user_id' => 1, 'friend_id' => 1), array('user_id' => ..))); This may not be obvious if you just look at the code PPS you also may want to review you DB design/scheme as I found that you used unnecessary tables like friend_requests for example
  6. These questions should not be answered by us but by your business requirements. If you for example want to list these counties it is more beneficial when you query a table with ~100 records and just: SELECT * FROM county Then that it is when you would have to query ~300k rows like: SELECT DISTINCT county FROM users So like I said these questions can not be answered by us as we don't know anything about your domain and we can only make best guesses as to what your approach should be. Remember: a good planning has never hurt anyone.
  7. Have your forwarded your ports on the router? Are all computers connected to the same network?
  8. You need natsort which applies the "natural order sorting" algorithm. This algorithm addresses this problem.
  9. Belgian - a person living in Belgium Beligum doesn't even have such a force (if it has any force at all) I just wanted to know how many Belgian people were on these forums so that we could setup possible meetings, talk about PHP, get a general idea of the knowledge a general belgian PHP developer possesses and start with that knowledge to further educate using presentations. It was just a thought. I didn't knew that having a thorough knowledge of or talking about PHP would be against the law.
  10. If you want to add flexibility to your functions you may want to try: function html_profile($id) { $user = user_get_details($id); $post = user_get_posts($id, 'DESC', 1); $post = empty($post) ? array() : $post[0]; $html_status = 'Status: ' . (empty($post) ? '<em>No status</em>' : $post['status'] . ' - ' . date('F j, Y, g:i:a', strtotime($post['posted']))); $html_about = '<strong>About me</strong><br /><em>' . (isset($user['about_me']) ? $user['about_me'] : 'Unknown') . '</em>'; $html_friend = user_is_friend($id, $_SESSION['id']) ? 'Already friends' : (user_has_invite($id, $_SESSION['id']) ? 'Friend request sent' : '<a href="#" onclick="$.facebox.settings.opacity = 0.2; jQuery.facebox({ajax: \'profile/friends/request.php?uid=$id\'})"> Add as a friend</a>'); $html_username = '<em>' . $user['username'] . '</em>'; $html_register_date = '<em>' . date('F j, Y', $user['date']) . '</em>'; $html_last_active_date = '<em>' . date('F j, Y', $user['last_login']) . '</em>'; $html_maritial_status = '<em>' . (isset($user['rel_status']) ? $user['rel_status'] : 'Unknown') . '</em>'; $html_sexual_orientation = '<em>' . (isset($user['orien_status']) ? $user['orien_status'] : 'Unknown') . '</em>'; $html_looking_for = '<em>' . (isset($user['looking_for']) ? $user['looking_for'] : 'Unknown') . '</em>'; return '<div id="profheader" style="padding-top:10px; min-height:150px; border:1px solid black;">' . '<div style="float:right; width:390px; margin-right:10px;">' . '<div style="background:#E1E3DE; padding:4px;">' . $html_status . '</div>' . $html_about . '</div>' . '<div style="text-align:center; width:130px; float:left;">' . '<img src="resize_image.php?file=' . (isset($user['avatar']) ? $user['avatar'] : 'images/avatars/default.jpg') . '&size=120" border="0" />' . $html_friend . '</div>' . '<div style="margin-left:140px; margin-right:400px;">' . '<strong>User Details</strong>' . '<table>' . '<tr><th>Username</th><td>' . $html_username . '</td></tr>' . '<tr><th>Registered on</th></td>' . $html_register_date . '</td></tr>' . '<tr><th>Last active on</th><td>' . $html_last_active_date . '</td></tr>' . '<tr><th>Maritial status</th><td>' . $html_maritial_status . '</td></tr>' . '<tr><th>Sexual orientation</th><td>' . $html_sexual_orientation . '</td></tr>' . '<tr><th>Looking for</th><td>' . $html_looking_for . '</td></tr>' . '</table>' . '</div>' . '</div>'; } function user_get_details($id) { $id = intval($id); if (0 === $id) return array(); $result = mysql_query("SELECT * FROM users WHERE id = $id"); return $result ? mysql_fetch_assoc($result) : array(); } function user_get_posts($id, $sort = 'ASC', $limit = 0) { $id = intval($id); if (0 === $id) return array(); $result = mysql_query("SELECT * FROM user_status WHERE user_id = $id ORDER BY posted $sort"); if (!$result) return array(); $posts = array(); $i = 1; while ($row = mysql_fetch_assoc($result)) { $posts[] = $row; if ($limit > 0 && $i == $limit) break; ++$i; } mysql_free_result($result); return $posts; } function user_get_friends($id, $limit = 0) { $id = intval($id); if (0 === $id) return array(); $result = mysql_query("SELECT * FROM friends WHERE user_id = $id"); if (!$result) return array(); $friends = array(); $i = 1; while ($row = mysql_fetch_assoc($result)) { $friends[] = $row; if ($limit > 0 && $i == $limit) break; ++$i; } mysql_free_result($result); return $friends; } function user_is_friend($user_id, $friend_id, $table_rows = array()) { $user_id = intval($user_id); $friend_id = intval($friend_id); if ($user_id < 1 || $friend_id < 1) return false; if (!empty($table_rows)) { $key = key($table_rows); if (!is_integer($key)) { return isset($row['user_id']) && isset($row['friend_id']) && $user_id == $row['user_id'] && $friend_id == $row['friend_id']; } else foreach ($table_rows as $row) { if (isset($row['user_id']) && isset($row['friend_id'])) { if ($user_id == $row['user_id'] && $friend_id == $row['friend_id']) return true; } } return false; } else { $result = mysql_query("SELECT user_id FROM friends WHERE user_id = $user_id AND friend_id = $friend_id"); return $result ? true : false; } } function user_has_invite($user_id, $friend_id, $table_rows = array()) { $user_id = intval($user_id); $friend_id = intval($friend_id); if ($user_id < 1 || $friend_id < 1) return false; if (!empty($table_rows)) { $key = key($table_rows); if (!is_integer($key)) { return isset($row['user_id']) && isset($row['friend_id']) && $user_id == $row['user_id'] && $friend_id == $row['friend_id'] && $row['status'] == 0; } else foreach ($table_rows as $row) { if (isset($row['user_id']) && isset($row['friend_id'])) { if ($user_id == $row['user_id'] && $friend_id == $row['friend_id'] && $row['status'] == 0) return true; } } return false; } else { $result = mysql_query("SELECT status FROM friend_requests WHERE user_id = $user_id AND friend_id = $friend_id AND status = 0"); return $result ? true : false; } }
  11. SELECT * FROM table WHERE contact_next > now() ORDER BY contact_next Add a LIMIT if you want to limit the number of rows returned
  12. $body = ''; $dash = str_repeat('=', 70); while ($row = mysql_fetch_assoc($result)) { $message = $row['date'] . PHP_EOL . $row['time'] . PHP_EOL . $row['sport'] . ' - ' . $row['visitor'] . ' at ' . $row['home'] . ' ' . $row['ump1'] . ' ' . $row['ump2'] . ' ' . $row['ump3'] . ' ' . $row['ump4'] . ' ' . $row['ump5'] . PHP_EOL . $row['field'] . PHP_EOL . $row['notes'] . PHP_EOL . $dash . PHP_EOL; $body = $body . $message . PHP_EOL; } $status = mail($to, $subject, $body, $headers); echo 'Mail', (!$status ? ' not ' : ''), 'sent';
  13. Yes. <img src="images.php?image_id=<id>" width="<width>" height="<height>"> images.php must echo out the contents of the BLOB field
  14. By using $_REQUEST['dropdown'] as <select name="dropdown">
  15. Try: function array2csv($array, $separator = ',') { return implode($separator, array_values($array)); } $query = 'SELECT * FROM user'; $result = mysql_query($query); $lines = array(); $include_headers = true; while ($row = mysql_fetch_assoc($result)) { if ($include_headers) { $lines[] = array2csv(array_keys($row)); $include_headers = false; } $lines[] = array2csv($row); } if (false === file_put_contents('CSV.txt', implode(PHP_EOL, $lines))) { echo '<p>Failed to write CSV data</p>'; } Notice the PHP_EOL I was kinda hoping file_put_contents would do this as I passed an array apparently not
  16. What do you want to accomplish and what is lastfs & lastfsend
  17. error_reporting(E_ALL); ini_set('display_errors', 1); In your script and error_reporting = E_ALL display_errors = On in your php.ini
  18. Rename your $result and $row in your inner-while loop
  19. SELECT u.email, c.country FROM user_detail u JOIN country c ON u.country = c.id
  20. Have you looked at these possible solutions? http://www.opensource-it.com/enterprise_solutions/open_source_video_conferencing I tried: "video conferencing open-source" as search query
  21. function array2csv($array, $separator = ',') { return implode($separator, array_values($array)); } $query = 'SELECT * FROM user'; $result = mysql_query($query); $lines = array(); $include_headers = true; while ($row = mysql_fetch_assoc($result)) { if ($include_headers) { $lines[] = array2csv(array_keys($row)); $include_headers = false; } $lines[] = array2csv($row); } if (false === file_put_contents('CSV.txt', $lines)) { echo '<p>Failed to write CSV data</p>'; }
  22. Read here what the possible problems can be http://php.net/manual/en/function.flush.php
  23. This subject has been discussed before here and here
×
×
  • 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.