Jump to content

PFMaBiSmAd

Staff Alumni
  • Posts

    16,734
  • Joined

  • Last visited

  • Days Won

    9

Everything posted by PFMaBiSmAd

  1. What is the length of your password field in your database table?
  2. Assuming you only want to use your own mysql server, instead of being able to use both yours and the one that xampp installs, you will need to stop (don't start) the mysql server that xampp installs and make sure that your mysql server is running (if two services are configured to listen on the same TCP port, only the first one will start.) Your mysql server will then be 'listening' on the default port and your php scripts will connect to it without any other changes.
  3. You should be using a single joined query to get all the related data you want in the order that you want it with one query. If you output a html <pre> tag before you use print_r on your array, the output will be formated so that it is readable. If you reread the multisort examples, you will see that the array_multisort statement is after the foreach(){} loop that is extracting the values to sort on.
  4. function date_range($s_date,$e_date){ list($s_day,$s_month,$s_year) = sscanf($s_date, "%d %s %d"); list($e_day,$e_month,$e_year) = sscanf($e_date, "%d %s %d"); if($s_year == $e_year){ // same year, either 1st or 2nd form if($s_month == $e_month){ // same year, same month, 1st form - DAY. - DAY. MONTH YEAR return "$s_day. - $e_day. $e_month $e_year"; } else { // same year, different month, 2nd form - DAY. MONTH - DAY. MONTH YEAR return "$s_day. $s_month - $e_day. $e_month $e_year"; } } else { // different year - 3rd form - DAY. MONTH YEAR - DAY. MONTH YEAR return "$s_day. $s_month $s_year - $e_day. $e_month $e_year"; } } $s_date = "15 July 2012"; $e_date = "17 July 2012"; echo date_range($s_date,$e_date); echo "<br />"; $s_date = "30 July 2012"; $e_date = "1 August 2012"; echo date_range($s_date,$e_date); echo "<br />"; $s_date = "30 December 2012"; $e_date = "1 January 2013"; echo date_range($s_date,$e_date);
  5. Or you could sort the data in your query - ORDER BY positionid, ranking
  6. See my replies in the following thread - http://forums.phpfreaks.com/index.php?topic=363172.0
  7. A multi-value REPLACE query is also an option - REPLACE INTO your_table (your column list) VALUES (value list 1),(value list 2), ... This would require that you have all the columns listed in the query since it completely replaces any existing row that it finds. If your table has more than just the title, price, user_id, and itemID columns, you would not do it this way since that would require you to first SELECT the existing data to get any other columns. It would also require that you have a composite unique key using your user_id and itemID columns. This method also has the advantage of INSERTing new rows into your table along with replacing existing rows. If you currently have code that is testing if the user_id and itemID exist, then executing an INSERT query if they don't and an UPDATE query if they do, the REPLACE query will replace all that code with one single query.
  8. ^^^ You haven't selected a database at all or your mysql_select_db statement failed.
  9. @GD77, Queries that match zero rows don't produce php fetch statement errors. The only mysql data retrieval statement that produces a php error when there are zero rows in the result set is mysql_result.
  10. It would seem that you are stuck at the design step, so moving this thread to the Application Design forum section...
  11. This topic has been moved to Application Design. http://forums.phpfreaks.com/index.php?topic=363847.0
  12. Arbitrarily setting program variables, named directly from externally submitted data, without any limits/restrictions or validation of the name, would allow a hacker to set any of your program variables to anything he wants.
  13. See this post - http://forums.phpfreaks.com/index.php?topic=363620.msg1721259#msg1721259
  14. If your intent is to be able to easily manipulate (insert, update, delete) or find any piece of data, then each piece of data should be stored in its own record/row.
  15. #1 - I'm not sure what that refers to. If you are asking about producing the form, I'm going to assume that you have some php code now that is producing your existing form. The only real change to switch to using an array name for the <select> field would be to change the php code that is producing the name='...' attribute from making it name='optionx' to name='option[x]' #2 - I have no idea what you are asking. #3 - the echo statement displays the $_POST data so that you can see exactly what is being submitted. One last comment - you should be using the id value from your database table as the value='...' attribute in the <option> tags. Your current scheme of using the 'title' as the value, then putting that value into the SELECT query will prevent you from ever using the same title more than once under a single product. For example, if you added a second option after 'Bacon', of 'White', a query looking for 'White' would find one row from variation 1 and one from variation 2. By using the id, any query looking for a value would be unique.
  16. Here's an example showing how the resulting form would look using an array name for the select fields and how you can loop over the submitted data in the php code - <form method='post'> Coffee: Colours: <select name='option[1]'> <option value=''>Make your selection:</option> <option value='Black'>Black</option> <option value='White'>White</option> </select> Test: <select name='option[2]'> <option value=''>Make your selection:</option> <option value='Bacon'>Bacon</option> </select> <input type='submit'> </form> <?php echo '<pre>',print_r($_POST,true); foreach($_POST['option'] as $key => $value){ if($value !=''){ echo "Option $key is $value<br />"; } else { echo "Option $key is empty<br />"; } }
  17. Actually2, please use the bbcode tags around code (the # button.) The tags, depending on the original new-line character in the source, adds a new-line character to every \t, \r, and \n in the code, resulting in hundreds of extra new-lines when you select/copy/paste code to try and help with it.
  18. I've been looking at your code, trying to figure out what it is trying to do. There's so much extra code that its got a - "cannot see the forest for the trees" problem. Some questions and comments - 1) Are the $_POST['option1'], $_POST['option2'], .... values simply set/not-set or are they a quantity of any particular option? 2) Using a HTML array for the above option fields will allow you to have any number of options and the code will be simpler because you will be able to use php array functions, such as a foreach(){} loop, to operate on the data. 3) What does the store_variations_values table do? Your code is already getting the price for each option from the store_variations table, so I don't see the point of the last block of code with the SELECT query for the store_variations_values table? 4) You have $option1_price,2,3,4,5 and $price1, 2,3,4,5 variables floating around. It appears that those were intended to be all just $option1_price,2,3,4,5 Arrays are for sets of data, where you will be processing each value in the same way. I'll try to post a version of code using arrays that shows how simplified it can be (probably about 1/5 the amount of code.)
  19. Here's a different slant on the problem - You should never need to run SELECT queries inside of loops. You should also never have a series of name/numbered variables. Using variable variables takes more (and 3x slower) code to accomplish anything. You should be using arrays for sets for data. In general, you should have ONE query that gets all the rows you want in the order that you want them. You then simply loop over the rows and output the data the way you want.
  20. This topic has been moved to Third Party PHP Scripts. http://forums.phpfreaks.com/index.php?topic=363613.0
  21. Since you haven't specifically stated exactly what the script is doing that leads you to believe it doesn't work, no one here can help you based on the information you have supplied. If you want specific help with a program, you must supply the specific symptoms or errors that you need help with. You started this thread by adding your post to an existing thread, where you implied that you were getting the same error as in the title - "Cannot re-assign $this". But there is no indication at all that you were getting that error. The list of undefined variable notices 'could' prevent a script from working if that script was trying to use header() statements, sessions, or cookies... But again, nothing you have supplied indicates what is or is not working. We are not here to rewrite poorly written 3rd party scripts for people who want to use them, and since this is a 3rd party script, moving this thread to the appropriate forum section...
  22. A Unixtime stamp of zero is Jan 1, 1970. Adding 5 days of seconds to that would make it Jan 6, 1970.
  23. Here's an example of using JOINs in the query that will get the schedule with the teamname for both the visitor and home team (this assumes that you have a date column in your schedule as suggested above) - <?php // query to display the schedule from the database information // make database connection/select database here... //teams (teamid, teamname) //schedule (gameid, homeid, awayid, weeknum, seasonnum, date) $query = "SELECT weeknum, date, v.teamname as visitor, h.teamname as home FROM schedule s INNER JOIN teams v ON s.awayid = v.teamid INNER JOIN teams h ON s.homeid = h.teamid ORDER BY gameid"; $result = mysql_query($query) or die(mysql_error()); $last_week = null; $last_date = null; while($row = mysql_fetch_assoc($result)){ // output any week # heading if($last_week != $row['weeknum']){ // week changed (or is the first one) echo "Week {$row['weeknum']}<br />"; $last_week = $row['weeknum']; } // output any date sub-heading if($last_date != $row['date']){ // date changed (or is the first one) $date = date('D, M j',strtotime($row['date'])); // format the date as: Wed, Sep 5 echo "$date<br />"; $last_date = $row['date']; } // output data under each week/date heading echo "{$row['visitor']} at {$row['home']}<br />"; } The above should display your schedule, something like the following -
  24. Here are some things to consider, assuming you are doing this for real and it is not just a classroom assignment. Players are not on one team for their entire career and some players switch the position and/or jersey number that they play. You would actually need a player table with the 'static' information about a player - id, first name, last name, dob, collage, date drafted... This would assign each player an id. You would then need a player_details (or perhaps call it player_history) table that holds the 'variable' details of where a player played at, when, what position, and jersey number - id, playerid, teamid, positionid, jersey_no, start_date, end_date. There can be multiple records for each playerid that tracks what teams he has been on. The end_date would be either a null/empty/zero/or a far-future date in the record for the current team the player is a member of. By storing the date(s) in the above table, you can then determine the team roster for any game (if the date the game was played on is between the player's start and end date and the teamid matches, that player was on that team for that game.) You would also need to store the actual complete date for each game in the schedule table.
  25. The second parameter of the ->set() method expects a string, i.e. like the first two uses set("Titolo_Pagina", ... If your 'pages/left.php' file contains the string your want to supply as the second parameter, use file_get_contents instead of require_once.
×
×
  • 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.