Printer Friendly Version Print this thread
Email this thread to a friend eMail this thread to a friend
  • Unusual script request (In: Coding & Databases - PHP, ASP, Perl, etc.)
  • SEO Top 10 Check List (In: General Search Engine Optimization)
  • Featured Web Site Template

    Hundreds More at Free Site Templates.com!

    Web Site Partners
    Sponsored Links
    Jet City Software
     
    Whos Here ?
    Reflects user activity within the last 5 minutes
    Moderator(s): Prowler, jcokos
    Member Message

    karrella
    Joined: Aug 19, 2005
    # Posts: 41

    View the profile for karrella Send karrella a private message

    Posted: 2005-Dec-22 15:27
    Edit Message Delete Message Reply to this message

    Basicly what im trying to do is have a "products" page check a js file for an "in stock" or "out of stock" and write that to the "products" page.

    The reason I want to do this is because the products will be listed on multiple pages and I dont want to have to edit the pages to say in stock etc, also I want to make the stock file easy to edit for a person who doesnt know much more than how to write emails.

    So my idea is to have the list in the js file;
    300 = 1
    301 = 0
    302 = 1
    303 = 1

    where the 300 number is the product number and the 1 or 0 is the in stock or out of stock. Hopefully I can add an if 1 write "in stock" else 0 write "out of stock"

    Then the script on "products" page will just have to check the js file for the result for the product number.

    I'm sure there are a ton of ways to go about doing this, but could someone help me get the ball rolling on the code I have tried and each time it returns absolutely nothing, so I'm way off so far.

    Thanks



    Dinkar
    Staff
    Joined: Aug 12, 2001
    # Posts: 4391

    View the profile for Dinkar Send Dinkar a private message

    Posted: 2005-Dec-22 19:57
    Edit Message Delete Message Reply to this message

    It's simple. Just put it in Array and write If Else code.

    But IMO, you should do it at server side language like php/perl/asp etc etc. Avoid Javascript.




    karrella
    Joined: Aug 19, 2005
    # Posts: 41

    View the profile for karrella Send karrella a private message

    Posted: 2005-Dec-22 20:11
    Edit Message Delete Message Reply to this message

    That works, do you know what thats called in php? that will help me look up how to's.

    All im good at in php is the include page thing, and thats a no brainer!

    Thanks,





    Dinkar
    Staff
    Joined: Aug 12, 2001
    # Posts: 4391

    View the profile for Dinkar Send Dinkar a private message

    Posted: 2005-Dec-22 20:45
    Edit Message Delete Message Reply to this message

    It's call Array in php too. Read PHP Manual to learn more.



    karrella
    Joined: Aug 19, 2005
    # Posts: 41

    View the profile for karrella Send karrella a private message

    Posted: 2005-Dec-22 21:09
    Edit Message Delete Message Reply to this message

    Perfect! thanks a ton!



    karrella
    Joined: Aug 19, 2005
    # Posts: 41

    View the profile for karrella Send karrella a private message

    Posted: 2005-Dec-22 22:43
    Edit Message Delete Message Reply to this message

    Ok, I read through that php stuff, and wow was having some trouble seeing what was what, but in doing so I did figure it out in javascript....

    Java file looks like this:

    var stock = new Array()
    stock[300] = "In Stock"
    stock[302] = "In Stock"
    stock[306] = "In Stock"
    stock[309] = "Out Of Stock"
    stock[313] = "In Stock"

    -------------------------------------------
    actual product pages look like this:

    <html>
    <head>
    <script type="text/javascript" language="JavaScript"src="stock.js"></script>
    </head>
    <body>
    <script type="text/javascript"> {
    document.write(stock[300] + "<br />"wink
    }
    </script>
    </body>
    </html>
    -------------------------------------

    So now my question is, is there any reason to avoid javascript when i'm just doing something this simple?

    Thanks,

    :edit: Smileys are the spawn of satan! See next post for code.



    karrella
    Joined: Aug 19, 2005
    # Posts: 41

    View the profile for karrella Send karrella a private message

    Posted: 2005-Dec-22 22:48
    Edit Message Delete Message Reply to this message

    The code messed up by the smiley for anyone interested is:

    [code] <html>
    <head>
    <script type="text/javascript" language="JavaScript"src="stock.js"></script>
    </head>
    <body>
    <script type="text/javascript"> {
    document.write(stock[300] + "<br />")
    }
    </script>
    </body>
    </html>[code]



    Dinkar
    Staff
    Joined: Aug 12, 2001
    # Posts: 4391

    View the profile for Dinkar Send Dinkar a private message

    Posted: 2005-Dec-22 22:52
    Edit Message Delete Message Reply to this message

    If you use JS:

    1. Browsers cache static pages on user computer to load those pages faster in future. So the user may get wrong status of stock availability.

    2. If you have 1,000's of products then page loading time will be much more. It will increase uses of your bandwidth also.






    Dinkar
    Staff
    Joined: Aug 12, 2001
    # Posts: 4391

    View the profile for Dinkar Send Dinkar a private message

    Posted: 2005-Dec-22 22:57
    Edit Message Delete Message Reply to this message

    If you have too many products, you may like to use database. In that case, MySQL will be a good choice.



    Dinkar
    Staff
    Joined: Aug 12, 2001
    # Posts: 4391

    View the profile for Dinkar Send Dinkar a private message

    Posted: 2005-Dec-22 23:09
    Edit Message Delete Message Reply to this message

    Try this:



    Code: [copy]








    g1smd
    Staff
    Joined: Jul 28, 2002
    # Posts: 10440

    View the profile for g1smd Send g1smd a private message

    Posted: 2005-Dec-22 23:39
    Edit Message Delete Message Reply to this message

    PHP is the way to go. Keep all the processing on your server and send the result in HTML to the browser.

    With JS the user runs the program, may have an old cache copy, or may have JS off. JS is not the right tool.



    karrella
    Joined: Aug 19, 2005
    # Posts: 41

    View the profile for karrella Send karrella a private message

    Posted: 2005-Dec-23 00:01
    Edit Message Delete Message Reply to this message

    excelent I totally didnt think of that!
    I'm just amazed I figured it out in js, lol.

    Again, thanks a lot, I'm sure I'll have to ask a few more questions by the time im done, but the array stuff is making much more sense now!

    Thanks,



    karrella
    Joined: Aug 19, 2005
    # Posts: 41

    View the profile for karrella Send karrella a private message

    Posted: 2005-Dec-23 00:23
    Edit Message Delete Message Reply to this message

    So using the script you provided Dinkar, would I be able to have that in an external file and use $productID = "304"; on several different pages to check availability. I don't want to have to update each product page, just a master stock page, to change all the different products. How would I ask it to call up a certain php file and check it there just like I did in js.

    Thanks,



    g1smd
    Staff
    Joined: Jul 28, 2002
    # Posts: 10440

    View the profile for g1smd Send g1smd a private message

    Posted: 2005-Dec-23 01:00
    Edit Message Delete Message Reply to this message

    You could "include" that file each time; the included file containing just the PHP stuff....


    Eventually you might want to keep all this information in a mySQL database, but for now keep it simple.. that way you learn more.





    karrella
    Joined: Aug 19, 2005
    # Posts: 41

    View the profile for karrella Send karrella a private message

    Posted: 2005-Dec-23 01:33
    Edit Message Delete Message Reply to this message

    So if I php include the file once at the top of the page, then use,

    <?php
    $productID = "304";
    ?>

    in each spot I want to check availability that should work fine correct?

    Thanks,



    g1smd
    Staff
    Joined: Jul 28, 2002
    # Posts: 10440

    View the profile for g1smd Send g1smd a private message

    Posted: 2005-Dec-23 02:12
    Edit Message Delete Message Reply to this message

    I would guess so.

    Once you get to thousands of products it is going to an inefficient method, but for now go with that, it will work OK.



    karrella
    Joined: Aug 19, 2005
    # Posts: 41

    View the profile for karrella Send karrella a private message

    Posted: 2005-Dec-23 04:25
    Edit Message Delete Message Reply to this message

    Tried that, and it actually doesnt work. It will only display the first include.

    I also tried adding the include with each product, and most work fine but the first one on the page will always no matter what the value display an "out of stock"

    Any more ideas?
    Thanks,



    karrella
    Joined: Aug 19, 2005
    # Posts: 41

    View the profile for karrella Send karrella a private message

    Posted: 2005-Dec-23 05:05
    Edit Message Delete Message Reply to this message

    Sorry for all the posts, but I think i've found an easy solution. The only thing is (just like my original js) you have to type the words "in stock", "out of stock" rather than do the 1, 0 thing, but it works! also the variable cannot be a number so I used our full product code which works out perfect because it starts with a number.

    [code]
    Stock file:
    <?php
    $rb300 = "In Stock";
    $rb301 = "Out of Stock";
    ?>

    Product page:
    <?php
    include ("stock.php");
    echo "$rb300 <br>";
    ?>
    [code]

    There we have an easy solution, assuming there isn't some other kind of bad thing I don't know about.
    Yes, I totally agree that MySQL is better for most jobs like this. The company this is for will not ever have more than 25 - 30 products, and as I said has to be some what easy to update for a non-web person, the business owners (my compter illiterate parents) LOL

    Thanks for the help!




    karrella
    Joined: Aug 19, 2005
    # Posts: 41

    View the profile for karrella Send karrella a private message

    Posted: 2005-Dec-23 06:19
    Edit Message Delete Message Reply to this message

    Have you ever heard the saying measure twice cut once.... its a woodworker thing, anyways how about the saying;

    "Check to make sure your parents web host has PHP installed before spending a day creating something that will never work!"

    Man am I bummed, I tested it in my own web space where PHP is definatly installed, and after finally finishing all that work, nothing....

    I have half a mind to cancel the service cause of that, come on people its almost 2006!

    Well Happy Holidays Everyone! I refuse to type another line until I get some turkey into me!



    g1smd
    Staff
    Joined: Jul 28, 2002
    # Posts: 10440

    View the profile for g1smd Send g1smd a private message

    Posted: 2005-Dec-23 19:53
    Edit Message Delete Message Reply to this message

    A friend of mine always says "if you thought this was simple, then you have probably overlooked something important".

    Too true. Too often.


    You are not permitted to post messages in this forum or topic, because of one or more of the following reasons:
    1. You have not yet logged in, or registered properly as a member
    2. You are a member, but no longer have posting rights.
    3. This is a private forum, for which you do not have permissions.

    If you are a recent member, it's possible that you simply have not yet confirmed your account. Please check your email for a message entitled 'JimWorld Forums: Confirm Your Account' and follow the instructions contained within.

    If you cannot find this message, click here to Re-Send it.

    If you are still experiencing problem, please read the Login Assistance Article for some advice on what may be causing your login not to work properly.

    Switch to Advanced Editor and ... Create a New Topic or Reply to this Thread

    New posts Forum is locked
    © 1995  ·  iWeb, Inc  ·  DBA JimWorld Productions