Jump to content

bschultz

Members
  • Posts

    486
  • Joined

  • Last visited

Everything posted by bschultz

  1. I should add that eventually, I'll need to add file uploads (which isn't hard)...and adding to / editing the text file once new pics are added. So, when you load the "edit" file for photo descriptions, it will need to keep the value that's already added for that file name.
  2. I found a photo slideshow script at http://www.zinkwazi.com/wp/scripts/. If I want photo descriptions, I have to create a text file with the following format: I would like to create that text file on the fly. I can read all image files in the directory with this... <?php $dir = opendir ("/my/directory/here"); while (false !== ($file = readdir($dir))) { if (strpos($file, '.gif',1)||strpos($file, '.jpg',1)||strpos($file, '.JPG',1) ) { echo "$file <br />"; } } ?> I also know how to write to a text file...but how can I take the file name garnered from the above code...and create a form with an editable description that can be added? I tried echo "$file[0] <br />"; echo "$file[1] <br />"; But it echoed this... s c s c b l Thanks!
  3. I should also ask what's the best layout of the database? I currently have a table for registration, and a separate table for miles each week. Should I add a table for team names?
  4. The local hospital in town has started a "wellness challenge"...where they want people to form a team of co-workers or friends and collectively, the goal is to walk 100,000 miles this summer. They want a website that will allow people to register, post their miles each week (only team captains can enter mile), and calculate how many miles have been walked (average) by each team member. All of this is working...except for the registration part. I currently have a drop box with team names and their captain's name (in case walkers don't know their team name...but only who their captain is). I also have a spot for "OTHER". I then log into phpmyadmin a couple times a day and "fix" all the others, and add the new teams to the drop box. This way, all team names are typed correctly...etc. Sometimes, the team member (not the captain) registers BEFORE the captain does...so I can't just have the php write the team info to the drop box when the captain registers. What's the best way to handle this problem?
  5. riwan, that worked great! Thank you. What did adding those extra slashes do? I always like to learn!
  6. I'm trying to write some variable values to a separate file. That separate file will be used in an include on a third file. File1 is a simple html form File2 processes that form, and writes the data to File3 File4 reads the variables from File3 and compares them to a database...and prints out the results. File1, File3 and File4 all work fine. File2 (which uses fwrite) isn't writing the variable name to the file. Here's the code: <?php $myFile = "testFile.php"; $fh = fopen($myFile, 'w') or die("can't open file"); $stringData = " <?php \n\n $your_page_title = \"$_POST[your_page_title]\";\n $your_number_color = \"$_POST[your_number_color]\";\n $your_position_color = \"$_POST[your_position_color]\";\n $your_name_size = \"$_POST[your_name_size]px\";\n $your_stats_color = \"$_POST[your_stats_color]\";\n ?> "; fwrite($fh, $stringData); fclose($fh); ?> The above code writes this to the file As you can see, none of the variable names are written to the file. It should read this How can I get the variable names to be written to the file? Thanks.
  7. post removed by me...the dumbie!
  8. I have the following code...which works...but I'd like to check it so that the user can't type in anything they like...and create errors. The code below will set a variable in a php calendar. Obviously, I need $thismonth and $thisyear to be 01-12 and and valid year respectively. Is there a way to check this, so that only months and years will be accepted? Thanks! <?php //BEGIN MONTH ISSET if(isset($_GET['thismonth'])) { $thismonth = $_GET['thismonth']; } elseif(!isset($_GET['thismonth'])) { $thismonth = date('m'); } //BEGIN YEAR ISSET if(isset($_GET['thisyear'])) { $thisyear = $_GET['thisyear']; } elseif(!isset($_GET['thisyear'])) { $thisyear = date('Y'); } echo "$thismonth<br />$thisyear"; ?>
  9. That did it...thanks to everyone!
  10. There is no column de1...that variable is defined in a "config" file that is "required" earlier in the page. It's defined as "99"...the jersey number of the player playing that position. In the database, the column "number" will match "99"...as the select statement says.
  11. Upon further testing...I think I've made this harder than it needs to be. This code works...sort of... <?php function football_table($position){ $dbc = mysql_connect('localhost', 'xxx', 'xxx'); mysql_select_db('briansch_2009fb',$dbc); $sql = " SELECT * FROM bschultz_own WHERE number = '99'"; $rs = mysql_query($sql,$dbc); if (!$rs) { echo "Could not successfully run query ($sql) from DB: " . mysql_error(); exit; } if (mysql_num_rows($rs) == 0) { echo "No rows found, nothing to print so am exiting"; exit; } $matches = 0; while ($row = mysql_fetch_assoc($rs)) { $matches++; print "<table border='0'><tr><div class='position'>$dend_left</div></tr><tr>"; print "<td class='number'>$row[number]</td><td><div class='name'>$row[name]</div><div class='height'>$row[height], $row[weight] - $row[year]<br />$row[city] $row[state] </div><div class='stats'><strong>$row[tackles] Tack - $row[tfl] TFL - $row[sack] Sacks <br /> $row[int] INT - $row[fumb] FUMB</strong></div></td></tr><tr>"; } if (! $matches) { print "<table border='0'><tr><div class='position'></div></tr><tr>"; print "<td class='number'></td><td><div class='name'></div><div class='height'></div><div class='stats'><strong></strong></div></td></tr></table><br /><br />"; } } echo "this goes before the player<br />"; echo football_table(de1); echo "this goes after the player"; ?> The function part of this works...other than at the bottom... Both of these show up BEFORE the database results. Also, if I try to change the WHERE clause to use the variable defined in the function... WHERE number = $position"; I still get the Unknown column 'de1' in 'where clause' error. Any ideas? Thanks!
  12. OK...upon looking more closely at the error, there was no db table in the query. Obviously, it's not pulling that from an include earlier in this script. So, can I use an include of a config file (for DB connection info) inside a function? If I manually enter the table name, I get this error: de1_number was defined in the select...what's going on here?
  13. OK...that was dumb. Now if I echo $sql, the query is as it should be... But, I still get this: Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource
  14. OK...this isn't working as I wanted it to... Here's some background. I have a database that is filled with football (American football) players information (jersey number, name, height, weight, etc). For several reasons...ALL INFO IS IN ONE DATABASE TABLE...and it has to stay this way. I have a config file that will list who is playing for a given day...broken down by position. It's format is such: The format above is this: $de1, $de2 and $de3 are positions on the field. The numbers 93, 48, and 1 are the players jersey numbers that will be playing for the game. I currently have this code to print out the players name, height weight and all other data from the database. <table border="0" cellspacing="0" cellpadding="0"> <tr> <td width="290"> <?php mysql_select_db('briansch_2009fb',$dbc); $sql = " SELECT * FROM (select number as de1_number, name as de1_name, pos as de1_pos, height as de1_height, weight as de1_weight, year as de1_year, city as de1_city, state as de1_state, tackles as de1_tackles, tfl as de1_tfl, sack as de1_sack, intc as de1_int, fumb as de1_fumb FROM $db_select_own WHERE number = $de1) as de1"; $rs = mysql_query($sql,$dbc); $matches = 0; while ($row = mysql_fetch_assoc($rs)) { $matches++; echo "<table border='0'><tr><div class='position'>$dend_left</div></tr><tr>"; echo "<td class='number'>$row[de1_number]</td><td><div class='name'>$row[de1_name]</div><div class='height'>$row[de1_height], $row[de1_weight] - $row[de1_year]<br />$row[de1_city] $row[de1_state] </div><div class='stats'><strong>$row[de1_tackles] Tack - $row[de1_tfl] TFL - $row[de1_sack] Sacks <br /> $row[de1_int] INT - $row[de1_fumb] FUMB</strong></div></td></tr><tr>"; } if (! $matches) { echo "<table border='0'><tr><div class='position'></div></tr><tr>"; echo "<td class='number'></td><td><div class='name'></div><div class='height'></div><div class='stats'><strong></strong></div></td></tr></table>"; } ?> <?php mysql_select_db('briansch_2009fb',$dbc); $sql = " SELECT * FROM (select number as de2_number, name as de2_name, pos as de2_pos, height as de2_height, weight as de2_weight, year as de2_year, city as de2_city, state as de2_state, tackles as de2_tackles, tfl as de2_tfl, sack as de2_sack, intc as de2_int, fumb as de2_fumb FROM $db_select_own WHERE number = $de2) as de2"; $rs = mysql_query($sql,$dbc); $matches = 0; while ($row = mysql_fetch_assoc($rs)) { $matches++; echo "<td class='number'>$row[de2_number]</td><td><div class='name'>$row[de2_name]</div><div class='height'>$row[de2_height], $row[de2_weight] - $row[de2_year]<br />$row[de2_city] $row[de2_state] </div><div class='stats'><strong>$row[de2_tackles] Tack - $row[de2_tfl] TFL - $row[de2_sack] Sacks <br /> $row[de2_int] INT - $row[de2_fumb] FUMB</strong></div></td></tr><tr>"; } if (! $matches) { echo "<table border='0'><tr><div class='position'></div></tr><tr>"; echo "<td class='number'></td><td height='60'><div class='name'></div><div class='height'></div><div class='stats'><strong></strong></div></td></tr></table>"; } ?> <?php mysql_select_db('briansch_2009fb',$dbc); $sql = " SELECT * FROM (select number as de3_number, name as de3_name, pos as de3_pos, height as de3_height, weight as de3_weight, year as de3_year, city as de3_city, state as de3_state, tackles as de3_tackles, tfl as de3_tfl, sack as de3_sack, intc as de3_int, fumb as de3_fumb FROM $db_select_own WHERE number = $de3) as de3"; $rs = mysql_query($sql,$dbc); $matches = 0; while ($row = mysql_fetch_assoc($rs)) { $matches++; echo "<td class='number'>$row[de3_number]</td><td><div class='name'>$row[de3_name]</div><div class='height'>$row[de3_height], $row[de3_weight] - $row[de3_year]<br />$row[de3_city] $row[de3_state] </div><div class='stats'><strong>$row[de3_tackles] Tack - $row[de3_tfl] TFL - $row[de3_sack] Sacks <br /> $row[de3_int] INT - $row[de3_fumb] FUMB</strong></div></td></tr></table>"; } if (! $matches) { echo "<table border='0'><tr><div class='position'></div></tr><tr>"; echo "<td class='number'></td><td><div class='name'></div><div class='height'></div><div class='stats'><strong></strong></div></td></tr></table>"; } ?> </td> I'd like to simplify this by creating a function...and then just calling the function once per position on the field. I tried this: <?php function football_table($postion){ $pos_number = $position . "_number"; $pos_name = $position . "_name"; $pos_pos = $position . "_pos"; $pos_height = $position . "_height"; $pos_weight = $position . "_weight"; $pos_year = $position . "_year"; $pos_city = $position . "_city"; $pos_state = $position . "_state"; $pos_tackles = $position . "_tackles"; $pos_tfl = $position . "_tfl"; $pos_sack = $position . "_sack"; $pos_int = $position . "_int"; $pos_fumb = $position . "_fumb"; $dbc = mysql_connect('localhost', 'xxx', 'xxx'); mysql_select_db('briansch_2009fb',$dbc); $sql = " SELECT * FROM (select number as $pos_number, name as $pos_name, pos as $pos_pos, height as $pos_height, weight as $pos_weight, year as $pos_year, city as $pos_city, state as $pos_state, tackles as $pos_tackles, tfl as $pos_tfl, sack as $pos_sack, intc as $pos_int, fumb as $pos_fumb FROM $db_select_own WHERE number = $position) as $position"; $rs = mysql_query($sql,$dbc); $matches = 0; while ($row = mysql_fetch_assoc($rs)) { $matches++; print "<table border='0'><tr><div class='position'>$dend_left</div></tr><tr>"; print "<td class='number'>$row[$pos_number]</td><td><div class='name'>$row[$pos_name]</div><div class='height'>$row[$pos_height], $row[$pos_weight] - $row[$pos_year]<br />$row[$pos_city] $row[$pos_state] </div><div class='stats'><strong>$row[$pos_tackles] Tack - $row[$pos_tfl] TFL - $row[$pos_sack] Sacks <br /> $row[$pos_int] INT - $row[$pos_fumb] FUMB</strong></div></td></tr><tr>"; } if (! $matches) { print "<table border='0'><tr><div class='position'></div></tr><tr>"; print "<td class='number'></td><td><div class='name'></div><div class='height'></div><div class='stats'><strong></strong></div></td></tr></table>"; } } echo football_table(de1); echo football_table(de2); echo football_table(de3); ?> The problems that I'm having are: - If I echo $sql, the position de1 isn't being included in the echo...so I'm obviously doing something wrong in my defining of the variable. - If I add in the de1 manually, I still get an error Any ideas? Thanks!!!!!
  15. This is going inside a function...and I'll need to print out ten different rows.... Is there any way to do it once...or will I have to come up with ten different "keys"?
  16. I need to add a variable to a mysql row... so...below, $position is the variable...then an underscore and then "number" $row[$position_number] I've tried this $row[$position'.'_number] and I get this... Any ideas on how to concatenate these two?
  17. That did it...thanks!
  18. Right...but that prints everybody in one line. I want no more than eight in each line.
  19. I need to figure out a way to count the number of items in an array (which is easy)...and then echo the results in an ordered fashion. I only want 8 results to show up per line. I'm sure it's some form of for loop, but I don't know where to start. This works...but it can't be the best way....plus what if I add more names to the array...??? <?php $count = count($umpires); if ($count <= echo "<a href = 'schedule_names.php?name=$umpires'>$umpires</a> "; elseif ($count >= 9) echo "<a href = 'schedule_names.php?name=$umpires[0]'>$umpires[0]</a> <a href = 'schedule_names.php?name=$umpires[1]'>$umpires[1]</a> <a href = 'schedule_names.php?name=$umpires[2]'>$umpires[2]</a> <a href = 'schedule_names.php?name=$umpires[3]'>$umpires[3]</a> <a href = 'schedule_names.php?name=$umpires[4]'>$umpires[4]</a> <a href = 'schedule_names.php?name=$umpires[5]'>$umpires[5]</a> <a href = 'schedule_names.php?name=$umpires[6]'>$umpires[6]</a> <a href = 'schedule_names.php?name=$umpires[7]'>$umpires[7]</a> <a href = 'schedule_names.php?name=$umpires[8]'>$umpires[8]</a> <br /><br /> <a href = 'schedule_names.php?name=$umpires[9]'>$umpires[9]</a> <a href = 'schedule_names.php?name=$umpires[10]'>$umpires[10]</a> <a href = 'schedule_names.php?name=$umpires[11]'>$umpires[11]</a> <a href = 'schedule_names.php?name=$umpires[12]'>$umpires[12]</a> <a href = 'schedule_names.php?name=$umpires[13]'>$umpires[13]</a> <a href = 'schedule_names.php?name=$umpires[14]'>$umpires[14]</a> <a href = 'schedule_names.php?name=$umpires[15]'>$umpires[15]</a> <a href = 'schedule_names.php?name=$umpires[16]'>$umpires[16]</a> <br /><br /> <a href = 'schedule_names.php?name=$umpires[17]'>$umpires[17]</a> <a href = 'schedule_names.php?name=$umpires[18]'>$umpires[18]</a> <a href = 'schedule_names.php?name=$umpires[19]'>$umpires[19]</a> "; ?>
  20. Man, I hate dates in PHP! Worked great...thanks Ken!
  21. Great...that worked. Now, once I get to that link, the month and year variables will be passed in a $_GET fashion. I've tried this: <?php $thismonth = $_GET['thismonth']; $thisyear = $_GET['thisyear']; $last_month = date('m', strtotime('-1 month', strtotime($thismonth)); $last_year = date('Y', strtotime('-1 month', strtotime($thismonth)); $next_month = date('m', strtotime('+1 month', strtotime($thismonth)); $next_year = date('Y', strtotime('+1 month', strtotime($thismonth)); ?> This gives me a $_GET['thismonth'] will give an integer (May is "05")...is that what's throwing this off? How would I fix this? Thanks!
  22. How do I work that into the link though?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.