Jump to content

bigheadedd

Members
  • Posts

    71
  • Joined

  • Last visited

Everything posted by bigheadedd

  1. Thats a good point. Apologies, that is actually what my code should be; I'd copied one of the other queries! Sorting by enddate does the trick perfectly. It seems dumbly obvious now, though thanks for the help!
  2. Hi, I've been trying to sort out some issues I've been having with a query to fetch dates from an events based web app I've done. Currently, the query looks like this.. $listresult = mysql_query("SELECT * FROM events WHERE (startdate >= NOW() OR enddate >= NOW()) ORDER BY events.startdate ASC LIMIT $amount")or die(mysql_error()); This works as it should do, by picking up events that are currently on. However, if there is an event that starts from 1st January 2013 and doesn't end until 1st October 2014 (Next year!), it places itself at the beginning of the list regardless. What i'm trying to achieve is where the query orders them by the NOW() time, by bringing the nearest (starting or ending) to the top of the list, and the others further down. Is this possible at all? I've been trying to rack my brains, but nothing has come up so far. Any help would be great. Thanks, E
  3. Okay so I found a way around it, though maybe someone can shine a better way? while ($ss=mysql_fetch_array($result)) { $areacount[$ss['area_id']]++; } mysql_data_seek($result,0); Doing a simple count with a separate loop before the main loop. (Also removed all of the COUNT and GROUP BY statements in the main query!).
  4. Hi, I'm wondering if this is possible. Basically i'm making a query that gets lots of results from different tables. I'll then loop through them, displaying each event. However, each event is assigned a venue, which is assigned an area. What I want to do is count the amount of events that are in each area, but without doing separate mysql queries (one for the main listing, the other for the count). $result = mysql_query("SELECT event_title, img_filename, area_name, COUNT(area_id) AS counted FROM events LEFT JOIN images ON events.event_id=images.owner_id LEFT JOIN venues ON events.venue_id=venues.venue_id LEFT JOIN area ON venues.v_area=area.area_id GROUP BY area.area_id ORDER BY area_name ASC")or die(mysql_error()); Now obviously this won't work, as it groups the results by the area_id in order to make the count work, and I can't loop through my events. When going through the loop i'm using some separate php code to only echo the area name once. I'd do this for the count, however I need the count at the top of the page. if ($areaname!=$row['area_name']){ $areaname = $row['area_name'].$row['count']; echo "<div class=\"areaheader\"><h2 class=\"gridarea\">".$areaname."</h2></div>"; $count=""; } Any help would be amazing! Thanks, E
  5. Hi, Wondering if this is possible at all. I'm using htaccess to rewrite my pages, and i'm using the following line: RewriteRule ^([a-zA-Z0-9^-]+)$ page.php?page=$1 to rewrite it into clean links. page.php then calls the data appropriately. I am wondering though if its possible, that if the variable is 3 characters long it redirects to another page. RewriteRule ^([a-zA-Z0-9^-]+{3})$ small.php?char=$1 Something similar the above? Is that possible? I just stuck the {3} for illustration purposes. For example if my address was www.example.com/abc, it would redirect to small.php?char=abc and if it was any longer it would redirect to the page.php address. Thanks in advance, E
  6. Hi, I imagine I am doing this completely the wrong way, but i'm a little stumped either way. I currently have three tables: images pages img_assigned the relation is this: images.image_id \ img_assigned.img_id img_assigned.page_id / pages.page_id The idea is that there are lots of different images and pages, and each page can reference the image. So for example for page id 8, there would be the following in the img_assigned table: - page_id: 8 img_id: 22 - page_id: 8 img_id: 36 This all works kind of how I want it do, however, when calling the information with this query: $result = mysql_query("SELECT * FROM pages INNER JOIN img_assigned ON pages.page_id=img_assigned.page_id INNER JOIN images ON img_assigned.img_id=images.image_id WHERE (page_id='8')")or die(mysql_error()); It collects the records how I want it to, except when I do a while loop to go through the data like this while($row=mysql_fetch_array($result)) { echo $row['page_content']; echo $row['img_id']; } it displays everything twice (or however many records are in img_assigned). Is there any way to get the main data just once, and then loop through the other data? I am using innodb with a relation between the three tables. I hope that makes enough sense, and if anyone could help that would be great! Thanks, E
  7. Hi, I imagine theres a simple way of doing this, but I can't think what it could be. Basically I am making a simple query to a database and fetching rows. Each 'page' has 10 records each, and is dealt with by using OFFSET '#number'. What i'm wondering though, is if there is an easy way of getting the required rows (say number 40-50), but also get the total number of posts that exist. $result = mysql_query("SELECT * FROM articles OFFSET 40 LIMIT 10"); but also combine in the same query this: $total = mysql_query("SELECT COUNT(article_id) AS count FROM articles"); Is there a simple way of doing this with two queries rather than two? Seems a little excessive with two. Thanks in advance! E
  8. Hi, I'm wondering if there is anyone who can shed any light on this for me. I am currently looking to serve web fonts (via @font-face) across multiple servers. I have my main server which hosts the files, along with CSS files for the other domains. Each CSS file is in its own folder, but then protected by its own css file, allowing only the associated domain to access it. So far no problem. However, the CSS file links the main font files; again no problem, however the current configuration I have is this: SetEnvIf Referer mainserver.com localreferer SetEnvIf Referer fonts.mainserver.com localreferertwo <FilesMatch \.(eot|woff|ttf|svg)$> <IfModule mod_headers.c> Order deny,allow Deny from all Header set Access-Control-Allow-Origin "*" Allow from env=localreferer Allow from env=localreferertwo </IfModule> </FilesMatch> Now, this works to an extent. The user can't go to the font file and download it directly, and the font loads correctly from external domains... but only in firefox. It doesn't load the fonts in safari or chrome (webkit). I think this has something to do with the Access-Control-Allow-Origin, and that safari/webkit doesn't look for that header. I'm a bit confused as to what to do next really, as I could simply add another referer inside the main .htaccess, but it could get quite bulky. If anyone has any ideas that would be amazing! Thanks, E
  9. Hi, I was wondering if anyone can potentially help me on this one. I'm not so hot with htaccess/apache so any help would be hugely appreciated! Okay.. So i'm serving a selection of files from my website, but want them restricted so that no one can go to the file and download it. I've currently got that working via this code: SetEnvIf Referer mywebsite\.com localreferer SetEnvIf Referer sub.mywebsite\.com localreferertwo SetEnvIf Referer subtwo.mywebsite\.com localrefererthree <FilesMatch \.(eot|woff|ttf|svg)$> Header add Access-Control-Allow-Origin "*" Order deny,allow Deny from all Allow from env=localreferer Allow from env=localreferertwo Allow from env=localrefererthree </FilesMatch> This currently works, and going to the location of an eot, woff etc is presented with a 403 forbidden warning, yet when my website (or sub domains etc) calls the files, it all displays them correctly etc. Hoorah! However, when I call these files from another server, it allows the files to be displayed. How can I prevent this from happening? I would of course like to be able to maybe make an exception for one or two websites, but generally I don't want others being able to use my files. I thought I may be able to do this via hotlink prevention, however this resulted in problems displaying it on my own site for some reason. If anyone can help that'd be great. Thanks, Edd
  10. I did think about that actually yes. In my query I have left joined another table, so in some cases it will be more than just 0. I realised though that I can just loop through this initial loop to get the subset of data. Thanks for the help!
  11. Hi, Ah yes, sorry! I've actually figured out a way of doing what I wanted to do. Rather than doing multiple while loops using mysql_fetch_array, or avoiding using a large one at the beginning (and assigning all of the information to variables), I wanted to put it all into an array with the same keys so I could call it without using loops. The code I came up with is: while ($data[]=mysql_fetch_assoc($tresult)); echo $data[0]["title"]; echo $data[0]["information"]; etc etc. I've realised this is what I needed, but never tried it before. Of course, if theres a better way, let me know Thanks!
  12. Really? At the moment, I call $row["data"] for example, but it has to be within a mysql_fetch_array() function/loop. What i'm wondering, is that rather than looping through, resetting the query to the beginning etc each time, be able to put it inside of an array that functions the same as $row["data"], but not within the mysql loop?? I think that makes sense..?
  13. Hi, I'm wondering if theres a shortcut to a potential problem I have. I'm currently running a query on my website to pull all the fields from a table in my database, for the data to be used on various parts of the page. Usually I would do something as follows $result = mysql_query("SELECT * FROM table WHERE page='1'"); while ($row=mysql_fetch_array($result)) { $title = $row["title"]; $data = $row["data"]; } And so on and so forth. I would then call the appropriate data by echoing $data for example. However, my table contains a lot more rows than i've mentioned (Around 25 or so). Rather than assigning each to a variable and having a large portion of variable assignments at the top of the page, is there any clever way of putting all of these values inside of an array. So for example, I could call $array_data["title"] or $array_data["data"]?? So it keeps the same key, but puts it inside of an array that I don't have to loop through each time? Hope that makes sense! Thanks, Edd
  14. Hi, Thanks for this! Worked a charm!
  15. Hi, I'm currently hosting some fonts on my website for use with @font-face, and have restricted access to them via my website only. However I have multiple domains. How can I add multiple domains to this piece of code? Sorry, bit out of my depth when it comes to the syntax of these things! SetEnvIf Referer example-domain\.co.uk localreferer <FilesMatch \.(eot|woff|ttf|svg)$> Order deny,allow Deny from all Allow from env=localreferer </FilesMatch> Thanks in advance Edd
  16. Thats great, thank you to both of you! That did the trick perfectly, thanks! Edd
  17. Hi, Been looking for a little while on this problem, but can't seem to find a solution. Ok, so I have two tables, gallery & users Gallery contains images, image info etc. Users contains usernames, emails etc. In users there is a 'photo' column, which references to an ID in the gallery table. This is so each user can have a 'profile' image from a bank of images stored in gallery. What i'm trying to do is have a query that will output all of the images, and then show the usernames of assigned to each photo if there is one. Heres what i've got: $result = mysql_query("SELECT *,COUNT(photo) AS usercount FROM gallery LEFT JOIN users ON gallery.img_id=users.photo GROUP BY img_id ORDER BY date_uploaded ASC"); Its all fine, and displays the username, though if there are multiple users using the same photo, it only shows one username. However, when displaying 'usercount', it will show that there are 2+ or whatever. Short of nesting queries within other loops, is there an alternative solution?? Thanks! Edd
  18. Hi, Thanks for the reply! Yes, I realized that was why it was printing the title each time, but I wasn't sure if there was a simpler way of doing this in the query level rather than in the loop. Nevermind though, thanks!
  19. Hi, So i'm having a little trouble trying to simplify some code I already have. $result = mysql_query("SELECT images, cat_id FROM image_cat"); while ($row=mysql_fetch_array($result)) { $cat_id=$row['cat_id']; echo $cat_id; $imgresult = mysql_query("SELECT * FROM images WHERE cat_id='".$cat_id."'"); while ($col=mysql_fetch_array($imgresult)) { echo $col['img_id']; } } Okay, so this works, however i'm sure I can bring it together under one query, though i'm truly stumped as to how? I thought I could do a simple join: $result = mysql_query("SELECT image_cat.cat_id, images.img_id WHERE image_cat.cat_id=images.image_cat"); This works, but repeats the image category on each loop. I could remove this via php if statements, but there must be a simpler/mysql solution. If it doesn't make any sense I need to get Img cat 1 -img 1 -img 2 img cat 2 -img 3 -img 4 etc etc That join will give img cat 1 -img 1 img cat 1 -img 2 img cat 2 -img 3 Hope that makes sense?? And any help would be amazing! Thanks.
  20. Hi, Thanks for the code, it made it work by sticking the div to the top of the page after moving past the top div, however i'm in need of it sticking to the bottom of the page. Any ideas? Thanks! Edd
  21. Hi, I'm having a little trouble trying to force a div to the bottom of the screen. What i'm effectively trying to do is make a div with a fixed position of bottom: 0, but when going past a certain point, it stays there. For example, I have a div on the left/top with a height of 400 pixels, and the div I want to fix at the bottom is 400 pixels high. When I scroll down, the div at the bottom would be at the bottom, but when scrolling up, the top of that bottom div would 'stick' to the bottom of the top div (like being relative rather than fixed). I came across this plugin for jQuery http://www.chmoddesign.com/testbed/jquery/scrollToFixed/scrollExample.html It works really well, however they only give examples of headers or items on the top of the page. Theres nothing that does it from the bottom. I've tried using this code: $(document).ready(function() { $('#image').scrollToFixed({ marginBottom: 10 }); }); But no luck unfortunately. If anyone could shed some light on this, that'd be great! Thanks, Edd
  22. Just got it working! I realized that the date was YYYY-MM-DD 00:00:00 and not DD-MM-YYYY 00:00:00 ! Thanks so much for your help! E
  23. Thanks for that; although it still isn't working? $searchdate = date('d',$day)."-".date('m',$day)."-".date('Y',$day)." 00:00:00"; WHERE events.startdate < '".$searchdate."' AND events.enddate > '".$searchdate."' if I add `` to my field names it comes up with invalid field names? Is this my problem?
×
×
  • 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.