Jump to content

hosker

Members
  • Posts

    57
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

hosker's Achievements

Member

Member (2/5)

0

Reputation

  1. I have a query that runs perfectly when I enter it into the SQL tab within my PHP Admin screen, but when I add my PHP to it, it does not display all the values. Here is my code: <?php $i = 1; $position = 1; while($i < 39) { $tournament_sql = "(SELECT * FROM weekly_picks, tournaments_2013, leaderboards_2013 WHERE tournaments_2013.tournament_id = leaderboards_2013.tournament_id AND weekly_picks.tournament_id = leaderboards_2013.tournament_id AND weekly_picks.player_id = leaderboards_2013.player_id AND tournaments_2013.id = '$i') ORDER BY (leaderboards_2013.player_money)DESC"; $tournament_result = mysql_query($tournament_sql); $tournament_row = mysql_fetch_assoc($tournament_result); print "<h2>" . $tournament_row['tournament'] . "</h2>"; print "<div id='picks'><table border=1><tr><th>Position</th><th>Player</th><th>Total</th></tr>"; while ($tournament_row = mysql_fetch_assoc($tournament_result)) { echo "<tr><td>" . $position . "</td><td>" . $tournament_row['user'] . "</td><td>" . $tournament_row['player_money'] . "</td></tr>"; $position++; } print "</table></div>"; $i++; $position = 1; }; ?>
  2. I am using strtotim() which I can get to work outside of my SQL query. How would I mkae this SQL statement work" $today = strtotime(date('2013-01-07')); $sql = "SELECT * FROM tournaments_2013 WHERE (strtotime('Last Monday', start_date) = $today)"; $result = mysql_query($sql); print_r($result); exit; echo "<table><tr><th>Tournament</th></tr>"; while($row = mysql_fetch_array($result)) { echo "<tr><td>" . $row['tournament_id'] . "</td></tr>"; } echo "</table>";
  3. I have searched the forum, but I did not finda post that would help me with my issue. I have a cron job that I am going to run every monday, however, I do not want to type out all of the dates into an if else statement, but would rather write it in a loop. I want to pull the date from the database table, which is always going to be a Thursday( and an ocassional Wednesday), and check to see if the Monday prior is todays date, and if it is, I want to pull the file tournament_id from my database and insert it into a variable. How can this be done? The date is in the following format: YYYY-MM-DD. Thanks in advance for your help.
  4. Okay, so global is a bad way to go. ANy thoughts on how I can make it work using the global variable format for now?
  5. I have a form I created that writs to a text file. I have a variable issue. Basically, I need to know where to put this variable so that when the page loads it is empty and when the forms is filled out and submitted the variable is filled with a text string. Below is my code <?php //include files include_once('classes/Validation.php'); //initiate object of the validation class $Validation = new Validation(); //array that will store the error messages $errorArray = array(); if (isset($_POST['submit'])){ validate(); } global $added; $added = " "; function validate() { //anything created outside the function must be global to be used inside a function. //or passed via the parameter. Also any variables created inside the function that are //set as global can be used outside the function. global $errorArray; global $Validation; //This checks the entry and if there is an error puts the message into the errorArray $errorArray[0] = $Validation->checkForBlanks($_POST['fname']); $errorArray[1] = $Validation->checkForBlanks($_POST['lname']); $errorArray[2] = $Validation->checkForBlanks($_POST['pnumber']); $errorArray[3] = $Validation->checkForBlanks($_POST['email']); /* * This does a final check for errors if none are found it will write the form values to a text file, clear the $_POST variables and * fill in a variable to alert the user the form was submitted correctly. */ if (!$Validation->checkErrors()){ $file = fopen("content.txt","a") or die("Cannot Open File"); $formdata = $_POST['fname'] . ',' . $_POST['lname'] . ',' . $_POST['pnumber'] . ',' . $_POST['email'] . "\n"; fwrite($file,$formdata); fclose($file); $_POST['fname'] = ""; $_POST['lname'] = ""; $_POST['pnumber'] = ""; $_POST['email'] = ""; return $added = "<p>Contact has been added<p>"; } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> <link rel="stylesheet" type="text/css" href="css/project1.css" /> </head> <body> <div id="project1-wrapper"> <div id="project1-header"> <h2>INP 271<br /> PHP Web Site</h2> </div> <div id="project1-menu"> <ul> <li><a href="index.php" title="Home">Home</a></li> <li><a href="add-contact.php" title="Add Contact">Add Contact</a></li> <li><a href="view-contacts.php" title="View Contacts">View Contacts</a></li> </ul> </div> <div id="project1-form"> <h2>Add Contact</h2> <?php echo $added; ?> <form method="post" action="" > <!-- When this form is submitted, but now all fields hold a value, the form will display error messages next to the label that is not filled in. Those fields that were filled in will still hold the value the user entered. --> <p><label for="fname">First name:</label><?php if(isset($errorArray[0])){echo "<span class='error'>{$errorArray[0]}</span>";} ?><br /> <input type="text" name="fname" id="fname" value="<?php if(isset($_POST['fname'])){echo $_POST['fname'];} ?>" /></p> <p><label for="lname">Last name:</label><?php if(isset($errorArray[1])){echo "<span class='error'>{$errorArray[1]}</span>";} ?><br /> <input type="text" name="lname" id="lname" value="<?php if(isset($_POST['lname'])){echo $_POST['lname'];} ?>" /></p> <p><label for="pnumber">Phone Number:</label><?php if(isset($errorArray[2])){echo "<span class='error'>{$errorArray[2]}</span>";} ?><br /> <input type="text" name="pnumber" id="pnumber" value="<?php if(isset($_POST['pnumber'])){echo $_POST['pnumber'];} ?>" /></p> <p><label for="email">Email:</label><?php if(isset($errorArray[3])){echo "<span class='error'>{$errorArray[3]}</span>";} ?><br /> <input type="text" name="email" id="email" value="<?php if(isset($_POST['email'])){echo $_POST['email'];} ?>" /></p> <p><input type="submit" value="submit" name="submit" id="submit" /></p> </form> </div> </div> </body> </html>
  6. The code that I changed gave me the right result once, but has given me errors since. Would a join statement make what I am trying to do easier? Here are the coloumns in my DB tables: clp_users: ide username password role status fname lname dob email secquestion secanswer createdby creationtime test_picks: id t_id tournament user player backup timestamp email I am trying to pull all the users who did not make a pick for the current tournament, go back to the previous week and grab that particular users backup pick. After I do that I want to insert that into my database with particular parameters. I know how to do the insert I just need help in creating the correct set of SQL statements. Any and all help is appreciated. Thanks.
  7. I am not very familiar with joins within MySQL. However, I got the code to produce the results I needed by changing "AND username" to "AND user". However I am trying to run a 2ndquery with the first queries results and am having no luck. Here is the following code so far: $sql2 = "SELECT username from clp_user WHERE ide != 1 AND user NOT IN (SELECT * from test_picks WHERE t_id = 3)"; $res2 = mysql_query($sql2) or die (mysql_error()); while($row2 = mysql_fetch_array($res2)) { //echo $row2[username] . '<br />'; $sql = "SELECT * from test_picks WHERE t_id = 2 AND user = $row2[username]"; $res1 = mysql_query($sql1) or die (mysql_error()); while($row1 = mysql_fetch_array($res1)) { echo $row1[user] . '<br />'; }; }; I echoed out the user to make sure that I was pulling the right rows. The output I am getting is: Unknown column 'user' in 'IN/ALL/ANY subquery' I do have a column user in the test_picks table.
  8. Here is my SQL statement: $sql2 = "SELECT username from clp_user WHERE ide != 1 AND username NOT IN (SELECT * from test_picks WHERE t_id = 3)"; $res2 = mysql_query($sql2) or die (mysql_error()); while($row2 = mysql_fetch_array($res2)) { echo $row2[username] . '<br />'; }; I have two tables within my DB. I want to select all the usernames from the users table that are not in the test picks table that have a t_id = 3. This statement is returning all of the usernames in my users table, why is that?
  9. I meant to ask, how do I ensure each variable has a value prior to inserting the value into my database.
  10. I have a firm that post to my database. When I tested it always posted my information correctly. I require the user to be logged in before they can access the page with the form. I do I ensure that each php variable has a value in it before the data is posted? Any help would be appreciated. I can post my code if needed.
  11. well, I just thought I would let you know that from your earlier help, I adapted that code to fit the current issue I was trying to resolve and the following code is doing exactly what I want it to if ($result2 = mysql_query("SELECT * FROM weekly_picks WHERE tournament = '$tournament' AND user = '$usr'")) { if (mysql_num_rows($result2)) { while($row2 = mysql_fetch_array($result2)) { mysql_query("UPDATE weekly_picks SET player = '$golfer', backup = '$backup', timestamp = '$time' WHERE tournament = '$tournament' AND user = '$usr'"); } } else { mysql_query("INSERT INTO weekly_picks (t_id, tournament, user, player, backup, timestamp) VALUES ('$t_id', '$tournament', '$usr', '$golfer', '$backup', '$time')",$link) or die('Error, insert query failed'); }}
  12. yes I did, sorry to no have commented, I had that post up prior to me reading it. I put that code in and it worked and I got the result I was looking for.
  13. again, thanks for the tips. I also cannot get the following code to work: $sql = "SELECT * FROM weekly_picks WHERE tournament = '$tournament' AND usr = '$usr'"; $result = mysql_query($sql); echo mysql_num_rows($result); mysql_error(); if ($num > 0) mysql_query("UPDATE weekly_picks SET player = '$golfer' WHERE tournament = '$tournament' AND user = '$usr'"); else mysql_query("INSERT INTO weekly_picks (t_id, tournament, user, player, backup, timestamp) VALUES ('$t_id', '$tournament', '$usr', '$golfer', '$backup', '$time')",$link) or die('Error, insert query failed'); I have a form, and when it is submitted I would like to check to see if the $tournament variable already exists in the table along with the userid. IF it does, I would like to update the golfer field with the new $golfer. If it does not, insert a new row. Any suggestions? I get this response: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in D:\Hosting\6027795\html\demo\submit.php on line 125
  14. The code below works. $result = mysql_query("SELECT id FROM `2012_tournaments` WHERE tournament = '$tournament'"); while($row = mysql_fetch_array($result)) { echo $row['id']; }; After looking through the remaining code, I realized that I was not storing the variable $tournament before I was calling the function, thus the error. It works now. Thanks for walking me through the steps to re-examine my code.
  15. mysql_error() retured this: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''2012_tournaments' WHERE tournament = ''' at line 1 Server version: 5.0.91
×
×
  • 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.