GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   Attn PHP guys = Stupid $20 contest for stupid wannabe programmer (https://gfy.com/showthread.php?t=698805)

mkx 01-23-2007 10:47 PM

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

fatdicksimon 01-23-2007 10:53 PM

<?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

fatdicksimon 01-23-2007 10:54 PM

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.

martinsc 01-23-2007 10:54 PM

Quote:

Originally Posted by fatdicksimon (Post 11780257)
<?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 :winkwink:
and the blah's below should be in quotes too...

mkx 01-23-2007 10:58 PM

that should do, thanks :)

fatdicksimon = 1

fatdicksimon 01-23-2007 10:58 PM

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";
}
?>

fatdicksimon 01-23-2007 10:59 PM

Quote:

Originally Posted by martinsc (Post 11780267)
you forgot the closing quotes in the if statement :winkwink:
and the blah's below should be in quotes too...

yeah, i just caught that, thanks!

mkx 01-23-2007 11:13 PM

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.

Zoose 01-23-2007 11:25 PM

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

woj 01-23-2007 11:51 PM

wow, whole $20 for answering 20 questions? :1orglaugh

Nookster 01-23-2007 11:57 PM

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.)

mkx 01-24-2007 12:01 AM

Quote:

Originally Posted by fatdicksimon (Post 11780265)
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:

Originally Posted by Zoose (Post 11780422)
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

mkx 01-24-2007 12:06 AM

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

mkx 01-24-2007 12:09 AM

Quote:

Originally Posted by Nookster (Post 11780549)
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

jMEGA 01-24-2007 12:23 AM

$query = "SELECT SUM(total_income) FROM `db` WHERE payment_date='Jan' ORDER BY id DESC";

mkx 01-24-2007 12:27 AM

Quote:

Originally Posted by jMEGA (Post 11780632)
$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"

mkx 01-24-2007 12:45 AM

Quote:

Originally Posted by woj (Post 11780524)
wow, whole $20 for answering 20 questions? :1orglaugh

Well mr. woj, if you do the math 11 answers guarantee you the win

jMEGA 01-24-2007 12:50 AM

Quote:

Originally Posted by jMEGA (Post 11780632)
$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";

calmlikeabomb 01-24-2007 12:50 AM

Quote:

Originally Posted by mkx (Post 11780641)
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..

Quote:

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;


CyberHustler 01-24-2007 12:55 AM

<? ?> ...thats how much php I know

mkx 01-24-2007 01:02 AM

Quote:

Originally Posted by calmlikeabomb (Post 11780704)
Assuming you've got your db connection established..

winner


fatdicksimon = 1
calmlikeabomb = 1

calmlikeabomb 01-24-2007 02:09 AM

This would probably suit your first question a little nicer:

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

Quote:


<?

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.. */

?>



calmlikeabomb 01-24-2007 02:20 AM

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.

Natural Cause 01-24-2007 02:21 AM

This thread is pretty stupid.

Jamie 01-24-2007 02:24 AM

Real dev's don't have time for this bullshit

calmlikeabomb 01-24-2007 02:27 AM

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

bizarredollars 01-24-2007 03:26 AM

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

sarettah 01-24-2007 03:34 AM

Quote:

Originally Posted by calmlikeabomb (Post 11780704)
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.

sarettah 01-24-2007 03:35 AM

Quote:

Originally Posted by Jamie (Post 11780992)
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.

aico 01-24-2007 03:51 AM

Hello World

Natural Cause 01-24-2007 03:51 AM

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 :)

calmlikeabomb 01-24-2007 10:58 AM

Quote:

Originally Posted by sarettah (Post 11781209)
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 :upsidedow

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

Klen 01-24-2007 11:01 AM

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

RawAlex 01-24-2007 11:03 AM

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!

hjnet 01-24-2007 11:04 AM

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) :)

calmlikeabomb 01-24-2007 12:08 PM

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