![]() |
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 |
<?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 |
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.
|
Quote:
and the blah's below should be in quotes too... |
that should do, thanks :)
fatdicksimon = 1 |
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"; } ?> |
Quote:
|
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.
|
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 |
wow, whole $20 for answering 20 questions? :1orglaugh
|
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.)
|
Quote:
Quote:
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 |
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 |
Quote:
|
$query = "SELECT SUM(total_income) FROM `db` WHERE payment_date='Jan' ORDER BY id DESC";
|
Quote:
Payment date should *contain* "Jan" since this is how it is entered "04:55:21 Jan 19, 2007 PST" |
Quote:
|
Quote:
$query = "SELECT SUM(total_income) FROM `db` WHERE MONTH(payment_date)='01' ORDER BY id DESC"; |
Quote:
Quote:
|
<? ?> ...thats how much php I know
|
Quote:
fatdicksimon = 1 calmlikeabomb = 1 |
This would probably suit your first question a little nicer:
Again, assuming you've already got the db connection established... Quote:
|
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.
|
This thread is pretty stupid.
|
Real dev's don't have time for this bullshit
|
Keep your money. I've got time to help out - not in this thread to make any $.
|
Spend the $20 on a book.. SAMS was one of the best investments I ever made. Knowledge = Power.
|
Quote:
(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. |
Quote:
Just woke up, time for coffee. |
Hello World
|
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 :) |
Quote:
Duh, but he is a newbie! He gets what he asks for :upsidedow You're right though - he should be using a date, datetime or int data type storing time(); |
When i need to found out something about php then i got php forums,i always found answer about php there.
|
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!
|
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) :) |
There is no such thing as a single right answer in programming.
It's all about semantics and pragmatism : - ) |
| All times are GMT -7. The time now is 08:34 AM. |
Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2026, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123