Jump to content

monkeytooth

Members
  • Posts

    1,129
  • Joined

  • Last visited

    Never

Posts posted by monkeytooth

  1. Since your using mySQL there is not "IF" needed.. this would be more of a mySQL related question.. what you need to do is structure your queries example from existing code posted:

    $query = "SELECT * FROM ". $detailsTable;

     

    Would be changed to something like..

    $query = "SELECT * FROM ". $detailsTable WHERE listType = 'F'";

     

  2. .htaccess is not a project file, its a server file that tells the server what to do in certain events (thats the short and gritty version of it).

     

    Your project and executing it well thats a whole nother concept. You need a hosting account or you need to set up a local dev enviroment on your PC xampp I hear is a decent localized server if your on a windows machine.

    http://www.apachefriends.org/en/xampp.html

     

    After that, whats you projects coded language? PHP, ASP, Ruby, JavaScript, Other? A combination of all the above?

    You really havent posed any questions here for us to help you with. This form is for people to help others with generalize coding questions ie: you write a script, its broken you can't figure out why, you come here, hopefully someone here can help you.

     

    Actually i just noticed you said your using "php,mysql,apache server" sounds like you have your "test server" already. Apache is a web server. Back to the how to process the execution of your code/script put it in your root hosting folder and navigate to it with your browser.

  3. You would paste the extra part I mentioned, anywhere you want it to display the text in its "Shoutbox" form.

     

    As for the frame, yes it is possible. Just make it load in an iframe or something, and use a piece of javascript in the HTML for that frame that refreshes the frame every x seconds.

     

    an example of my code plus a refresh in a file for use in an iframe would be..

    <html>
    <head>
    <script type="text/JavaScript">
    <!--
    function timedRefresh(timeoutPeriod) {
    setTimeout("location.reload(true);",timeoutPeriod);
    }
    //   -->
    </script>
    </head>
    <body onload="JavaScript:timedRefresh(30000);">
    
    <?php
    $urls="http://www.yourdomain.com/filename.ext";
    $page = join("",file("$urls"));
    $kw = explode("\n", $page);
    
    for($i=0;$i<count($kw);$i++){
    echo $kw[$i]."<br />";
    }
    ?>
    
    </body>
    </html>
    

     

    A huge note worth mentioning is.. storing data in something like this is not highly advisable. A couple of the key reasons being..

    One is as this file grows, your bandwidth is going to consume quickly if your on a hosting package with limited bandwidth its going to hurt eventually. Say you get about 2000 lines of shouts each shout is 100 words or so, your looking at maybe 1) a 500kb file size on that text file (or bigger, maybe bigger). Now that doesnt seem like a lot, but lets pretend for a minute you get a spout of 100 people coming to your site in an hour. Thats 5mb of data used again doesnt seem like much but now imagine if they site there for an hour, your script is refreshing to 100 people every 30 seconds thats 500kb * 100 users * 120 refreshes per user in that hour. So in that hour you just popped 5,000kb 120 times.. thats 600,000kb or 585mb of bandwidth. And thats all for 1 hour, imagine a day where you've got many hours back to back like that.. then times that by 30 days..

     

    Also on the same note, short of hosting your site on a cloud or grid server system where resources are mirrored for heavy useage. A single file can get whats called a bottle neck effect. Think of a full bottle of soda for example. Unscrew the cap, and flip it upside down. It doesn't all come out at once does it. Takes a minute right? Think about that say concept as your file. Eventually it will get over used with all the constant calls to it, that some users will come up with a file not found error, which in turn will break your script.

     

    And biggest reason for me why I wouldnt do this text file as storage. Is its a security threat. Someone who knows what they are doing, or someone who is using bots to probe for things as such will eventually XSS attack your site, exploiting that file and dumping malisious code in it, and when it renders for them in the iframe can and will all them to do whatever said code does. It sucks trust me Ive had clients who have had it happen to them, clean up on all levels reallly sucks.

     

    Im going to go out on a limb say since your new to coding, you feel php is more than you can handle right now adding javascript, or the ability to use a database rather than a flat file seems like wayyy to much. I used to feel and think the same way so many years ago that I would go way above and beyond to go out of my way and find ways to avoid using javascript and mysql. What I have to say to you with that is don't avoid it, embrace it.. and then run with it.

     

    If you need further help feel free to message me on AIM (in profile). I wont serve as your end all be all resource of information and I wont do everything for you but Ill be happy to help when and if I can to getting you where you want to go with things. If you truly desire learning the craft, and are motivated enough to actually do the work needed to achieve the goals you want.

     

  4. Alright I know scraping is frowned upon.. but its for a client...  Anyways.. The below is supposed to form an array $kw for output. But its breaking on line 27:

      foreach ($kw as $keyword => $pages)  

     

    Ive concluded my array is being broken and then formed into an empty string, but I can't figure out where it wen't wrong.

     

    I want to say the trouble comes from lines 20-23:

      foreach($data as $temp) {
        $kx = text_between('"','"',$temp);
        if (is_array($kx)) $kw[key($kx)] = current($kx);
      }
    

     

     

    The full version..

     

    <?php
    function text_between($start,$end,$string) {
      $keyword = '';
      if ($start != '') {$temp = explode($start,$string,2);} else {$temp = array('',$string);}
      $temp = @explode($end,$temp[1],2);
      $temp2 = @explode($end,$temp[1],3);
      $pages = (int)@str_replace(',','',$temp2[1]); 
      if ($pages) $keyword[$temp[0]] = $pages;
      return $keyword;
    }
    
    function gsscrape($keyword) {
      $keyword=str_replace(" ","+",$keyword);
      $keyword=str_replace("%20","+",$keyword);
      global $kw;
      $data=file_get_contents('http://clients1.google.com/complete/search?hl=en&gl=us&q='.$keyword);
      
      $data=explode('[',$data,3);
      $data=explode('],[',$data[2]);
      foreach($data as $temp) {
        $kx = text_between('"','"',$temp);
        if (is_array($kx)) $kw[key($kx)] = current($kx);
      }
    }
    #simple to use, just use yourscriptname.php?keywords
    echo $_SERVER['QUERY_STRING'];
    if ($_SERVER['QUERY_STRING']!='') {
      gsscrape($_SERVER['QUERY_STRING']);
      foreach ($kw as $keyword => $pages) {
          gsscrape($keyword);
      }
    }
    #all results are in array $kw...
    echo "<pre>";
    print_r($kw);
    echo "</pre>";
    ?>

  5. Your not reading the text file though, your opening it currently to append to the text but not read from it..

    $urls="http://www.yourdomain.com/filename.ext";
    $page = join("",file("$urls"));
    $kw = explode("\n", $page);
    
    for($i=0;$i<count($kw);$i++){
    echo $kw[$i];
    }
    

     

    also change

    $stuff = $nickname . ": " . $message . "n";

    to

    $stuff = $nickname . ": " . $message . "\n";

     

    in your existing code posted..

     

  6. you may have to do a SELECT query to establish an array of all the existing rows that fall into those constants.. then run a delete on a per row basis using the results from your SELECT Query.. Or build a long delete query dynamicly through the results of the SELECT then run a single query with the delete that way.

  7. I'd add a new column to my db table that represents the current data set. The new column would specify region1, region2.. respectfully to what ever city falls into the region you want it to.. then just query for that alone when you want to list all the cites within a specific region..

     

    ie

    if($city == "region1")
    {
         $sql = "SELECT * FROM myTableName WHERE myNewColumnName = "region1";
    }
    else
    {
        //existing code you already have?
    }

  8. /data/images/Whitchurch.jpg//Applications/MAMP/htdocs/Data/images/Whitchurch.jpg

     

    somewhere your getting a double // which is likely resulting in an invalid path.

     

    so lets do this.. ill give you a quickie sample, not specific to what you have currently but to how I would handle it..

     

    my database would be:

      - Name: imagesDB with 3 columns.

          - Column 1 > name > ID : Type INT(11) AUTO INCREMENT

          - Column 2 > name > pic: Type varchar(255)

          - Column 3 > name > picpath : Type varchar(255)

     

    sample of the data stored per row

     

    1 | myimage1.jpg | path/to/my/img/folder

    2 | myimage2.jpg | path/to/my/img/folder

    3 | myimage3.jpg | path/to/my/img/folder

     

    how I would call it via the Query

     

    If I wanted to yield all of them and list them out.

    mysql_connect("localhost", "dbusername", "dbpassword") or die(mysql_error());
    mysql_select_db("imagesDB") or die(mysql_error());
    
    $result = mysql_query("SELECT * FROM imagesDB") or die(mysql_error()); 
    $row = mysql_fetch_array( $result );
    
    foreach($row as $value){
    echo "<img src=\"http://www.mydomain.com/".$value['picpath']."/".$value['pic']." border=\"0\" alt=\"".$value['pic']."\" /><br /><br />";
    }
    

     

    if I wanted one in specific I would

    mysql_connect("localhost", "dbusername", "dbpassword") or die(mysql_error());
    mysql_select_db("imagesDB") or die(mysql_error());
    
    $result = mysql_query("SELECT * FROM imagesDB WHERE ID=2") or die(mysql_error()); 
    $row = mysql_fetch_array( $result );
    
    echo "<img src=\"http://www.mydomain.com/".$row['picpath']."/".$row['pic']." border=\"0\" alt=\"".$row['pic']."\" />";
    

     

    The above is core basic concept mind you. If you want a good reference site, I used http://www.tizag.com/ so many years ago when I was learning. Its not a bad resource and they have multiple resources from PHP to mySQL to JavaScript and so on, as far as the basic 101 type stuff goes.

  9. you would need the full path. in your case since its an image on your harddrive, thats not on some form of server or another it would be

     

    C:\Users\{username}\Desktop\ (of course this would have to be altered to your systems direct path)

     

    Also to just display

     

    <img src=\"/Desktop/images/Whitchurch.jpg/{$row['images']}\">

     

    you wouldnt need

    header("Content-type: image/jpeg");

     

    as the image tag is standard html, the use of the header like you have it is for all different types of reasons other than what I am gathering here..

     

    Also keep in mind most browsers don't directly allow access to directories on peoples computers (including yours despit it being your code your computer etc) sometimes theres settings to disable to by pass that, also depends on your Operating System to, newer versions of Windows for example don't like to let many apps access the desktop without previous permissions given to the app(s)

     

     

  10. in essense what I said still stands. You just end up with a super sized query string which really isnt a problem per say. You would just have to redo the line

     

    $sqlQueryString .= "my_column LIKE '%".mysql_real_escape_string($value)."%'";

     

    to better fit your needs as you specify something like

     

    $sqlQueryString .= "my_column1 LIKE '%".mysql_real_escape_string($value)."%' OR ";
    $sqlQueryString .= "my_column2 LIKE '%".mysql_real_escape_string($value)."%' OR ";
    $sqlQueryString .= "my_column3 LIKE '%".mysql_real_escape_string($value)."%'";
    

     

    because as you have it right now. $filters is what it is. its either Ford, Ford Focus, Turbo Ford, something else.. with no breakage of the independent values as I am trying to show with the use of explode and foreach. As you have it, if you type Ford and theres values on any of those columns with ford in them anywhere you will yield a return result. Otherwise Something like Ford Focus Turbo won't show up cause your looking for that term specificly with anything on either side of it but none the less that exact term all the while. Of course again your going to have to refine the results in the example I show as you may get duplicate results Searching for Ford and then Focus may show return the same row.

     

    Bottom line is there is no special means of making the query much shorter and simpler like some tutorials would have you believe as those tutorials really go into the basics of the basics. So in the end your going to have a search query a mile long if someone types out a full range of keywords in the one text box. Only other way to go per say is rebuild your form from a single text input that someone can put anything in, to a multi part form thats got hardcoded constraints to search from. The possibility of the supersized query isn't a problem though. If it gets big enough it may take an extra second or three to run the query but in the end anything you do to try an harness the concept the way you want is going to take process time.

  11. hidden fields work, as long as they are within the <form> tags you are submitting. Although I wouldn't hard code my table names or anything that would make any connection to actual structure of my database into a place that's visible to those who know where to look in hopes of such information. Don't want to give any would be bad users anything pertinent to work with ya know.

     

    Your concept however is alright, I would just use a different association.. say instead of TableName use some other identifier whatever you want to call it really. that you can put in your form handling script if($myHiddenValue == "thisSpecialValue"){$tableToUse = "TableName";} little extra work and processing per say. But in the end run Im a paranoid person. I don't trust anyone that comes to sites I work on cause ya never know when your gunna get that one that will just really $*(#$*RT& up your day..

  12. Well your existing code shown no offence makes no sense, as on page load its going to get an SQL error, as there is no connection to work with. However if its defined somewhere else and you havent shown that, ok.. but with this code from the looks of it your just posting empty data to a database as soon as the page loads..

     

    If you want to auto populate fields in the form then you need to query an existing database for what you want those field values to be..

     

    then in the <input> tags you put a line value="$myDBValue" (of course you need to edit it to your needs.. but generally speaking thats all there is to auto population

     

    the code given here really doesnt make sense to your described need and desire though, and youve provided little background otherwise on how your orgainizing your data for use to do auto populations and otherwise so its not likely anyone can really help you much unless more is known.

  13. Thats very little description for a need that sounds much larger than PHP.

     

    Sounds like you need a database to store times and dates in to then check against for a specific user, which will then shoot them off an email based on x amount of time prior to said return date. Which then will need some reference as to whether or not it was returned so its not sending emails constantly to anyone.. and the list of concept goes on from there..

     

    Through the use of cron-jobs and PHP backed up with id say mySQL as your DB this is achievable without issue (aside from the actual time needed to put something like this together).

     

     

  14. well crons are scheduled runs. So if your looking to have it run any time or any day based on your choice I would figure it would be best to just copy the concept minus the date constraints to another file that you can just visit in your browser. But keep in mind the people who had made it originally may have done it on Sat for a specific reason, could be what ever the cron is doing is data intense and not something you just wanna run whenever, could be it connects to another system to get new data of which that system only updates once a week.. could be that same concept of connecting to another system where they system provider specifies in the terms you are only allowed to do it once a week, etc.. Im not familiar with your site or its code or what ever its true functionality is and the little code you shown is irrelivant per say to the need your describing. But thats only merely my own 2 cents. I could be wrong :)

  15. I usually handle all my inputs on a one to one basis, as most of my inputs I require different things from..

    in the form tag you don't need a value (actually I'm not even sure thats valid by W3C standards, I know Ive never seen it though).

     

    Anyway.. if your looking just to have an array of data from any given form that you want to work with that array instead of a one to one, then all you need to do is go based on $_POST without the ['whatever'] as $_POST is an array by itself if you post your form and on the page its going to if you put

     

    echo "<pre>";
    print_r($_POST);
    echo "</pre>";
    

     

    you will see all the data in said array. All though I see you mention multiple forms? Do you mean on the same page? If so then a post is a post is a post. what ever lies between

    <form> and </form>

    is fair game to $_POST on a per form tag basis once the submit button is hit within those form tags.. Anything outside of that particluar form is not submitted. 

  16. Chances are you have to 1 change the "Collation" type of the table/column your storing the data in within the DB, most DB's by defualt (that ive run into) seem to set it to some latin charset by default. Which when stored might be losing the character in translation so to speak. 2 you might need to use something like

    http://php.net/manual/en/function.utf8-decode.php

    when calling the data out.

  17. I hear ya on simplicity. Got no problems with that.. But I can't just walk past a post that has no mention of something like sanitization and looks like that OP might not know better (yet), and not mention it, as its good practice to pick up right from the beginning :)

  18. $rows = mysql_num_rows(mysql_query("SELECT * FROM users WHERE username='$username'" AND password='$password'));

     

    bare in mind this is user input client side.. so sanitize your queries

     

    $rows = mysql_num_rows(mysql_query("SELECT * FROM users WHERE username='".mysql_real_escape_string($username)."' AND password='".mysql_real_escape_string($password."'));

  19. I think I might retract my previous statement, although I think what I said in the long run may be a bit easier. Despite the extra query made to achieve the goal. I have to say though I don't typically use this myself (maybe I should start)..

     

    This might be a good reference for ya.

    http://dev.mysql.com/doc/refman/5.0/en/if-statement.html

     

    its not specific to what you want to do, but I think its a good starting place

  20. I'm not 100% understanding what your saying. But chances are in the overall you would be better to do a SELECT to return a count.. based on that count a simple if-else to either update or insert. But generally speaking in order to find out if there is something to update you have to first search for it. Though I am sure there is some super elaborate way to do what your saying without directly selecting anything out right. But for me, in a simple case like this sounds its likely easier to just go a head and select then count then do upon that count what need be done. If you want to avoid duplicates in the long run, try

     

    SELECT DISTINCT(column_name) FROM table_name WHERE column_name = 'value'

     

    DISTINCT runs a smidge bit slower as it will crawl through the entire DB of records on that particular table but it will or should return only one result every time in a matter of speaking at least.

×
×
  • 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.