You are not logged in. Join Free! | Log In Thank you!    

Welcome to your Green Bay Packers Online Community!

Since 2006, PackersHome has been providing a unique experience for fans.
Your participation is greatly anticipated!
Login or Register.

Notification

Icon
Error

7 Pages«<34567>
Share
Options
View
Go to last post Go to first unread
Offline Zero2Cool  
#61 Posted : Monday, September 21, 2009 12:17:51 AM(UTC)
Zero2Cool

Rank: Legend

United States
Posts: 25,225
Joined: 10/13/2006(UTC)
Location: Green Bay, WI

Applause Given: 1,739
Applause Received: 1,790

I'd like to use an array.

The array would be declared like this...
$varArray(0 to 16, 2)



$varArray(x, 1) = $strGame
$varArray(x, 2) = $strSelection

Then I'd use a for loop to go through each and send each to the db. There's more to this, obviously, but is this possible with PHP?

UserPostedImage
Click here and find the LATEST Packers News!
Offline Zero2Cool  
#62 Posted : Monday, September 21, 2009 12:59:23 AM(UTC)
Zero2Cool

Rank: Legend

United States
Posts: 25,225
Joined: 10/13/2006(UTC)
Location: Green Bay, WI

Applause Given: 1,739
Applause Received: 1,790

I hate PHP. Hate.

UserPostedImage
Click here and find the LATEST Packers News!
Offline dhpackr  
#63 Posted : Monday, September 21, 2009 9:02:37 AM(UTC)
dhpackr

Rank: 4th Round Draft Pick

Posts: 963
Joined: 12/12/2007(UTC)

Applause Given: 36
Applause Received: 36

Zero,
as far as using an array, the best way to use an array would be to populate a drop down list. radio buttons and drop down lists kind of work in the same manner.

you can give the end user many choices, but only one selection will be processed.

do not make it harder than you have to. using radio buttons will work fine, you'll just need 16 variables.

the code I posted will work for you. if you want to show the selection in a db instead of a 1 or 0, maybe use a drop down list instead. like this

&lt;tr&gt;
&lt;td&gt;02&lt;/td&gt;
&lt;td&gt;
&lt;?----start php

$01s = array("Packers","Bengals");

if (empty($01s[0])) {
echo '&lt;input type="text" name="01" class="textbox" value="' . $01. '" maxlength="255" /&gt;' . "\n";
}
else {
?>
&lt;select name="01" class="textbox"&gt;
&lt;option value=""&gt;-- please select --&lt;/option&gt;
&lt;?
// Print out position options
for ($i = 0; $i &lt; count($01s); $i++) {
echo '&lt;option value="' . $01s[$i] . '"';
if($01s[$i]==$01){echo " selected ";}
echo "&gt;" . $01s[$i] . "&lt;/option&gt; \n";
}
?>
&lt;/select&gt;
&lt;?
}
?&gt;
&lt;/td&gt;
&lt;/tr&gt;
So if you meet me Have some courtesy, Have some sympathy, and some taste
Use all your well-learned politesse, Or I'll lay your soul to waste
Offline dhpackr  
#64 Posted : Monday, September 21, 2009 9:59:20 AM(UTC)
dhpackr

Rank: 4th Round Draft Pick

Posts: 963
Joined: 12/12/2007(UTC)

Applause Given: 36
Applause Received: 36

Originally Posted by: " Go to Quoted Post
I hate PHP. Hate.


lol, what u learned in school only scratches the surface of programming. I was lucky to have worked with the guy that hired me out of school. Dude was completely insane. totally bipolar, but man did he know vb6, vb.net, classic asp, IIS, sql. he gave me a book on coldfusion, a 40 hour week and told me to create some database driven order forms. I did it.

next was classic asp, which I wish I could've stuck with. safe, secure database driven websites with nothing but notepad. I was given a 40 work week to create some database driven order forms, and I completed that project and 1 other. after that i did a financial program in vb6 and then another in vb.net that was sold for 5 grand multiple times.

