Page 2 of 2 FirstFirst 1 2
Results 16 to 26 of 26

Thread: php insert id

  1. #16
    Join Date
    Mar 2008
    Location
    pd
    Posts
    497
    Rep Power
    151
    There's another thread recently asking if PHP is a good thing to learn for the web. This is an example of how it's really easy to solve a problem in PHP. The thing you can't see is that doing it this way could be a disaster waiting to happen. Storing files in a database isn't a very good idea anyway - filesystems are the right places to store files. I don't know anything about PHP, but knowing that it's an interpreted script, and seeing that piece of code makes me worry that the webserver will read the entire contents of your PDF into the array it creates with my_sql_fetch_array(). That would use a lot of server memory. If you used this technique with a SELECT statement that isn't LIMIT 1, you could easily bring a server to its knees!

    Maybe the php developers are smarter than that and the DB query actually returns a handle to a stream to the big data object, so it can echo the contents in small chunks. If a real PHP wizard should read this thread, I'd be interested to know! I don't like to use PHP because I think it conceals too much of what it does while it's making things easy for the developer. That's obviously why some people like it so much!

    I'd be interested to know how Nur and Catz get on with their developments...

  2. #17
    Join Date
    Aug 2009
    Location
    Kuching
    Posts
    19
    Rep Power
    0
    still blur now.. huhuhuuu...

  3. #18
    Join Date
    Aug 2009
    Location
    Malaysia
    Posts
    8
    Rep Power
    0
    Quote Originally Posted by nur_kasih View Post
    thanks seanie for sharing..

    about the pdf, i have a table for pdf in my database. before i can view the
    pdf i actually upload it to my server and all data like pdf file name, and
    description is post to my database. i manage to upload pdf file to my server
    but now i cannot view it at my page. can i do like that? i mean can i put pdf file to my server and then view it at my page?
    Have you tried using Inline Frame? I just did & it worked perfectly.

    Test below:
    http://lotmaya.com/pdf/viewpdfinphp.php

  4. #19
    Join Date
    Mar 2008
    Location
    pd
    Posts
    497
    Rep Power
    151
    Very nice lotmaya! I don't think I've ever seen a PDF in an iframe before - the idea never even crossed my mind. Maybe you'll start something!

    I'm going to use it for spider.my!

  5. #20
    Join Date
    Mar 2008
    Location
    pd
    Posts
    497
    Rep Power
    151
    A productive day on WMM... thanks to lotmaya for the iframe suggestion, I quite like it for displaying PDFs (and probably some other content I haven't tried yet...) on spider.my's cache page.

    If you revisit that cache page from spider.my I linked earlier - I've left the nasty link to the PDF as before. It's the one that says 'Click here to open or download'. If you right click it and choose Save As (don't actually save anything strange men tell you to!), you'll see in the Save As dialog that it uses the nasty 'name' from the URL of my cache page.

    [NB I used 'application/x-pdf' earlier, it should have been 'application/pdf']

    If your browser shows frames, and you have the Acrobat plugin, you should be able to click on the 'save file' button (it looks like a 3.5" diskette on my PC) in the Acrobat frame, and it'll open the save dialog again. This time, you can see it gives you the original filename.

    The cache page is
    [spider.my cache] http://www.insteadofwar.org/site/images/...

    I have a CacheObject page generator that provides the content for spider.my URLs like /co and /cacheobject/*. If I use /co, I pass the ID of the PDF file in the database as an argument in the URL. That's why the save dialog tells me the filename is 'co'. If I use /cacheobject, I pass the ID - and the filename - as part of the URL path, like
    Code:
    http://spider.my/cacheobject/1535440/occupationprojectflyer2.pdf
    spider.my is written in Java, using a WebServer that I wrote called Spinneret (I'm hoping to make it available as an open source project later this year). In Spinneret, the URLs are just strings that have to match a table that provides 'hooks' into the Java application that is your website. You can use pattern matching, so /cacheobject/* matches the same class as /co. The class checks the URL and if it finds '/cacheobject/' at the start, extracts the ID from the middle part, to fetch the content from the DB. It doesn't use the 'filename' part ('occupationprojectflyer2.pdf' in the example above) of the '/cacheobject' URL at all. Your browser uses the 'filename' part of the URL when it opens the Save dialog.

    If you're using Apache, I think the way you would do this is to use URL rewriting. URL rewriting in Apache scares me, so you really need to find a mod_rewrite wizard to tell you how to do the same thing with Apache. If you use IIS, well I should just give up.

  6. #21
    Join Date
    Aug 2009
    Location
    Johor Bahru
    Posts
    16
    Rep Power
    0
    Your spider is awesome, Malaysian Spider, SUPPORT IT!!!

    And for this problem, first, when you make the primary key id to be auto_increment, then after you insert a row to that table, you can try to use mysql_insert_id() function to return the new id;

    for example, currently you have record id = 1; you insert a row
    $query = mysql_query("INSERT INTO mytable (name, age) VALUES ('Ali', 23)");

    $new_id = mysql_insert_id($query);

  7. #22
    Join Date
    Aug 2009
    Location
    Kuching
    Posts
    19
    Rep Power
    0
    hi all

    thanks again for helping me solve my problem. i use header like seanie told and combine with iframe. and now i can view my pdf n it is so nice. thanks to you lotmaya.

  8. #23
    Join Date
    Aug 2009
    Location
    Kuching
    Posts
    19
    Rep Power
    0
    Quote Originally Posted by fyhao View Post
    Your spider is awesome, Malaysian Spider, SUPPORT IT!!!

    And for this problem, first, when you make the primary key id to be auto_increment, then after you insert a row to that table, you can try to use mysql_insert_id() function to return the new id;

    for example, currently you have record id = 1; you insert a row
    $query = mysql_query("INSERT INTO mytable (name, age) VALUES ('Ali', 23)");

    $new_id = mysql_insert_id($query);

    oh ok. i will try it.. thanks

  9. #24
    Join Date
    Mar 2008
    Location
    pd
    Posts
    497
    Rep Power
    151
    it is so nice
    It's good of you to post a 'all done now' response - I'm glad you got everything working.

    Your spider is awesome, Malaysian Spider, SUPPORT IT!!!
    thanks - but spider.my will always be a 'work in progress'. I think I could make a search engine, but I can't afford 100,000 servers. Maybe I should start a thread asking for suggestions for what I could do with a search engine running on 2 small servers!

  10. #25
    Join Date
    Aug 2009
    Location
    Kuching
    Posts
    19
    Rep Power
    0
    Quote Originally Posted by Seanie View Post
    It's good of you to post a 'all done now' response - I'm glad you got everything working.!

    hi again.. i would like to do so but i just use localhost for the system. not yet publish. do you know where n what the best site to get free hosting? hehehe..

  11. #26
    Join Date
    Mar 2008
    Location
    pd
    Posts
    497
    Rep Power
    151
    i just use localhost for the system
    You could just continue to do that - how good is your Internet connection? poditronic.com and spider.my are both running on my desk on Streamyx 512(256up)kbit/s. I use ZoneEdit for Dynamic DNS.

    If you're hosting PDFs and on Streamyx, that may not be ideal. You could test it by looking up your WAN IP address:

    Poditronic: IP address check

    Then set up your router to 'Port Forward' incoming requests on port 80 (might be called 'web server' or 'http server' by your router) to your localhost's LAN IP address (probably something like 192.168.x.x if you're at home).

    Then you could go to your local Internet Cafe, type in that WAN IP address and see what it's like to be your own hosting company! It's very expensive, leaving a PC on 24/7, even a low-power one. The servers I use only use just over 50W, but that's still about 50 sen per day. If you could find an old, but good quality PC, you could conceivably get that down below 20sen per day if you could run it diskless (USB drive?), headless and fanless.

    It's almost certainly better for you to find professional hosting - I don't know if you'll have much luck finding free PHP hosting that's any good.

Page 2 of 2 FirstFirst 1 2

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. How to insert song to your site, i use Joomla CMS
    By blackmachine in forum Website Design
    Replies: 2
    Last Post: 14-01-2008, 10:37 AM
  2. insert php in html
    By sloth in forum Website Programming
    Replies: 7
    Last Post: 26-08-2005, 07:34 PM
  3. insert data into multiple table
    By azmaliya in forum Website Programming
    Replies: 18
    Last Post: 06-08-2005, 11:02 AM
  4. XML : macam mana nak insert new record?
    By therion in forum Website Design
    Replies: 21
    Last Post: 23-04-2005, 09:20 AM
  5. insert multiple data
    By vash in forum Website Programming
    Replies: 4
    Last Post: 28-04-2004, 02:48 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Search Engine Optimization by vBSEO 3.5.0 RC1 PL1

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112