Jump to content

adambedford

Members
  • Posts

    86
  • Joined

  • Last visited

    Never

Everything posted by adambedford

  1. Thanks for your reply. To be honest, I think that most of the code I have at the moment is pretty useless! All I have is basically what I said I wanted to avoid...doing it all manually by coding for every eventuality. Essentially i have an include for the right hand side that deals with the navigation and another include for the right hand side that deals with the actual business listings. How would I go about implementing the code you suggested? I'm pretty new to PHP so I don't really know what to do with it!
  2. anyone? this is still baffling me? I'll just have to write out every possibility otherwise.
  3. I'm designing a website and writing the PHP code to list businesses and I'm having a little trouble with displaying the records. On the homepage there is the option to browse by location or category which then adds 'location=' or 'category=' to the URL. The listings page then needs to read this and filter the records accordingly. This is pretty simple and I am comfortable doing this. The problem comes when I want to have more than one url variable. ie. ?location=somewhere&category=something. On the listings page I have a menu down the right hand side that changes content depending on what is supplied in the URL. ie. if the category is supplied, it shows subcategories. and if the location is supplied, it shows categories. I want these links to then change the URL parameters (for example, by adding '&subcategory=blah') and then on the right hand side, where the listings are, to query and return the results based on the various URL parameters supplied. One problem that I can't overcome is the different number of URL parameters that can be supplied and how to process them. So far I've written code so that if there is only 1 $_GET and it equalt 'location' I query the categories table and display that content. And if there is 1 $_GET and it equals 'category' then I query the subcategories table and list the results. I could proceed like this and try and account for every eventuality but this seems like an awful lot of code and an awful lot of repetetive querying How would I go about doing this much more dynamically and then having the results on the right hand side show dynamically based on the varying URL parameters. I don't really want to be spending hours typing out every eventuality because I an convinced there is a much better way of doing this. Would it involve adding the $_GET parameters to an array with foreach()? Just my very (very!) basic speculation. But then how would I decide that 'category' had been set and then display subcategories. and how would I filter the listing results based only on 'category'...and so on... Any help would be REALLY appreciated! Thanks in advance.
  4. Yeah I do, but at the moment it is displaying each track and a single comment and then repeating each track with a different comment. I want the comments to be displayed underneath each track and grouped together so that the tracks only display once. So yeah just to display the comments for each track.
  5. I've written some simple code that shows a list of music files that are in a database. I'm now trying to add a comments system so that users can add a comment to a specific track. I've got two tables, 'tracks' and 'comments' and the 'comments' table has a field called c_TrackID which relates to the field 't_ID' in the tracks table - all standard stuff. The problem I have is displaying the comments. My first thought was to use a LEFT JOIN query to return a recordset of the two but that hasn't worked out quite as I'd hoped. The query itself is fine but it doesn't repeat the comments within each track, it repeats each combination of track & comment. I'm looking for a solution to repeat all the tracks and within that list repeat all the comments for that particular track. I thought about querying the comments table within the while loop for the tracks but that will be quite slow and cumbersome and I'm sure there is a more efficient and easier way. I'd really appreciate any suggestions!
  6. I'm designing a web application that will have elements of social networking involved and I'm theres a couple of things that I'm not sure which way is best to go about them: The first is notification options. I want to make it possible for a user to decide what notifications from my website they receive. Kind of like Facebook where you can decide if you get an email when someone sends you a message etc. I've thought about having a table called notification_options with fields for the User ID and then fields for the various notification options they can opt in/out of (e.g. receive email when friend requested etc.) The other option I've come up with is to have a field in the existing users table with a number that corresponds to a certain combination of notification options (such as 1 means receive emails for everything, 2 means receive emails only when someone sends you a message and so on...) What do you guys think is the best way to approach this? My other dilemma involves privacy options (ie. who can view profile, other info etc) And I've come up with the same options as above for this one as well. Any suggestions/pointers would be really appreciated! And if I've missed a different posibility to go about this - I'd really like to hear it as I'm sure it's better than the possible solutions I've come up with. At the moment I'm leaning towards having a table with fields for each option and User ID and then just updating that if a user changes their mind and referring to that when writing the functions that will send notifications/restrict info based on privacy settings.
  7. I'm making a tabbed menu that displays an inline div onclick. I've written this and got it to switch between divs when clicking a subsequent menu item but I am having a little trouble switching the class of the <li> tab onclick. I know how to add a class to an element but the problem I'm having is that I don't know how to remove it when another tab is clicked and switch the class to that tab. My menu script is as follows (it's probably quite cumbersome by professional standards but it works for me!) function menudiv (layertoshow, layertohide) { //Declare the variables var show, hide, show_vis, hide_vis; //code for show layer if( document.getElementById ) // this is the way the standards work show = document.getElementById( layertoshow ); else if( document.all ) // this is the way old msie versions work show = document.all[layertoshow]; else if( document.layers ) // this is the way nn4 works show = document.layers[layertoshow]; show_vis = show.style; //code for hide layer if( document.getElementById ) // this is the way the standards work hide = document.getElementById( layertohide ); else if( document.all ) // this is the way old msie versions work hide = document.all[layertohide]; else if( document.layers ) // this is the way nn4 works hide = document.layers[layertohide]; hide_vis = hide.style; // if the style.display value is blank we try to figure it out here if(show_vis.display==''&&show.offsetWidth!=undefined&&show.offsetHeight!=undefined) show_vis.display = (show.offsetWidth!=0&&show.offsetHeight!=0)?'block':'none'; show_vis.display = (show_vis.display==''||show_vis.display=='block')?'none':'block'; if(hide_vis.display==''&&hide.offsetWidth!=undefined&&hide.offsetHeight!=undefined) hide_vis.display = (hide.offsetWidth!=0&&hide.offsetHeight!=0)?'none':'block'; hide_vis.display = (hide_vis.display==''||hide_vis.display=='none')?'none':'none'; } How would I go about integrating into the above script something that, when the tab is selected, adds the class "tab_selected" to the <li>. I guess I would need to pass the id of the <li> to the function but I don't know what to do from there so that when the next tab is selected, the previous one has the class removed. I only have two tabs that I need to switch between, hence why I pass a 'tab to show' and a 'tab to hide' variable. I don't need it to work with more menu items. Any thoughts?
  8. I've been thinking...do I even need to use an array or can I just use JOINs in the original query to link everything together? I'm really struggling to get my head around how it's all going to tie together to be honest...
  9. They seem to be to do with the final three lines: $Business_owners = mysql_query($query_Business_owners, $links); $row_Business_owners = mysql_fetch_assoc($Business_owners); $totalRows_Business_owners = mysql_num_rows($Business_owners); Because when I comment the lines out, the error goes away but I can't use the data because I've commented some vital parts out.
  10. I'm using Dreamweaver CS4 and it automatically adds sprintf to the query...I'm not actually sure why it does that. I've run into another problem now though...I'm getting error messages from MySQL. The code I'm using is this: //Add the results of the above query ^^^^^ to an array, $arr $arr = array(); $result = mysql_query($query_Relationships, $links); while($row = mysql_fetch_assoc($result)) { $arr[] = $row; } mysql_select_db($database_links, $links); $query_Business_owners="SELECT * FROM business_owners WHERE ID IN ("; if(count($arr)) { foreach($arr as $a){ $query_Business_owners .= "'" . $a['ID'] . "',"; } $query_Business_owners = substr($query_Business_owners,0,-1); } else{ $query_Business_owners .= "''"; } $query_Business_owners .= "))"; $Business_owners = mysql_query($query_Business_owners, $links); $row_Business_owners = mysql_fetch_assoc($Business_owners); $totalRows_Business_owners = mysql_num_rows($Business_owners); And the errors I'm seeing on the screen are: Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /var/www/vhosts/hiperlynx.com/httpdocs/hl_user/account/index.php on line 98 Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /var/www/vhosts/hiperlynx.com/httpdocs/hl_user/account/index.php on line 99 Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in /var/www/vhosts/hiperlynx.com/httpdocs/hl_user/account/index.php on line 131 I'm really not sure why this is happening. Surely there is a simpler way to achieve what I want to do... Essentially I need to get a list of all the businesses that a user is 'following'. (i'm then going to use that to get status updates...but that part comes later). So I've gone about it by retrieveing a list of Business_IDs but then that is no use as I need the actual name from another table, so I'm trying to use this array to retrieve the name. Surely there is a simpler way using a JOIN or something? It's very user specific because I retrieve the list of IDs using the username of the logged in user (which is a session value) Thanks for your advice. Any thoughts?
  11. Ahhhh this is so confusing! I haven't quite made it to that stage yet unfortunately. I'm stuck trying to add the the results of the first query to the array. $colname_Relationships = "-1"; if (isset($_SESSION['ID'])) { $colname_Relationships = $_SESSION['ID']; } mysql_select_db($database_links, $links); $query_Relationships = sprintf("SELECT * FROM relationships WHERE User_ID = %s AND Relationship = 'Following'", GetSQLValueString($colname_Relationships, "int")); $Relationships = mysql_query($query_Relationships, $links) or die(mysql_error()); $row_Relationships = mysql_fetch_assoc($Relationships); $totalRows_Relationships = mysql_num_rows($Relationships); //Add the results of the above query ^^^^^ to an array, $arr $arr = array(); $result = mysql_query($query_Relationships, $links); while($row = mysql_fetch_assoc($Relationships)) { $arr[] = $row; } I tried echoing $arr and all it says is 'Array' I'm getting myself rather confused with all this, but hopefully I'll learn for future projects!
  12. Thanks. Can '1','2','3' etc be an array? Because I won't know the exact values?
  13. Thanks for your help. I've not got my query to return all the User_ID's of the people that the user is following. With this list of ID's, I want to retrieve the other information about the user from the table 'business_owner' (i've split the members into two tables based on whether they are a user or a business owner) Can I query against a list of ID's? ie. If I put the list of business ID's that are being followed into an array, can I query against that? If so, how would I go about it. If not, does anyone have any suggestions as to how I achieve something similar? Again, thanks for the help guys!
  14. OK thanks for the suggestions. I kind of suspected that would be the best solution....but I think it also might be the hardest to work with! To then work with the list of friends each user has, would it be best to query the database (i can manage that part) and add the resulting list to an array? If so, how would I go about that. Essentially, I want to be able to display a list of friends (that I can do - I think!) and then use that list of friends to retrieve status updates from another table. Thanks
  15. I'm writing a pretty simply PHP social networking site. It's pretty similar to twitter I guess but it will be quite different once it's done. My problem is that I don't know the best way to store the friend/following information. I've thought of three ways: Each user has a table and each record stores the user ID of the person they follow I have a table for relationships that has a field for user1, a field for relationship (ie. following) and a field for user2 - the person user1 is following I have a table of users storing all their information and a field called 'following' where all the user IDs of the people that user is following - perhaps comma separated. The problem with this is I wouldn't know how to parse this in PHP so that I can query the information Any suggestions would be really great.
  16. So I've got a table (Links) with a field called 'Category_ID' that stores a number. This value is matched to the field 'ID' in the table 'Categories'. The Categories table also has a field called 'Category_name'. I have a recordset/query that returns data from the table 'Links' based on a URL filter of 'Category_ID'. How would use this Category_ID to return the value of 'Category_name' from the other table?
  17. sader! so simple and yet I doubt I would have ever noticed. Thank you so much! It works perfectly now
  18. This is my whole code: <?php require_once('Connections/links.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; } $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $currentPage = $_SERVER["PHP_SELF"]; $colname_websites = "-1"; if (isset($_GET['Category_ID'])) { $colname_websites = $_GET['Category_ID']; } mysql_select_db($database_links, $links); $query_websites = sprintf("SELECT * FROM links WHERE Category_ID = %s AND Visible = 'Y'", GetSQLValueString($colname_websites, "int")); $websites = mysql_query($query_websites, $links) or die(mysql_error()); $row_websites = mysql_fetch_assoc($websites); $totalRows_websites = mysql_num_rows($websites); $maxRows_websites = 20; $pageNum_websites = 0; if (isset($_GET['pageNum_websites'])) { $pageNum_websites = $_GET['pageNum_websites']; } $startRow_websites = $pageNum_websites * $maxRows_websites; $colname_websites = "-1"; if (isset($_GET['Category_ID'])) { $colname_websites = $_GET['Category_ID']; } mysql_select_db($database_links, $links); $query_websites = sprintf("SELECT Name, URL, `Description`, Category_ID FROM links WHERE Category_ID = %s AND Visible = 'Y'", GetSQLValueString($colname_websites, "int")); $query_limit_websites = sprintf("%s LIMIT %d, %d", $query_websites, $startRow_websites, $maxRows_websites); $websites = mysql_query($query_limit_websites, $links) or die(mysql_error()); $row_websites = mysql_fetch_assoc($websites); if (isset($_GET['totalRows_websites'])) { $totalRows_websites = $_GET['totalRows_websites']; } else { $all_websites = mysql_query($query_websites); $totalRows_websites = mysql_num_rows($all_websites); } $totalPages_websites = ceil($totalRows_websites/$maxRows_websites)-1; $queryString_websites = ""; if (!empty($_SERVER['QUERY_STRING'])) { $params = explode("&", $_SERVER['QUERY_STRING']); $newParams = array(); foreach ($params as $param) { if (stristr($param, "pageNum_websites") == false && stristr($param, "totalRows_websites") == false) { array_push($newParams, $param); } } if (count($newParams) != 0) { $queryString_websites = "&" . htmlentities(implode("&", $newParams)); } } $queryString_websites = sprintf("&totalRows_websites=%d%s", $totalRows_websites, $queryString_websites); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <link href="styles/global.css" rel="stylesheet" type="text/css" /> <script type="text/javascript" src="scripts/menu.js"></script> <link href="styles/links.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="wrapper"> <div id="bodywrapper"> <?php if ($totalRows_websites > 0) { // Show if recordset not empty ?> <div id="listings"> <ul> <?php do { ?> <?php $class = ($row_websites['Highlight'] == "Y")? "highlighted" : "standard" ?> <li class="<?php $class ?>"> <a href="forward.php?URL=<?php echo $row_websites['URL']; ?>"><?php echo $row_websites['Name']; ?></a><?php echo $row_websites['Highlight'] ?></li> <?php } while ($row_websites = mysql_fetch_assoc($websites)); ?> </ul> </div> <?php } // Show if recordset not empty else { echo("There are no websites in this category. List yours now for $1!") ; } ?> </div> <?php print_r($row_websites) ?> <div id="nav"> Websites <?php echo ($startRow_websites + 1) ?> to <?php echo min($startRow_websites + $maxRows_websites, $totalRows_websites) ?> of <?php echo $totalRows_websites ?> <table border="0"> <tr> <td><?php if ($pageNum_websites > 0) { // Show if not first page ?> <a href="<?php printf("%s?pageNum_websites=%d%s", $currentPage, 0, $queryString_websites); ?>">First</a> <?php } // Show if not first page ?></td> <td><?php if ($pageNum_websites > 0) { // Show if not first page ?> <a href="<?php printf("%s?pageNum_websites=%d%s", $currentPage, max(0, $pageNum_websites - 1), $queryString_websites); ?>">Previous</a> <?php } // Show if not first page ?></td> <td><?php if ($pageNum_websites < $totalPages_websites) { // Show if not last page ?> <a href="<?php printf("%s?pageNum_websites=%d%s", $currentPage, min($totalPages_websites, $pageNum_websites + 1), $queryString_websites); ?>">Next</a> <?php } // Show if not last page ?></td> <td><?php if ($pageNum_websites < $totalPages_websites) { // Show if not last page ?> <a href="<?php printf("%s?pageNum_websites=%d%s", $currentPage, $totalPages_websites, $queryString_websites); ?>">Last</a> <?php } // Show if not last page ?></td> </tr> </table> </div> </div> </body> </html> <?php mysql_free_result($websites); ?> Posting it here I've noticed it looks like I've got some duplicated code...not sure why :S
  19. Yes it returns the same records that are showing on my page. Neither CSS class is showing though, so I'm thinking it's a problem with $row_websites['Highlight'] although I don't see why it wouldn't work - I've used the same function quite a few times on my page (with different fields) and they work fine. Even $row_websites['URL'] works, so I dont why 'Highlight' doesnt !
  20. Yeah me too! I've been trying to figure this out all day! $row_websites['Highlight'] appears to be null, which is strange.
  21. sader, unfortunately thats not it - the field in the table is called Highlight, not HighlightED. I wish it was that! And xjake88x, print_r($row_websites) didn't return anything. (I changed it from Featured to websites as I made a mistake in my original post - I'm working on the 'websites' recordset, not the 'Featured' one.
  22. Yeah I do get an output between <li></li> which is why I know the database connection and query are working - why is why this is so confusing why this doesn't work! I've also changed the name of the CSS class and still nothing. I really don't get whats going on here....
  23. That returns: NULL pcloudhosting_link SELECT Name, URL, `Description`, Category_ID FROM links WHERE Category_ID = 2 AND Visible = 'Y' LIMIT 0, 20 But I know that my database connection is OK and my query works because I've got other data on the page that works fine. It just seems to be that <?php $class = ($row_websites['Highlight'] == "Y")? "highlighted" : "standard" ?> does not echo highlighted under any circumstance. And even though it echoes 'standard' all the time, the class does not get switched to .standard
  24. I've tried it as 'highlighted' and it's still not working. This is really strange, everything seems to be in order and yet neither style is applied.
×
×
  • 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.