that was in my first 6 months of work. then came ektron and vb.net. i did that and was getting really good with vb.net for bout the next 9 months when i was laid off. i really think a senior programmer got a little nervous about how I was attacking all my projects and pulled the cord on my job to try and save his.

but a month after i got laid off i got this part time php gig. no experience in php, no training, just cut loose on live web forms, and service tickets.

just stick with it and you will get it. just remember, you may be editing as many as 3-4 files and several functions in each file every time you try and add something or change something.

this program will take some maintenance, which is why I am interested. I could always use another job reference, and would be willing to write some code for you.

if you decide to whip it yourself, cool, i wish you the best.
lol, little different than vb.net and using datagrids, which BTW, I may have some Ektron opportunities coming up.

you'll be fine. put the code i gave you in the file you sent me. that file you sent to me, that is what I would consider a "TEMPLATE" file.

the validation code would go in a class file.
So if you meet me Have some courtesy, Have some sympathy, and some taste
Use all your well-learned politesse, Or I'll lay your soul to waste
Offline Zero2Cool  
#65 Posted : Monday, September 21, 2009 10:05:09 AM(UTC)
Zero2Cool

Rank: Legend

United States
Posts: 25,225
Joined: 10/13/2006(UTC)
Location: Green Bay, WI

Applause Given: 1,739
Applause Received: 1,790

Why is everything so freaking complicated in PHP?

in VB ... piece of cake!

Code:
'declare array
Public strMaster(0 To 4000, 3) As String

'increment index
x = x + 1

'fill array
strMaster(x, 1) = strGrame
strMaster(x, 2) = strSelection


'and to pull the data out
For i As Integer = 0 To x
strSendGame = strMaster(i, 1)
strSendSelection = strMaster(i, 2)
'do work here to send each game number and selection to db
Next x



Now why can't I do that with PHP? From what I've seen of it, PHP is a very tool enriched language but how do you increment the darn index of the array dynamically?

UserPostedImage
Click here and find the LATEST Packers News!
Offline Zero2Cool  
#66 Posted : Monday, September 21, 2009 10:10:32 AM(UTC)
Zero2Cool

Rank: Legend

United States
Posts: 25,225
Joined: 10/13/2006(UTC)
Location: Green Bay, WI

Applause Given: 1,739
Applause Received: 1,790

Originally Posted by: " Go to Quoted Post
Originally Posted by: " Go to Quoted Post
I hate PHP. Hate.


lol, what u learned in school only scratches the surface of programming. I was lucky to have worked with the guy that hired me out of school. Dude was completely insane. totally bipolar, but man did he know vb6, vb.net, classic asp, IIS, sql. he gave me a book on coldfusion, a 40 hour week and told me to create some database driven order forms. I did it.

next was classic asp, which I wish I could've stuck with. safe, secure database driven websites with nothing but notepad. I was given a 40 work week to create some database driven order forms, and I completed that project and 1 other. after that i did a financial program in vb6 and then another in vb.net that was sold for 5 grand multiple times.

that was in my first 6 months of work. then came ektron and vb.net. i did that and was getting really good with vb.net for bout the next 9 months when i was laid off. i really think a senior programmer got a little nervous about how I was attacking all my projects and pulled the cord on my job to try and save his.

but a month after i got laid off i got this part time php gig. no experience in php, no training, just cut loose on live web forms, and service tickets.

just stick with it and you will get it. just remember, you may be editing as many as 3-4 files and several functions in each file every time you try and add something or change something.

this program will take some maintenance, which is why I am interested. I could always use another job reference, and would be willing to write some code for you.

if you decide to whip it yourself, cool, i wish you the best.
lol, little different than vb.net and using datagrids, which BTW, I may have some Ektron opportunities coming up.

you'll be fine. put the code i gave you in the file you sent me. that file you sent to me, that is what I would consider a "TEMPLATE" file.

