Jump to content

scarhand

Members
  • Posts

    382
  • Joined

  • Last visited

Everything posted by scarhand

  1. I need a regex that will preg_replace all "\n" (linebreaks) and "\t" (tabs) to spaces. After this is done, I want it to convert 2 spaces " " into 1 space " ". I know how to preg_replace the "\n" and "\t", but not the 2 spaces into 1. I imagine it would have something to do with {2} or something like that.
  2. ive got a string: i want to use preg_replace to make it look nicer, i.e: You can see there is a line break there too I want to get rid of. edit: can a mod move this to regex? my bad.
  3. If I create a varchar field with a length/value of 4 will I be able to store data whose length is greater than 4 characters? Example, lets say I make a VARCHAR(4) column. Can I store "i love mysql" in that column without any issues arising?
  4. mysql_query("delete from shoutbox where id not in (select id from shoutbox order by id desc limit 10);") why is this not working?
  5. Trying to get this code to work: <script type=”text/javascript”> function resizeframe() { var ff = parent.document.getElementById ? parent.document.getElementById('formframe') : parent.document.all['formframe']; var fc = ff.contentDocument ? ff.contentDocument : document.frames('formframe').document; var sf = parent.document.getElementById('shoutframe'); sf.rows = fc.body.offsetHeight + ", *"; } </script> <frameset id="shoutframe" onload="resizeframe();"> <frame id="formframe" src="shoutform.php" frameborder="0" scrolling="no"> <frame src="shoutdiv.php" frameborder="0" scrolling="auto"> </frameset> As you can see, all I want it to do is set the frame row's height based on its content.
  6. i have a div i want at the top of the page to scroll with the page the problem is that it is overlapping the top content, how do i make it so that the top content shows under the div before it starts scrolling? <div style="background-color: #dfdfdf; position: fixed; width: 100%;"> fixed content </div> <div> this content is being overlapped by the fixed div and therefore needs to be pushed down somehow </div>
  7. You'll be able to see what I'm trying to do: $sql = $db->query("select s.*, u.displaygroupid as did, if(did = 0, u.usergroupid as gid, u.displaygroupid as gid) (select opentag from " . TABLE_PREFIX . "usergroup where usergroupid = gid) as opentag, (select closetag from " . TABLE_PREFIX . "usergroup where usergroupid = gid) as closetag from " . TABLE_PREFIX . "shoutbox as s, " . TABLE_PREFIX . "user as u order by id desc limit " . $vbulletin->options['ddsb_show'] . ""); Doesn't work. Can someone show me the proper way of writing this query?
  8. nothing. i ended up adding the sub queries right into the original query.
  9. i don't know anything about indexes. heres an example of my select query for the band page (the page that lists all tabs for a band). this is the slowest page to load. $esc_band is simply the $_GET['band_slug'] variable protected with mysql_real_escape_string. <?php $sql = mysql_query("select song, song_slug, band, band_slug, version, rating, views from tabs where band_slug='$esc_band' order by song, version asc"); while ($row = mysql_fetch_assoc($sql)) { $song = $row['song']; $song_slug = $row['song_slug']; $band_slug = $row['band_slug']; $version = $row['version']; $rating = $row['rating']; $views = $row['views']; // additional coding using the variables here } ?>
  10. I have a table for guitar tabs. this table has about 270,000 rows, totalling about 1,200 megabytes. Its causing the page load times to take up to 5 seconds or more. The structure is as follows: CREATE TABLE IF NOT EXISTS `tabs` ( `id` int(10) unsigned NOT NULL auto_increment, `song` text NOT NULL, `song_slug` text NOT NULL, `band` text NOT NULL, `band_slug` text NOT NULL, `tab` longtext NOT NULL, `version` int(10) unsigned NOT NULL, `rating` int(11) NOT NULL default '0', `views` int(10) unsigned NOT NULL default '0', PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=267636 ; In my select query, I am using mysql_fetch_assoc and am only selecting the fields I am actually using on the page. If I split this table up into 2, 1 with all these fields minus "tab", and 1 solely with "tab" and "tab_id", would it improve my page load time?
  11. the funny thing is, it works for other raw sha1's such as ""!•g€Luµí¦S÷¸FF" and "¤h¦Š@ Ή´ùmÍëØØv¹" so obviously it is the null byte causing the issue. how do i make it work?
  12. i have a string - LÙH²räâG3Âd\0(anBì this is supposed to be coming from a $_GET variable, called $_GET['info_hash'] however, I believe the null byte "\0" in this string is causing php to read the variable as empty, as using the empty function tells me it is empty even though it is not. what is the workaround for this?
  13. i need to add the following 2 queries: $query = mysql_query("SELECT COUNT(*) FROM `peers` WHERE `hash` = RTRIM('$hash) AND `left` = 0 AND `expire_time` > NOW()"); $query = mysql_query("SELECT COUNT(*) FROM `peers` WHERE `hash` = RTRIM('$hash) AND `left` > 0 AND `expire_time` > NOW()"); to this query: $sql = mysql_query("select t.id, t.uploader_id, s.memberName, t.category_id, c.name, t.hash, t.title, t.file_name, t.file_size, t.rating, t.date_uploaded from thefiles as t, smf_members as s, categories as c where t.uploader_id = s.ID_MEMBER and t.category_id = c.id order by t.id desc limit 50") or die(mysql_error()); i created that query myself, but i have no idea how to add the counts to it so its all in 1 nice query. can a guru help?
  14. mysql_result(mysql_query("select count(*) from peers where hash='$hash' and left='0'"), 0) or die(mysql_error()); 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 '='0'' at line 1
  15. pagination works on the concept that you are dividing the mysql query into different chunks. each page represents a different chunk that is selected. so if you had 500 rows grabbed from a select query, and wanted to display 100 on each page, then 500/100=5 if youre on $_GET page 2, you'd change the LIMIT in the mysql query to 100, 100 then to display the actual page links you would use some PHP coding in order to break up the pages themselves into chunks so you don't have 200 page links.
  16. you need to explode the file contents into an array by using "\n" (which means linebreak) as a delimiter that way you can work with the array instead of the entire file as a string
  17. i am writing a visitor statistics system to go with a script i am working on the script will be using a transparent 1x1 gif (which is actually a php page) in order to track visitor date, ip, host, referer, country, browser, OS, and the page they have visited i am going to be writing scripts for pages where the admin can view visitor statistics by ip, date, host, referer, country, etc. and will also show unique and total pageview counters. i am wondering, should i just use 1 table for all of this and insert a new row each time a visitor comes to the page? or should i have a "hits" column and if the person is visiting the same page from the same IP just update that column? heres my current table structure: create table visits ( id int unsigned not null auto_increment, page text not null, domain text not null, keyword text not null, visit_date int unsigned not null, ip text not null, host text not null, referrer text not null, country text not null, hits int unsigned not null, primary key (id) ); any advice would be great.
  18. So I escaped the two "-"'s in the regex: str = str.replace(/[^a-z0-9\-]/, '-'); str = str.replace(/\-+/, '-'); and its still not working properly. Did I do this correctly? You'll have to forgive me, I am so used to PHP that javascript seems fairly unfamiliar.
  19. The regex does not seem to be working here. function trim(str, chars) { return ltrim(rtrim(str, chars), chars); } function ltrim(str, chars) { chars = chars || "\\s"; return str.replace(new RegExp("^[" + chars + "]+", "g"), ""); } function rtrim(str, chars) { chars = chars || "\\s"; return str.replace(new RegExp("[" + chars + "]+$", "g"), ""); } function putslug(str) { str = str.toLowerCase(); str = trim(str); str = str.replace(/[^a-z0-9-]/, '-'); str = str.replace(/-+/, '-'); str = trim(str, '-'); document.getElementById('slug').value = str; }
  20. Is there any way for PHP to check if a type="button" was pressed once a form is submitted? I am using Javascript to submit the form when the button is pressed. I can not use type="submit" for this.
  21. I am close: <?php $sql = mysql_query("select * from words"); $words = array(); $synonyms = array(); while ($row = mysql_fetch_array($sql)) { $words[] = $row['word']; $syns = explode(',', $row['synonyms']); $randsyn = array_rand($syns); $synonyms[] = $syns[$randsyn]; } $article = str_replace($words, $synonyms, $article); echo "<font style=\"color: red;\">$article</font>"; The problem now, is that it is making the replacements EVERYWHERE, even inside of words.
×
×
  • 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.