Jump to content

Kingskin

Members
  • Posts

    18
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

Kingskin's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. [quote author=kalivos link=topic=101405.msg401353#msg401353 date=1153508313] I use both, depending on which site I refer too  ;D I'm currently making a site with user switchable themes and styles. I'm trying out a new approach of using $_SESSION(). This is my way of trying out different formats. [code]<link href="<? echo $_SESSION['theme']; ?>/css/main.css" rel="stylesheet" type="text/css" />[/code] This way the CSS is constant and user selects the theme. Experiment and have fun  :D [/quote] OK, that's a slightly different interpretation of the thing i'm trying - you have a css file for each theme which is something I need to incorperate. A basic one for the regular, theme-independant one and then the one for the theme. The way you are doing things was what I was going to do if I couldn't get it working this way, but once I try something and it doesn't work I like to know why! [quote author=Koobi link=topic=101405.msg401367#msg401367 date=1153509716] well the thing is, your HTML would access the CSS via HTTP as far as i know and PHP would have parsed the main.php file via Apache by then. What you could do is pass the variables to CSS via the URL: main.php [code=php:0] <?php header('Content-type: text/css'); ?> body {background: #<?php echo $_GET['bg']; ?>;} [/code] HTML file [code=php:0] <link href="main.php?bg=0f0" rel="stylesheet" type="text/css" /> [/code] [/quote] [quote author=ryanlwh link=topic=101405.msg401436#msg401436 date=1153520271] by using LINK, main.php is treated as a separated script and would not see the variable scope of the current page as Koobi mentioned. you could use Koobi's methed, or include define.php within main.php [/quote] Yup, perfect thanks. I passed the constant to main.php via the url and it worked perfectly. Thanks for the help.
  2. [quote author=kalivos link=topic=101405.msg401309#msg401309 date=1153503261] That's an interesting way to do it. I'm sure I'm doing it incorrectly, but I just include_once("css.php") rather than trying to use <link ....> My way of doing it displays the CSS on the current page rather than "including" it as a link referance. Thus, it's a little sloppy. But it works :) [/quote] and are you using php constants or variables inside your css? I'd really like to keep the css separate if I can though.
  3. OK good people of php freaks, here's one for you: I have an external stylesheet that I want to include php a php constant in (the constant is a url, idea being that making themes is easy - i just set the constant to the location of my theme and bingo). To do this I'm saving my css as a .php file with the following code at the top: [code]header('Content-type: text/css');[/code] I then include my constants file, and then the stylesheet like this: [code]include_once("includes/define.php"); ... <link href="css/main.php" rel="stylesheet" type="text/css" />[/code] that works fine, my css is displayed as it should be, except that my defined constant is not available within the main.php css file. I can echo it out fine above or below the style sheet link and i get the value, but within that script itself it's empty. I can define the same constant within the css script and it all works fine, but the idea was the contant could be set via a database, so there would be no need to edit any source code to change themes. I then thought if I just run the query to define the constant inside the css script, that would work fine. I tried that, but it won't work - no error message, just an empty result. So, I'm at a loss. Anyone know why this is happening and how I can get round it? Cheers.
  4. [quote author=wildteen88 link=topic=101127.msg399930#msg399930 date=1153331611] Code looks fine to me, and I cant see nout wrong with it. However i'd suggest you use mysql_fetch_assoc rather than mysq_fetch_array, otherwise you'll get duplicate sessions, one with a numerical key and another with a string key eg: for your userid session, you'll get userid sessions like so: $_SESSION[0] and $_SESSION['userid'] With mysql_fetch_assoc this wont happen. Another suggestion which may not help but chnage this: [code]$_SESSION[$key] = $value;[/code] to: [code]$_SESSION[{$key}] = $value;[/code] Also make sure you have session_start(); as the first line for everypage that use's sessions. [/quote] cheers dude I had notices that duplicate session data which you mentioned, was going to be my next question! :D The suggestion regarding the curly braces actually resulted in an error, however it seems that changing to mysql_fetch_assoc seems to have cleared the problem anyway! I remember reading that session keys can't be numbers, so this must be the cause. Thanks for the help, problem solved :)
  5. Ok hopefully somone can help me with this as its driving me crazy! I'm trying toi register some session variables based on db fields within a loop when a user logs in. Here is the code im using: [code] <? function sqlquery($sql){ $result = mysql_query($sql); $row = mysql_fetch_array($result); if(!$result){ echo '<p>SQL Error: '.$sql.'</p>'; } return $row; } function reg_session_vars($userid){ $row = sqlquery("SELECT * FROM users WHERE userid = $userid"); foreach($row as $key => $value){ $_SESSION[$key] = $value; } session_write_close(); } [/code] This seems to register the variables fine until I navigate to another page, when they are emptied. If i print_r on the login page itself, I get my $_SESSION array nicely filled, but as soon as I navigate away it's gone. If i register sessions like this: [code] $_SESSION['userid'] = $userid; $_SESSION['username'] = $username; $_SESSION['first_name'] = $first_name; $_SESSION['last_name'] = $last_name; etc... [/code] It works fine. Why is it my loop isn't working properly, and can anyone help me populate $_SESSION from a db table with a loop please? I'd rather it was dynamic than be having to add & remove lines if the table structure changes.
  6. Using MySQL & PHP, how can I first, check if a row with a given primary id exists and if so, update it, or if not insert it. Secondly, if data already exists in a given field, I want to append the new data onto it rather than overwrite it. To clarify a bit, if I have 2 columns: id & value I want to check if id (primary key) exists in the table. If it doesn't exist, I want to insert a row with that 'id', and some data into 'values', such as '2 3 7 87' If it [i]does[/i] exist, i want to update the row with that id, the append some data to whats already in the 'value' field, so if the 'value' field already contains the data '2 3 7 87' and i also want to add '13 5 9', i end up with '2 3 7 87 13 5 9' in that column. Thanks for any help you can give me :)
  7. OK for some reason that script above would only work it if the script tags were not the first or last item in a string. This (much neater) solution works much better: [code]function evilTags($text) {     // Part 1     // This array is for single tags and their closing counterparts          $tags_to_strip = Array("html","body","meta","link","head");          foreach ($tags_to_strip as $tag)     {            $text = preg_replace("/<\/?" . $tag . "(.|\s)*?>/","",$text);     }          // Part 2     // This array is for stripping opening and closing tags AND what's in between          $tags_and_content_to_strip = Array("title","script");          foreach ($tags_and_content_to_strip as $tag) {            $text = preg_replace("/<" . $tag . ">(.|\s)*?<\/" . $tag . ">/","",$text);     }          return $text; }[/code]
  8. Ok, sorted i'll post the solution for anyone that needs it: I found this on php.net but it wasnt working and also used PHP5 only functions so I modified it and it's now working with PHP4 [code] // Usage: //    $nasty_tags=array('script','body');  #etc //    $to_clean='Here is some script: <script>alert("oops")</script> - it will be cleaned!'; //    $clean_str = removeTags($to_clean,$nasty_tags); function removeTags($text,$tags_array) {        $length = strlen($text);        $pos =0;        $tags_array = array_flip($tags_array);        while ($pos < $length && ($pos = strpos($text,'<',$pos)) !== false){            $dlm_pos = strpos($text,' ',$pos);            $dlm2_pos = strpos($text,'>',$pos);            if ($dlm_pos > $dlm2_pos)$dlm_pos=$dlm2_pos;            $which_tag = strtolower(substr($text,$pos+1,$dlm_pos-($pos+1)));            $tag_length = strlen($srch_tag);            if (!isset($tags_array[$which_tag])){                //if no tag matches found                ++$pos;                continue;            }            //find the end            $sec_tag = '</'.$which_tag.'>';            $sec_pos = strpos($text,$sec_tag,$pos+$tag_length);            //remove everything after if end of the tag not found            if ($sec_pos === false) $sec_pos = $length-strlen($sec_tag);            $rmv_length = $sec_pos-$pos+strlen($sec_tag);            $text = substr_replace($text,'',$pos,$rmv_length);            //update length            $length = $length - $rmv_length;            $pos++;        }        return $text; } [/code]
  9. Well, you have this line: $start = $screen * $rows_per_page; before you have defined the value of $rows_per_page dont know if thats the problem but it just jumped out at me.
  10. Should be a simple one, I need to know not just how to remove script tags, but also all of the text between them, ie i need a script that, upon encountering <script>, removes everything until it encounters </script>. At the moment i can remove the script tags which obviously takes care of the security aspect, but it leaves the content of the tags in my DB which obvisuly I dont want for neatness reasons. Cheers!
  11. Hi, I'd like to run daily backups of my MySQL database. I understand I can backup to a directory on my server using something like this with CPanel & cron: date=`date -I`; mysqldump -uDBUSER -pDBPASS --all-databases | gzip > /home/CPANEL/xbackup_$date.sql.gz However, I have a problem. Firstly, I get 150MB of disk space and my DB is a few megs and growing, so running daily backups to the server will max out my space in no time at all. I'm assuming this can be overcome by just storing the latest backup, ie: date=`date -I`; mysqldump -uDBUSER -pDBPASS --all-databases | gzip > /home/CPANEL/xbackup.sql.gz but I don't know for sure if that would work as I dont really know anything about the commands being used or cron jobs. What I really want to do however is automatically backup the database and then save it to my PC each night as my hosting is free and slightly undreliable - if the server disappears for any reason I dont want to lose everything. Is this possible, and how would I do it (please be straightforward in your reply, I know very little about this topic!). Up to now ive been manually doing it with phpMyAdmin but i'm sure there must be another way. Thanks
  12. Ah, Ok that looks like a better way of doing it, thanks
  13. Never mind, sorted now. For anyone else who may turn ths thread up after a search, here's what I did: $query = "SELECT location FROM episode"; $result = mysql_query($query); while ( $row = mysql_fetch_array($result)) { extract($row); $locations[] = $location; } $output = array_count_values($locations);
  14. Hi, I'd like to be able to count the number of times the same data appears in a table. I know i could just use a standard COUNT to do it, but the trouble is I want to do it for every item in my table. An example. Say a column from my table called 'country' looks like this: country: Holland England Ireland England Italy Holand England I want to return a list of entries, numbered by the amount of times they occur, like this: England - 3 Holland - 2 Ireland - 1 Italy - 1 Can anyone help me with this please?
  15. Hi, I've got some code which builds a query based on search results. I have an array of IDs called $player_ids, and the code builds the WEHRE clause based on that: foreach ( $player_ids as $output ) { $sql .= " || episode_player.player_id = $output"; } $sql = substr($sql,4); I then build my query as follows: $query = "SELECT DISTINCT * FROM episode INNER JOIN episode_player ON episode.id = episode_player.ep_id WHERE $sql "; This is working OK, and my final query looks something like this (obviously dependant on search results): SELECT DISTINCT * FROM episode INNER JOIN episode_player ON episode.id = episode_player.ep_id WHERE episode_player.player_id = 61 || episode_player.player_id = 36 || episode_player.player_id = 63 || episode_player.player_id = 62 || episode_player.player_id = 83 || episode_player.player_id = 31 || episode_player.player_id = 96 || episode_player.player_id = 16 || episode_player.player_id = 40 || episode_player.player_id = 104 || episode_player.player_id = 54 || episode_player.player_id = 53 || episode_player.player_id = 87 || episode_player.player_id = 9 || episode_player.player_id = 5 || episode_player.player_id = 7 || episode_player.player_id = 24 || episode_player.player_id = 56 || episode_player.player_id = 85 || episode_player.player_id = 73 || episode_player.player_id = 93 However, when I come to extract the results from this query, I find that there are duplicate rows. I don't see how this can be as i've used DISTINCT, but it just doesn't seem to be doing anything. Can anyone shed any light on this for me please?
×
×
  • 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.