the validation code would go in a class file.


It's so freaking frustrating! Everything I've learned with programming, doesn't work with PHP!! I can't even figure out how to increment the index of a flipping two dimensional array.

Another reason I like VB, the IDE can be used as a tool with intellisense. I'm not so lucky with PHP, even dreamweaver is no help, lol.


I did try the code you gave me and it didn't work. It was sending '0' or '1' and if it wasn't checked, it did do anything. Not sure how I screwed it up, but I must have somewhere along the lines.

If I have to make a 16 Week##.php files, I'm down with that. But I need one to work first in the scope I'm aiming for.

I thought once I had the link issue resolved it'd be a snap because all languages use arrays in a similar fashion. WRONG! lol

UserPostedImage
Click here and find the LATEST Packers News!
Offline dhpackr  
#67 Posted : Monday, September 21, 2009 10:21:56 AM(UTC)
dhpackr

Rank: 4th Round Draft Pick

Posts: 963
Joined: 12/12/2007(UTC)

Applause Given: 36
Applause Received: 36

Originally Posted by: " Go to Quoted Post
Why is everything so freaking complicated in PHP?

in VB ... piece of cake!

Code:
'declare array
Public strMaster(0 To 4000, 3) As String

'increment index
x = x + 1

'fill array
strMaster(x, 1) = strGrame
strMaster(x, 2) = strSelection


'and to pull the data out
For i As Integer = 0 To x
strSendGame = strMaster(i, 1)
strSendSelection = strMaster(i, 2)
'do work here to send each game number and selection to db
Next x



Now why can't I do that with PHP? From what I've seen of it, PHP is a very tool enriched language but how do you increment the darn index of the array dynamically?


