Attn PHP guys = Stupid $20 contest for stupid wannabe programmer

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mkx
    Confirmed User
    • Nov 2003
    • 4001

    #1

    Attn PHP guys = Stupid $20 contest for stupid wannabe programmer

    Ok heres the nutshell, I am trying to put together a automated accounting/inventory system for one of my projects and want to do it on my own with minimal php knowledge.

    Here is how the contest works, I will ask up to 20 stupid php questions in this thread and the webmaster who provides the most 'first correct replies' gets $20 sent to their paypal or epassporte account. All 20 questions are guaranteed within one week (probably won't last more than a a couple days) otherwise the contest ends and the current winner wins. I figure I can create 20 posts getting these codes free but I guess this is a cheap ass method of giving back to all the helpers.

    My first question =

    I need the correct PHP code for the following statement:

    If $item_title = blah
    $R_Qty_1 = blah AND R_Item_1 = blah AND R_Qty_2 = blah AND R_Item_2 = blah AND R_Qty_3 = blah AND R_Item_3 = blah
    Last edited by mkx; 01-23-2007, 08:48 PM.
  • fatdicksimon
    Confirmed User
    • Feb 2006
    • 226

    #2
    <?php
    if ($item_title=="blah) {
    $R_Qty_1 = blah;
    $R_Item_1 = blah;
    $R_Qty_2 = blah;
    $R_Item_2 = blah;
    $R_Qty_3 = blah;
    $R_Item_3 = blah;
    }
    ?>

    good luck
    icq: 199791893
    holler at me

    Comment

    • fatdicksimon
      Confirmed User
      • Feb 2006
      • 226

      #3
      if you need something coded i may do it for free in exchange for a hard link or two if you have some traffic. if ur interested, get at me on icq.
      icq: 199791893
      holler at me

      Comment

      • martinsc
        Too lazy to set a custom title
        • Jun 2005
        • 27043

        #4
        Originally posted by fatdicksimon
        <?php
        if ($item_title=="blah) {
        $R_Qty_1 = blah;
        $R_Item_1 = blah;
        $R_Qty_2 = blah;
        $R_Item_2 = blah;
        $R_Qty_3 = blah;
        $R_Item_3 = blah;
        }
        ?>

        good luck
        you forgot the closing quotes in the if statement
        and the blah's below should be in quotes too...
        Last edited by martinsc; 01-23-2007, 08:56 PM.
        Make Money

        Comment

        • mkx
          Confirmed User
          • Nov 2003
          • 4001

          #5
          that should do, thanks

          fatdicksimon = 1

          Comment

          • fatdicksimon
            Confirmed User
            • Feb 2006
            • 226

            #6
            whoops i missed some quotes...

            <?php
            if ($item_title=="blah") {
            $R_Qty_1 = "blah";
            $R_Item_1 = "blah";
            $R_Qty_2 = "blah";
            $R_Item_2 = "blah";
            $R_Qty_3 = "blah";
            $R_Item_3 = "blah";
            }
            ?>
            icq: 199791893
            holler at me

            Comment

            • fatdicksimon
              Confirmed User
              • Feb 2006
              • 226

              #7
              Originally posted by martinsc
              you forgot the closing quotes in the if statement
              and the blah's below should be in quotes too...
              yeah, i just caught that, thanks!
              icq: 199791893
              holler at me

              Comment

              • mkx
                Confirmed User
                • Nov 2003
                • 4001

                #8
                is this supposed to work even if item_title = "blah blah blah" with the spaces? i got it to work with a number without spaces but not with a line of text with spaces.

                Comment

                • Zoose
                  Confirmed User
                  • Aug 2006
                  • 268

                  #9
                  Give us a better idea of what exactly you're trying to do. It gets a bit more complicated if you want to check "if title CONTAINS blah" and not "if title IS blah".

                  RTFM ( no offense ) - http://www.php.net/stristr

                  Comment

                  • woj
                    <&(©¿©)&>
                    • Jul 2002
                    • 47880

                    #10
                    wow, whole $20 for answering 20 questions?
                    Custom Software Development, email: woj#at#wojfun#.#com to discuss details or skype: wojl2000 or gchat: wojfun or telegram: wojl2000
                    Affiliate program tools: Hosted Galleries Manager Banner Manager Video Manager
                    Wordpress Affiliate Plugin Pic/Movie of the Day Fansign Generator Zip Manager

                    Comment

                    • Nookster
                      Confirmed IT Professional
                      • Nov 2005
                      • 3744

                      #11
                      If the project takes me less than an hour to code I'll do the whole shebang for $20. (You're asking rudimentary questions so I'm guessing the project shouldn't take long.)
                      The Best Affiliate Software, Ever.

                      Comment

                      • mkx
                        Confirmed User
                        • Nov 2003
                        • 4001

                        #12
                        Originally posted by fatdicksimon
                        if you need something coded i may do it for free in exchange for a hard link or two if you have some traffic. if ur interested, get at me on icq.
                        Originally posted by Zoose
                        Give us a better idea of what exactly you're trying to do. It gets a bit more complicated if you want to check "if title CONTAINS blah" and not "if title IS blah".

                        RTFM ( no offense ) - http://www.php.net/stristr
                        This works =
                        if ($row['item_name']=="test")

                        This doesn't
                        if ($row['item_name']=="test test-test")

                        I need it to be able to accept "test test-test" as the item title to lookup

                        Comment

                        • mkx
                          Confirmed User
                          • Nov 2003
                          • 4001

                          #13
                          Next question is adding up all rows in a section of a field. for example, i have a field called Total_Income with rows containing numbers like 5, 20, and 9. I would like a script that displays the total income (34). If this can be based on the payment_date containing the "payment month" written down as 04:55:21 Jan 19, 2007 PST it will be two points

                          So basically,

                          $query = "SELECT total_income FROM `db` WHERE payment_date **CONTAINS** Jan ORDER BY id DESC";

                          echo
                          Total income = total_income_of_jan

                          Comment

                          • mkx
                            Confirmed User
                            • Nov 2003
                            • 4001

                            #14
                            Originally posted by Nookster
                            If the project takes me less than an hour to code I'll do the whole shebang for $20. (You're asking rudimentary questions so I'm guessing the project shouldn't take long.)
                            This is something that I must do myself as there is a lot of sensitive data plus I want to to be completely custom and my mind changes all the time

                            Comment

                            • jMEGA
                              Confirmed User
                              • Oct 2005
                              • 671

                              #15
                              $query = "SELECT SUM(total_income) FROM `db` WHERE payment_date='Jan' ORDER BY id DESC";
                              Design | SEO | Photo / Video Editing
                              ( ICQ 49354667 )

                              Comment

                              • mkx
                                Confirmed User
                                • Nov 2003
                                • 4001

                                #16
                                Originally posted by jMEGA
                                $query = "SELECT SUM(total_income) FROM `db` WHERE payment_date='Jan' ORDER BY id DESC";

                                Payment date should *contain* "Jan" since this is how it is entered "04:55:21 Jan 19, 2007 PST"

                                Comment

                                • mkx
                                  Confirmed User
                                  • Nov 2003
                                  • 4001

                                  #17
                                  Originally posted by woj
                                  wow, whole $20 for answering 20 questions?
                                  Well mr. woj, if you do the math 11 answers guarantee you the win

                                  Comment

                                  • jMEGA
                                    Confirmed User
                                    • Oct 2005
                                    • 671

                                    #18
                                    Originally posted by jMEGA
                                    $query = "SELECT SUM(total_income) FROM `db` WHERE payment_date='Jan' ORDER BY id DESC";
                                    here

                                    $query = "SELECT SUM(total_income) FROM `db` WHERE MONTH(payment_date)='01' ORDER BY id DESC";
                                    Design | SEO | Photo / Video Editing
                                    ( ICQ 49354667 )

                                    Comment

                                    • calmlikeabomb
                                      Confirmed User
                                      • May 2004
                                      • 1323

                                      #19
                                      Originally posted by mkx
                                      Payment date should *contain* "Jan" since this is how it is entered "04:55:21 Jan 19, 2007 PST"
                                      Assuming you've got your db connection established..

                                      Originally posted by calmlikeabomb
                                      $Total= mysql_result(mysql_query("SELECT SUM(total_income) AS Total FROM `db` WHERE payment_date LIKE '%Jan%'"),0);

                                      print $Total;
                                      subarus.

                                      Comment

                                      • CyberHustler
                                        Masterbaiter
                                        • Feb 2006
                                        • 28778

                                        #20
                                        <? ?> ...thats how much php I know
                                        “If you can convince the lowest white man he’s better than the best colored man, he won’t notice you’re picking his pocket. Hell, give him somebody to look down on, and he’ll empty his pockets for you.”

                                        Comment

                                        • mkx
                                          Confirmed User
                                          • Nov 2003
                                          • 4001

                                          #21
                                          Originally posted by calmlikeabomb
                                          Assuming you've got your db connection established..
                                          winner


                                          fatdicksimon = 1
                                          calmlikeabomb = 1

                                          Comment

                                          • calmlikeabomb
                                            Confirmed User
                                            • May 2004
                                            • 1323

                                            #22
                                            This would probably suit your first question a little nicer:

                                            Again, assuming you've already got the db connection established...


                                            <?

                                            ob_start();

                                            /* Generally with apps like you are making you want to store all information in the database and calculate totals such as total items in inventory, total sales, total debt ect on the fly. Cause it's information that is constantly changing and would be a real pain if you had to edit the source file of your app each time you made some $$, sold an item, restocked, got something new in stock, etc.

                                            Make a separate table for your items with fields such as ID, ItemTitle, Description, Onhand, Warehouse, Cost, etc (a field for each piece for product information you will be storing). With that being said let's iterate through the products table rows and create a clickable list of products that will take us to a page for viewing more information (could just as easily be a form for editing the product. We will assume this file is called admin.php make sure this file is protected with cookies, sessions, http authentication, .htaccess, whatever. */

                                            if(!isset($_GET['item'])) {//Not viewing a specific item so show the item list.

                                            $res=mysql_query("SELECT ID, ItemTitle FROM ProductsTable");
                                            while($row=mysql_fetch_assoc($res)) {$x++;
                                            $ItemMenu .="$x) <a href=\"admin.php?item=$row[ID]\">$row[ItemTitle]</a><br/>";

                                            }

                                            print $ItemMenu;

                                            unset($res, $row, $x);

                                            }else{/* We are viewing an item. Here you can show all the items details or even a form that allows you edit the item with an UPDATE query. */

                                            $res=mysql_query("SELECT * FROM ProductTable WHERE ID='$_GET[item]' LIMIT 1");

                                            if(mysql_num_rows($res) < 1) {//If no matching record is found redirect to admin.php

                                            header("Location: admin.php"); ob_flush(); exit();

                                            }else{//Item has been located, store row details into associative array.

                                            $Item=mysql_fetch_assoc($res);

                                            /* Now here is where you gotta get creative. You've got the record pulled from the database now along with all the details from each field. You just gotta refer to them like this inorder to use the information: $Item[FieldName]*/

                                            echo"Title of Item: $Item[ItemTitle] <br/> OnHand Stock: $Item[OnHand]<br/>,etc of course use any html you want just refer to the $Item[] array to access your item details.";

                                            }

                                            /* Hope this can get ya going. BTW, I didn't execute any of that code. Let me know if you have any problems - I did glance for bugs, but didn't use an editor to type it (easier to over look syntax errors if the editor doesn't do color coding). Keep us advised.. */

                                            ?>

                                            Last edited by calmlikeabomb; 01-24-2007, 12:12 AM.
                                            subarus.

                                            Comment

                                            • calmlikeabomb
                                              Confirmed User
                                              • May 2004
                                              • 1323

                                              #23
                                              http://rafb.net/p/OdT5zc28.html - Here's the same code color coded. Soon as I opened the code in my editor I noticed I missed a brace. Follow the link to the updated code. You should be able to just establish your connection after that output buffering on line 2 (haha, which I also forgot. Just add: ob_start();) and then edit those sql queries and be on your way.
                                              subarus.

                                              Comment

                                              • Natural Cause
                                                Confirmed User
                                                • Oct 2006
                                                • 222

                                                #24
                                                This thread is pretty stupid.

                                                Comment

                                                • Jamie
                                                  Confirmed User
                                                  • Apr 2001
                                                  • 2517

                                                  #25
                                                  Real dev's don't have time for this bullshit
                                                  CelebPay: Promote Celebrity Reviews
                                                  i/c/q - :1851935

                                                  Comment

                                                  • calmlikeabomb
                                                    Confirmed User
                                                    • May 2004
                                                    • 1323

                                                    #26
                                                    Keep your money. I've got time to help out - not in this thread to make any $.
                                                    subarus.

                                                    Comment

                                                    • bizarredollars
                                                      Confirmed User
                                                      • Mar 2006
                                                      • 1582

                                                      #27
                                                      Spend the $20 on a book.. SAMS was one of the best investments I ever made. Knowledge = Power.

                                                      [email protected]
                                                      icq: 205-252-550

                                                      Comment

                                                      • sarettah
                                                        see you later, I'm gone
                                                        • Oct 2002
                                                        • 14346

                                                        #28
                                                        Originally posted by calmlikeabomb
                                                        Assuming you've got your db connection established..
                                                        Well, (and not picking on any one in particular, so far all answers 2 have this problem) using the contains Jan works fine if we only have one years data in the db, otherwise we are going to get multiple years worth of data totalled.

                                                        (using Calm's statement as base)
                                                        $Total= mysql_result(mysql_query("SELECT SUM(total_income) AS Total FROM `db` WHERE payment_date LIKE '%Jan%' and payment_date like'2007'"),0);

                                                        However, it would be better to store the date in a proper date field and be able to hit it with a between function.
                                                        All cookies cleared!

                                                        Comment

                                                        • sarettah
                                                          see you later, I'm gone
                                                          • Oct 2002
                                                          • 14346

                                                          #29
                                                          Originally posted by Jamie
                                                          Real dev's don't have time for this bullshit
                                                          Well, at 4 in the morning I do. lololol.

                                                          Just woke up, time for coffee.
                                                          All cookies cleared!

                                                          Comment

                                                          • aico
                                                            Moo Moo Cow
                                                            • Mar 2004
                                                            • 14748

                                                            #30
                                                            Hello World

                                                            Comment

                                                            • Natural Cause
                                                              Confirmed User
                                                              • Oct 2006
                                                              • 222

                                                              #31
                                                              SELECT SUM(TotalPrice) AS [TotalPrice], COUNT(OrderID) AS [Sales], MONTH([Date]) AS [Month], YEAR([Date]) AS [Year]
                                                              FROM [Order]
                                                              WHERE OrderStatusID = 4 -- Complete
                                                              GROUP BY Month([Date]), YEAR([Date])

                                                              I just wrote that, nice and simple and it tells me how much ive made for each month of each year

                                                              Comment

                                                              • calmlikeabomb
                                                                Confirmed User
                                                                • May 2004
                                                                • 1323

                                                                #32
                                                                Originally posted by sarettah
                                                                However, it would be better to store the date in a proper date field and be able to hit it with a between function.

                                                                Duh, but he is a newbie! He gets what he asks for

                                                                You're right though - he should be using a date, datetime or int data type storing time();
                                                                subarus.

                                                                Comment

                                                                • Klen
                                                                  • Aug 2006
                                                                  • 32234

                                                                  #33
                                                                  When i need to found out something about php then i got php forums,i always found answer about php there.

                                                                  Comment

                                                                  • RawAlex
                                                                    So Fucking Banned
                                                                    • Oct 2003
                                                                    • 9465

                                                                    #34
                                                                    I would also recommend you get a decent PHP manual... I have an older one here from SAMS that is pretty good, there are any number of decent PHP references with examples out there. The PHP website is quite good too, although sometimes a little less than encouraging!

                                                                    Comment

                                                                    • hjnet
                                                                      Confirmed User
                                                                      • May 2002
                                                                      • 3815

                                                                      #35
                                                                      For the small chance that all the "blah"s are the same value you can also use

                                                                      <?php
                                                                      if ($item_title == "blah")
                                                                      {
                                                                      $R_Qty_1 = $R_Item_1 = $R_Qty_2 = $R_Item_2 = $R_Qty_3 = $R_Item_3 = "blah";
                                                                      }
                                                                      ?>

                                                                      (Correct me if I'm wrong)
                                                                      Last edited by hjnet; 01-24-2007, 09:06 AM.

                                                                      Comment

                                                                      • calmlikeabomb
                                                                        Confirmed User
                                                                        • May 2004
                                                                        • 1323

                                                                        #36
                                                                        There is no such thing as a single right answer in programming.

                                                                        It's all about semantics and pragmatism : - )
                                                                        subarus.

                                                                        Comment

                                                                        Working...