Jump to content

jacko310592

Members
  • Posts

    222
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

jacko310592's Achievements

Regular Member

Regular Member (3/5)

0

Reputation

  1. hey guys, i've been coding in PHP for a while now, but still not really touched on constants ..i know, naughty right?! so in the effort of cleaning out a few variables which don't change their value throughout the execution of the script, i was just wondering whether the small snippet of code below is the correct way of holding the data: define('COMPID', md5($_SERVER['HTTP_USER_AGENT'])); which i have used to replace: $COMPID = md5($_SERVER['HTTP_USER_AGENT']); so as you can see, the code is grabbing the user's user agent, and using it as an ID; this data is not changed at all throughout the running of the script, it is just referred to. so is it okay to inject a variable ($_SERVER) directly into the constant? i did google this first, but the examples i found of constants all used static/pre-defined data. thanks for any advice (:
  2. sorry, i meant html <select> tags/drop-down lists... i just have a habit of calling them select boxes but thanks for your answer, helped a lot (:
  3. hey guys, just wondering, is it advisable to use mysql_real_escape_string() with <select> boxes, i know the web designer will always set the values for options within select boxes, therefore there shouldn't be any danger, but then i found such js code as: javascript:document.body.contentEditable='true'; document.designMode='on'; void 0 (this allows the user of any site to edit content on the users end) so with something like the above, is it at all possible for a user to alter the option values within a select box and successfully submit the altered form? thanks
  4. in the end i went with: using two queries, one to get friend's status messages, and one to get friend's image uploads: $friendStatuses = mysql_query(" (SELECT ud.user_id, ud.username, us.post_body, us.date_posted FROM user_friends AS uf CROSS JOIN user_details AS ud ON ud.user_id = uf.user_id_link2 INNER JOIN user_statuses AS us ON us.user_id = uf.user_id_link2 WHERE uf.user_id_link1 = '$loggedInUserId') UNION ALL (SELECT ud.user_id, ud.username, us.post_body, us.date_posted FROM user_friends AS uf CROSS JOIN user_details AS ud ON ud.user_id = uf.user_id_link1 INNER JOIN user_statuses AS us ON us.user_id = uf.user_id_link1 WHERE uf.user_id_link2 = '$loggedInUserId') ORDER BY date_posted DESC LIMIT 0,10 ") or die(mysql_error()); $friendImages = mysql_query(" (SELECT ud.user_id, ud.username, ui.name, ui.date_uploaded FROM user_friends AS uf CROSS JOIN user_details AS ud ON ud.user_id = uf.user_id_link2 INNER JOIN user_images AS ui ON ui.user_id = uf.user_id_link2 WHERE uf.user_id_link1 = '$loggedInUserId') UNION ALL (SELECT ud.user_id, ud.username, ui.name, ui.date_uploaded FROM user_friends AS uf CROSS JOIN user_details AS ud ON ud.user_id = uf.user_id_link1 INNER JOIN user_images AS ui ON ui.user_id = uf.user_id_link1 WHERE uf.user_id_link2 = '$loggedInUserId') ORDER BY date_uploaded DESC LIMIT 0,10 ") or die(mysql_error()); mysql_close(); then combined the results from both queries into one array: $arr = array(); while($userInfoParts = mysql_fetch_array($friendStatuses)){ $arr[] = array( "user_id" => $userInfoParts['user_id'], "username" => $userInfoParts['username'], "value" => $userInfoParts['post_body'], "date" => $userInfoParts['date_posted'] ); } while($userInfoParts = mysql_fetch_array($friendImages)){ $arr[] = array( "user_id" => $userInfoParts['user_id'], "username" => $userInfoParts['username'], "value" => $userInfoParts['name'], "date" => $userInfoParts['date_uploaded'] ); } then set a function to sort the array by "date", and crop the array after the first 10 sub-arrays: function orderBy($array, $field, $order=NULL) { $code = "return strnatcmp(\$a['$field'], \$b['$field']);"; if ($order = "DESC") usort($array, create_function('$b,$a', $code)); else usort($array, create_function('$a,$b', $code)); return $array; } $arr = orderBy($arr, 'date', 'DESC'); array_splice($arr, 10);
  5. thanks Keith, i'll keep tweaking the code i have then, and look into grouping etc thanks again
  6. hi Keith, thanks for the help, but at the moment the code doesnt seem to be working as it returns no data, but without throwing errors, is this what the code is set out to do: find all friend's ids => get info for each friend from user_details => gather all status updates posted by each friend => gather all image uploads uploaded by each friend? thank you
  7. hey guys, my following code allows we me to get a friend id in a bi-directional table (by finding the user_id of the logged in user ($loggedInUserId)) and retrieve user details (such as username) for that user: (SELECT SQL_CALC_FOUND_ROWS * FROM user_details AS ud CROSS JOIN user_friends AS uf ON ud.user_id = uf.user_id_link1 WHERE uf.user_id_link2 = '$loggedInUserId') UNION ALL (SELECT * FROM user_details AS ud CROSS JOIN user_friends AS uf ON ud.user_id = uf.user_id_link2 WHERE uf.user_id_link1 = '$loggedInUserId') LIMIT 0,10 .. but now i need my code to gather the friend ids (from user_friends), get the friends username (from user_details), for each friend i then need to gather any status updates and image uploads relating to that user (from user_statuses and user_images) so i need to find a way of combining the following kind of codes with the above: SELECT post_body, date_posted FROM user_statuses WHERE user_id = '[FRIEND_ID]' SELECT name, date_uploaded FROM user_images WHERE user_id = '[FRIEND_ID]' ..while sorting the whole query using the dates from "date_posted" and "date_uploaded" general layout for tables: user_details: user_id | username ------------------------------ 001 | bob 002 | fred 003 | bill user_friends: user_id_link1 | user_id_link2 ----------------------------------------- 001 | 003 // bob is a friend of bill, vice-versa user_statuses: user_id | post_body | date_posted ---------------------------------------------------- 001 | testing | [TIMESTAMP] 001 | 1234 | [TIMESTAMP] 002 | blahblah | [TIMESTAMP] user_images: user_id | name | date_uploaded ---------------------------------------------------- 002 | blah.jpg | [TIMESTAMP] 002 | test.png | [TIMESTAMP] 001 | img.jpe | [TIMESTAMP] so if the logged in user was bill, the query would return the first 2 rows from user_statuses, and the 3rd row from user_images, as well as any data from the user_details table can anyone suggest how my problem can be solved? sorry if i haven't explained well, please ask if you need anymore info thanks for any help (:
  8. thanks a billion for the reply DavidAM, the middle one seems to be working just as i needed it to (: ..had to remove the square brackets from my column names though, it seemed to be throwing an error just for using them
  9. hey guys, at the moment i have two tables, one for user details, one for users friends, set out as follows: user_details: user_id | marked_online ------------------------------ 001 | 1 002 | 0 003 | 1 user_friends: user_id_[link1] | user_id_[link2] ----------------------------------------- 001 | 003 so with the above example, "001" is friends with "003", vice versa. my problem is i need to get all online friends for the logged in user, but im not sure how to alter my code (below) so that the logged in user could be in column "user_id_[link1]" or "user_id_[link2]" mysql_query(" SELECT SQL_CALC_FOUND_ROWS * FROM user_friends AS uf CROSS JOIN user_details AS ud ON ud.user_id = uf.user_id_[link2] WHERE uf.user_id_[link1]='$loggedInUserId' && ud.marked_online=TRUE "); $loggedInUserId = user_id of signed in user so i need my query to take the user id from either "user_id_[link1]" or "user_id_[link2]" (depending on which column the signed in user appears in) and use it to get the friends details from the user_details table hope ive explained my problem well thanks guys
  10. if i remember correctly, a maximum of only 25 keywords are usually processed.. BUT, most search engines these days completely ignore the tag, therefore in most cases your keywords become useless. the rest of your meta tags look fine apart from i *think* that html validator states that the trailing slashes are no longer needed (if your using one of the "HTML" doctypes)
  11. as long as the font-size for "#sitenav ul li" is set before "#sitenav ul li ul li" that css would be correct for a nav set out something like this: <div id="sitenav"> <ul> <li>Item 1</li> <li>Item 2</li> <li>Item 3</li> <li>Item 4 <ul> <li>SubMenu Item 1</li> <li>SubMenu Item 2</li> <li>SubMenu Item 3</li> </ul> </li> </ul> </div> ...does this html resemble your code?... if not can you post your html please
  12. well as long as the styles for normal Anchors are set before your Header Anchors within your CSS, you shouldn't be having any problems. which browser are you using? +can you post your whole html doc
  13. your HTML looks fine, though try using intends more effectively... it doesn't improve html validation, but it does help when it comes to having to read through loads of your own code. for example: <div id="menu"> <ul> <li><a href="#">Menu 1</a></li> <li><a href="#">Menu 2</a></li> <li><a href="#">Menu 3</a></li> <li><a href="#">Menu 4</a></li> <li><a href="#">More.</a> <ul class="subMenu"> <li><a href="#">Menu 1</a></li> <li><a href="#">Menu 2</a> </li> <li><a href="#">Menu 3</a> </li> <li><a href="#">Menu 4</a> </li> <li><a href="#">Menu 5</a></li> <li><a href="#">Menu 6</a> </li> <li><a href="#">Menu 7</a> </li> <li><a href="#">Menu 8</a> </li> </ul> </li> <!-- this was a <ul> in your posted code, the <ul> will have made the conflicts you where talking about --> <li><a href="#">Menu 1</a></li> <li><a href="#">Menu 2</a></li> <li><a href="#">Menu 3</a></li> <li><a href="#">Menu 4</a></li> </ul> </div> ..i only spotted one error within this HTML which i put a comment against, (you originally had it as a <ul> tag, but needed to be a closing <li> tag) with your CSS, under the "#menu ul li ul.subMenu" styles, you may want to add the rest of the opacity codes for wider browser support: #menu ul li ul.subMenu { opacity: .88; /* Standard: FF gt 1.5, Opera, Safari */ filter: alpha(opacity=88); /* IE lt 8 */ -ms-filter: "alpha(opacity=88)"; /* IE 8 */ -khtml-opacity: .88; /* Safari 1.x */ -moz-opacity: .88; /* FF lt 1.5, Netscape */ } and within the same block of codes (#menu ul li ul.subMenu), i noticed you have set a rather large "top" value set.. #menu ul li ul.subMenu { top:28px; } ...this will leave quite a large gap from the main menu to the dropdown menu... once your mouse enters this gap your drop down menu will close due to the fact you will no longer be hovering over the <li> element, with this in mind you may want to reduce that "top" value, or perhaps add "padding" to "#menu li" to close the gap. .. apart from that, the rest of your CSS looks fine (: one other thing... you will need to make sure you have a correctly specified Doctype at the very top of your HTML document for IE to display all your styles correctly, if you haven't got one yet, use the following... <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> if you need anymore help, or if i haven't explained something very well, just ask (: good luck with your project
  14. now ive found another problem.. after doing as the post on stackoverflow.com suggests, i found that when using session_destroy() or unset($_SESSION['blah']) all they do is remove all the data inside the session, but leave the empty session file behind... how do i remove the file too? ...otherwise im going to have a folder full of old, empty files will i just have to use unlink('/home/jacko/LocalHost/sess/sess_[sESSION ID HERE]') ..or is there a php session setting for removing empty sessions? thanks
×
×
  • 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.