like this
for ($i = 0; $i &lt; count($01s); $i++) {
echo '&lt;option value="' . $01s[$i] . '"';
if($01s[$i]==$01){echo " selected ";}
echo "&gt;" . $01s[$i] . "&lt;/option&gt; \n";
So if you meet me Have some courtesy, Have some sympathy, and some taste
Use all your well-learned politesse, Or I'll lay your soul to waste
Offline dhpackr  
#68 Posted : Monday, September 21, 2009 10:36:41 AM(UTC)
dhpackr

Rank: 4th Round Draft Pick

Posts: 963
Joined: 12/12/2007(UTC)

Applause Given: 36
Applause Received: 36

Originally Posted by: " Go to Quoted Post


I did try the code you gave me and it didn't work. It was sending '0' or '1' and if it wasn't checked, it did do anything. Not sure how I screwed it up, but I must have somewhere along the lines.



ok, that is what a radio button will do. if it is checked, you will see a 1 in the database. if not a 0 will appear. then you need to add that validation function so the user has to make a selection. Next you can write a function to display the users picks on a web page. just copy and paste the code into another file to display the selection.

if you want to see the selection in the database, i would suggest using a drop down list, populate with an array and then recycle this code 15 times with different variables and different arrays.

here is two picks


&lt;tr&gt;
&lt;td &gt;Pick1&lt;/td&gt;
&lt;td&gt;
&lt;?

$01s = array("Packers","Bengals");

if (empty($01s[0])) {
echo '&lt;input type="text" name="01" class="textbox" value="' . $01. '" maxlength="255" /&gt;' . "\n";
}
else {
?>
&lt;select name="01" class="textbox"&gt;
&lt;option value=""&gt;-- please select --&lt;/option&gt;
&lt;?
// Print out position options
for ($i = 0; $i &lt; count($01s); $i++) {
echo '&lt;option value="' . $01s[$i] . '"';
if($01s[$i]==$01){echo " selected ";}
echo "&gt;" . $01s[$i] . "&lt;/option&gt; \n";
}
?>
&lt;/select&gt;
&lt;?
}
?&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td &gt;Pick2&lt;/td&gt;
&lt;td&gt;
&lt;?

$02s = array("Vikings","Lions");

if (empty($02s[0])) {
echo '&lt;input type="text" name="02" class="textbox" value="' . $02. '" maxlength="255" /&gt;' . "\n";
}
else {
?>
&lt;select name="02" class="textbox"&gt;
&lt;option value=""&gt;-- please select --&lt;/option&gt;
&lt;?
// Print out position options
for ($i = 0; $i &lt; count($02s); $i++) {
echo '&lt;option value="' . $02s[$i] . '"';
if($02s[$i]==$02){echo " selected ";}
echo "&gt;" . $02s[$i] . "&lt;/option&gt; \n";
}
?>
&lt;/select&gt;
&lt;?
}
?&gt;
&lt;/td&gt;
&lt;/tr&gt;


like i wrote, if you want the actual selection text to show up in the database, use a dropdownlist.

a radio button will display a 1 or 0 in the database, not the text, so i think my code worked properly.
So if you meet me Have some courtesy, Have some sympathy, and some taste
Use all your well-learned politesse, Or I'll lay your soul to waste
Offline Zero2Cool  
#69 Posted : Monday, September 21, 2009 10:57:36 AM(UTC)
Zero2Cool

Rank: Legend

United States
Posts: 25,225
Joined: 10/13/2006(UTC)
Location: Green Bay, WI

Applause Given: 1,739
Applause Received: 1,790

Originally Posted by: " Go to Quoted Post
like this
[php]
for ($i = 0; $i &lt; count($01s); $i++) {
echo '&lt;option value="' . $01s[$i] . '"';
if($01s[$i]==$01){echo " selected ";}
echo "&gt;" . $01s[$i] . "&lt;/option&gt; \n";
[/php]



That is way over my head and doesn't look remotely close to what I posted (which makes sense cuz mine was in .NET), lol.

Isn't there a curly bracket missing in there? I see two open and only one close?

UserPostedImage
Click here and find the LATEST Packers News!
Offline Zero2Cool  
#70 Posted : Monday, September 21, 2009 11:28:15 AM(UTC)
Zero2Cool

Rank: Legend

United States
Posts: 25,225
Joined: 10/13/2006(UTC)
Location: Green Bay, WI

Applause Given: 1,739
Applause Received: 1,790

[php]$int = 0;
// see if the GET variable "picks" is set
if(isset($_GET["picks"]))
{
// if picks is equal to "yes" proceed
if($_GET["picks"] == "yes")
{
echo "&lt;strong&gt;You picked the following winners:&lt;/strong&gt;&lt;br /&gt;";
// if variable $x is less than the total number of games, add 1 to $x
for($x = 0; $x &lt;= 16; $x++)
{
// check games
if($x &lt; 10)
{
$x = "0" . $x . "";
}
if(isset($_POST["rdoGame" . $x . ""]))
{
// do whatever you want with each game right here
if($x != "1") {echo " ";}
//echo $_POST["rdoGame" . $x . ""] . "";
$strMember = $nick;
$strWeek = "01";
$strGame = $x;
$strSelection = $_POST["rdoGame" . $x . ""] . "";
$strTimeStamp = date("Ymd : His");
$int++;
echo $int . " number.";
$varSelection[$int] = array_fill($x, $strSelection);
}
}
echo $varSelection[0][0] . " - " . $varSelection[0][1] . "&lt;br&gt;";
echo $varSelection[1][0] . " - " . $varSelection[1][1] . "&lt;br&gt;";
echo $varSelection[2][0] . " - " . $varSelection[2][1] . "&lt;br&gt;";

echo "&lt;br /&gt;&lt;br /&gt;";
mysql_close($conMySQL);
}
}[/php]


See the mess I've created? lol

If I make three selections, the three 'echo' at the bottom there should show those three selections as ...

01 - Steelers
02 - Dolphins
03 - Broncos


But for some sweet reason, the array's index is not incrementing.

UserPostedImage
Click here and find the LATEST Packers News!
Offline dhpackr  
#71 Posted : Monday, September 21, 2009 2:03:15 PM(UTC)
dhpackr

Rank: 4th Round Draft Pick

Posts: 963
Joined: 12/12/2007(UTC)

Applause Given: 36
Applause Received: 36

try using the code i posted for a drop down list
So if you meet me Have some courtesy, Have some sympathy, and some taste
Use all your well-learned politesse, Or I'll lay your soul to waste
Offline Zero2Cool  
#72 Posted : Monday, September 21, 2009 2:17:47 PM(UTC)
Zero2Cool

Rank: Legend

United States
Posts: 25,225
Joined: 10/13/2006(UTC)
Location: Green Bay, WI

Applause Given: 1,739
Applause Received: 1,790

Originally Posted by: " Go to Quoted Post
try using the code i posted for a drop down list


I tried, but it's over my head. I don't understand the variables. They have no real meaning. i, i02? That's confusing to simple minded folk like me. Remember, I'm a VB programmer, I need pictures!!! lol


Drop Down List won't work too great. If you scroll you could inadvertently select a different team. That's why I went with radio buttons.

UserPostedImage
Click here and find the LATEST Packers News!
Offline dhpackr  
#73 Posted : Monday, September 21, 2009 3:15:41 PM(UTC)
dhpackr

Rank: 4th Round Draft Pick

Posts: 963
Joined: 12/12/2007(UTC)

Applause Given: 36
Applause Received: 36

Originally Posted by: " Go to Quoted Post


I don't understand the variables. They have no real meaning. i, i02? That's confusing to simple minded folk like me. Remember, I'm a VB programmer, I need pictures!!! lol


Drop Down List won't work too great. If you scroll you could inadvertently select a different team. That's why I went with radio buttons.


remember, if u choose a radio button, all that will show up in ur database is a 1 or 0

let's break this down
***********************************************************
1st pick a drop down list where the user either picks packers or bengals
&lt;?-----start php script

$01s = array("Packers","Bengals"); //here i am populating an array
//this is an array for a game.
//only two teams in this list are the packers and bengals
if (empty($01s[0])) {
echo '&lt;input type="text" name="01" class="textbox" value="' . $01. '" maxlength="255" /&gt;' . "\n";
}
else {
?>
&lt;select name="01" class="textbox"&gt;
&lt;option value=""&gt;-- please select --&lt;/option&gt;
&lt;?
// Print out position options
for ($i = 0; $i &lt; count($01s); $i++) {
echo '&lt;option value="' . $01s[$i] . '"';
if($01s[$i]==$01){echo " selected ";}
echo "&gt;" . $01s[$i] . "&lt;/option&gt; \n";
}
?>

************************************************************

2nd pick a drop down list where the user either picks Vikings or Lions
&lt;?-----start php script

$02s = array("Vikings","Lions"); //here i am populating an array
//this is an array for a different game.
//only two teams in this list are the Vikings and lions
if (empty($02s[0])) {
echo '&lt;input type="text" name="02" class="textbox" value="' . $02. '" maxlength="255" /&gt;' . "\n";
}
else {
?>
&lt;select name="02" class="textbox"&gt;
&lt;option value=""&gt;-- please select --&lt;/option&gt;
&lt;?
// Print out position options
for ($i = 0; $i &lt; count($02s); $i++) {
echo '&lt;option value="' . $02s[$i] . '"';
if($02s[$i]==$02){echo " selected ";}
echo "&gt;" . $02s[$i] . "&lt;/option&gt; \n";
}
?>

*************************************************************
so now i have two drop down lists for two different games. this code will go into my template file. it doesn't matter what u call the variable. I used 01 and 02, you can use whatever you wish.

*************************************************************
now you want to write a function to add picks to database
function add_pick(memberid,$01=null,$02=null) {
$id = $this->get_new_id();
$values = array (
$this->memberid(), $this->01 = $01;
$this->02 = $02;
);

$query = 'INSERT INTO ' . $this->get_table('whateverthetableis') . ' VALUES(?, ?,?)';
$q = $this->db->prepare($query);
$result = $this->db->execute($q, $values);
$this->check_for_error($result);

unset($values, $query);
return $id;
}
*************************************************************

modify the picks

function mod_pick() {
$values = array (

$res->get_01(),
$res->get_02()
);

$query = 'UPDATE ' . $this->get_table('whateverthetableis')

. ' 01=?,'
. ' 02=?,'


$q = $this->db->prepare($query);
$result = $this->db->execute($q, $values);
$this->check_for_error($result);

unset($values, $query);
}
*************************************************************
So if you meet me Have some courtesy, Have some sympathy, and some taste
Use all your well-learned politesse, Or I'll lay your soul to waste
Offline Zero2Cool  
#74 Posted : Monday, September 21, 2009 3:44:26 PM(UTC)
Zero2Cool

Rank: Legend

United States
Posts: 25,225
Joined: 10/13/2006(UTC)
Location: Green Bay, WI

Applause Given: 1,739
Applause Received: 1,790

Originally Posted by: " Go to Quoted Post
remember, if u choose a radio button, all that will show up in ur database is a 1 or 0


[php]
&lt;input name='rdoGame14' type='radio' value='Bears' /&gt;Chicago Bears
&lt;input name='rdoGame14' type='radio' value='Packers' /&gt;Green Bay Packers
[/php]

That gives me the 'Bears' or 'Packers' for the value instead of 1 or 0. I've wrote the team names to the database.

In fact, if you go to Special Features > NFL Picks > 1 and make some selections and hit submit, it'll go to the database with the team names.

I'm using Week02 as my test dummy for validation. :)


[php] //code above scans all rdoGame values ...

$varSelection = array($int => array($x, $strSelection));

$int++;
echo $int . " number. &lt;br&gt;";
}
}
//replace this with a check to see if $int = total games for that week.
//if yes, then use a for each loop through the $varSelection array and send
//each pick to the db, one by one.
/if no, exit and alert user to make all selections.

echo $varSelection[0][0] . " - " . $varSelection[0][1] . "&lt;br&gt;";
echo $varSelection[1][0] . " - " . $varSelection[1][1] . "&lt;br&gt;";
echo $varSelection[2][0] . " - " . $varSelection[2][1] . "&lt;br&gt;";
[/php]


Basically, once I get how to increment a multidimensional array's index dynamically, I could be set to go. I have most of this all written down on how to go about it. Except the incrementation of the index in my array. It's only storing the last set of data instead of an index.

UserPostedImage
Click here and find the LATEST Packers News!
Offline Zero2Cool  
#75 Posted : Tuesday, September 22, 2009 5:49:42 PM(UTC)
Zero2Cool

Rank: Legend

United States
Posts: 25,225
Joined: 10/13/2006(UTC)
Location: Green Bay, WI

Applause Given: 1,739
Applause Received: 1,790

Woohooo!! I figured it out!! Works like a freaking champ!!

I got the array to increment the element and also figured out how to use the for each array to cycle through each element. w00t!

Now to implement the check for all games selected and finish the template.

POW!!! RIGHT IN THE KISSER
POW!!! RIGHT IN THE KISSER
POW!!! RIGHT IN THE KISSER
POW!!! RIGHT IN THE KISSER
POW!!! RIGHT IN THE KISSER
POW!!! RIGHT IN THE KISSER
POW!!! RIGHT IN THE KISSER
POW!!! RIGHT IN THE KISSER

UserPostedImage
Click here and find the LATEST Packers News!
Users browsing this topic
Guest (4)
7 Pages«<34567>
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Powered by YAF 2.1.0 | YAF © 2003-2014, Yet Another Forum.NET
This page was generated in 0.401 seconds.