Jump to content

BluMess

Members
  • Posts

    32
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

BluMess's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Thanks, works perfectly!
  2. Hi all, Here is an extremely novice problem, yet the amount of times I have searched for an answer I haven't found anything, so I'm hoping someone could help me out Basically I have a column "rating" which I want to store a number between 1 and 10, but with say 2 or 3 decimal places e.g. 6.236 So I thought this would work for mysql: `rating` dec(4,2) NOT NULL DEFAULT '0', but it seems to just limit the number to being "4.00" this is my php part: echo "total value: ".$rating['total_value']."<br>"; echo "total votes: ".$rating['total_votes']."<br>"; $current_rating = $rating['total_value']/$rating['total_votes']; $printf_curr_rating = printf("%04.2f", $current_rating); echo "Current rating: ".$current_rating."<br>"; $add_curr_rating = mysql_query("UPDATE media SET rating='".$printf_curr_rating."' WHERE id=".$new_id."") or die("Update rating error: ".mysql_error()); if($add_curr_rating){ echo "-Updated rating for the media id to:".$printf_curr_rating."<br>"; } This is what my script returns: total value: 154 total votes: 20 7.70Current rating: 7.7 -Updated rating for the media id to:4 And, likewise in the db, it says the decimal is 4.00 What is going on? Thank you ~Chris
  3. Great, thanks! That worked really well, except that it wouldn't let me access the page without the slash after 'games'. This is what I've finally got: RewriteRule ^games([/]*)([^/\.]*)/?$ /view_media.php?type=1$2 [L] It works, hopefully it's right: The first set of characters is just to say that the trailing slash is optional, whilst the second (also optional) set is as intended, the parameters. I've used $2 at the end so that it ONLY adds the 2nd set on the end, without the slash. Thanks for your help
  4. Hi, On my website I want users to be able to access: /view_media.php?type=[whatever the media type is] through this: /games/ goes to /view_media.php?type=1 /toons/ goes to /view_media.php?type=2 HOWEVER on the end of the normal URL gets added some extra parameters for the script, lets just call them 'a' and 'b'. /view_media.php?type=1&a=foo&b=bar This would be accessible via /games/&a=foo&b=bar The .htaccess line I have is: RewriteRule ^games/([^/\.]+)/?$ /view_media.php?type=1$1 [L] where the regex part is the parameters on the end of the url as mentionned but, if I simply go to /games/, it doesn't redirect me. It will only redirect me if there is something after the trailing slash I've tried experimenting, but I just can't seem to find anything which will work both with and without that final regular expression part. Hopefully it's something simple, it's quite a nuisance Thank you for your time, I hope you can bear with me ~Chris
  5. You, sir, are a life saver I put it into a string, echoed it and yes I'd forgotten to global $new_table_name (that query is in a function). Thanks a lot, I'll remember that trick!
  6. Hi I've gotten really confused about this. Here is a seemingly fine PHP script for sending a query to mysql: $insert = mysql_query("INSERT INTO ".$new_table_name." VALUES('".mysql_real_escape_string($row['datetime'])."', '', '".mysql_real_escape_string($row['type'])."', '".mysql_real_escape_string($row['title'])."', '".mysql_real_escape_string($row['author'])."', '".mysql_real_escape_string($row['thumbnail'])."', '".mysql_real_escape_string($row['short_d'])."', '".mysql_real_escape_string($row['description'])."', ".$row['width'].", ".$row['height'].", '".mysql_real_escape_string($row['flash'])."', '".mysql_real_escape_string($row['status'])."', ".$row['hits'].", ".$row['favourites'].", ".$row['emails'].")"); Yet, it gives me this error (when inserting some dummy information): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'VALUES('2009-08-09 22:23:10', '', 'game', 'testgame', 'testuser', ' ', 'short_description_here', '' at line 1 What's going on here?! here's the table structure: CREATE TABLE IF NOT EXISTS `user_games` ( `datetime` datetime NOT NULL, `id` int(11) NOT NULL AUTO_INCREMENT, `type` varchar(15) NOT NULL DEFAULT 'game', `title` varchar(50) DEFAULT NULL, `author` varchar(20) DEFAULT NULL, `thumbnail` text, `short_d` varchar(60) DEFAULT NULL, `description` text, `width` int(4) DEFAULT NULL, `height` int(4) DEFAULT NULL, `flash` text, `status` varchar(15) NOT NULL DEFAULT 'pending', `hits` int(10) NOT NULL DEFAULT '0', `favourites` int(10) NOT NULL DEFAULT '0', `emails` int(10) NOT NULL DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=146 ; Thanks
  7. I'd just like to throw this out there I was in the same position, and while a lot of the pre-made forums out there are very effective etc, I found it impossible to customise them in any way, to make my own mark on them. I searched and looked into it for a long time, but gave up and went my own way to make a forum. If your site design is generic and would fit with the forums' general simple, light-coloured style, then it would be best to go with one. For me, I had lots of dark colours and as said before I couldn't make anything out of where my header and footer could go. I still made my own forum being a newbie and I have to say there have been SO many bugs to sort out, it's unbelievable! But they're going, and I'm starting to see the advantages of making your own forum. You can integrate it perfectly with your own site - bring in user details with ease, add and edit any area of it freely, and choose the features you want to make for it. You can even add to your BBCode script to make custom code tags, like bringing in youtube videos (very easy, just copy+paste their embed code but use a specified video id instead of the one they give you). It's really up to you - it is very satisfying to make one, and provides you with HUGE flexibility over things as I've said; everything can be tweaked, which makes it stand out from other pre-packaged forums. But it has taken a long time to get rid of the bugs, including many headaches over string shortening. It's also not as reliable as i'd have liked, with glitches popping up (the id int auto_increment in the database wasn't big enough to hold any more posts, which was a confusion for a while) and if your site has lots of traffic you don't want users poking holes into your work, so I'd advise it best for low-traffic sites while you get it stable Good luck with whatever you choose!
  8. Hey, just a quick question, I can't find it on the net for mysql, do I need to use the UPDATE query more than once if I'm updating all rows with the same value in 1 column? mysql_query("UPDATE comments SET media_id=".$new_id." WHERE media_id=".$game['id']); Basically in my table, I have lots of comments relating to 1 game (with the id in var $game['id']). I'm trying to change all these IDs to a new ID. Will I need to call that query just once to achieve what I want, or will I need to include it in a loop? Thanks
  9. Ahh, ok that makes more sense. Thanks again!
  10. Wow, thank you so much - it works perfectly! I think I understand how it works - It looks for 50 ($character_limit) non-whitespace characters and then looks back for "<tagname with properties etc>", that's actually genius, and so simple Cheers, that's helped such a lot. Good luck in future! ~Chris
  11. thebadbad, that script works brilliantly to prevent the tags from breaking up -thanks very much The only problem I have, which I have been playing around with your script to fix, is this: or Just specifically for those tags, it would be great if the regex could look for either the tags (w/o spaces) and not add any spaces for the things inside those tags. Is that possible? This is what I tried, but it failed miserably I'm afraid: $BBCode_Text = preg_replace('~\S{' . $character_limit. '}(?![^\[]*?\])|~\S{' . $character_limit. '}(?![^\[](url|img)\].*?\[\/(url|img)\])~', '$0 ', $BBCode_Text); The error was "an unknown modifier: / ", am I at least on the right line? :S
  12. Sorry, this is what I put in: [ url=http://www.hastheworldbeendestroyedbythelargehadroncollideryet.com]http://www.hastheworldbeendestroyedbythelargehadroncollideryet.com[/url ] (without spaces around the url tags)
  13. Thanks v much for the response Unfortunately it's not made any difference. I've placed the code at the end of all the BBCode stuff so that it doesn't interfere with for example changing tags into HTML links. This is what I've put in: And this is what has been displayed: <a href="http://www.hastheworldbeendestroyedbythelarg ehadroncollideryet.com">http://www.hastheworldbeen destroyedbythelargehadroncollideryet.com</a> It hasn't really made any difference. Would it be better / easier to make a regex code to remove spaces from parts between a or tag? I'm brushing up on my regex atm, this is quite a tricky problem to sort out because it interferes with all the tags if there are enough characters before it, causing them to be missed out of searches
  14. Hey I've been modifying an existing BBCode script for a forum I am making, but I found if someone put in a really long word, maybe just as spam, it broke up the content of the page. I'm using these lines to stop that from happening: $character_limit = 50; $BBCode_Text = preg_replace('/([^\s]{'.$character_limit.'})(?=[^\s])/m', '$1 ', $BBCode_Text); Which works great, but my problem is that if someone put in a URL, e.g. http://www.a-very-long-website-name-maybe-a-huuuuuge-link-to-an-obscure-file.com/a-folder/some-other-folder-with-a-name-so-long-it-should-be-made-illegal/file.html It gets broken up and doesn't work when it's clicked. I have the same problem for images, because their source is getting split apart. Is there any way of preventing this from happening, maybe by looking for a "www." or an ending such as ".com" or ".png" - I'm pretty stuck on this one Thank you for your time and help ~Chris
×
×
  • 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.