Jump to content

awjudd

Staff Alumni
  • Posts

    422
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by awjudd

  1. Not in the case where we are trying to see if something changes ... <?php $sql=mysql_query("SELECT items.itemname, cat.category FROM items,cat WHERE cat.catid=items.catid"); $curr = ''; while($res=mysql_fetch_array($sql)) { if ( $curr != $res [ 'category' ] ) { echo $res['category'] . "<br>"; $curr = $res [ 'category' ]; } echo $res['itemname'] . "<br>"; } Something like that would work. ~judda
  2. How do you keep track of it? ... in a variable? $prevCategory = $res['category']; The sorting in that manner should probably as you said put the things followed by a rank you would need a simple table mapping the orders, or you could do it in PHP (less efficient) using the array sorting functions. ~judda
  3. Question 1: what i need is for it to display the category name only once...then each item under that correct category..then display the next category and its respected items etc etc. Keep track of the current header and use an if statement if it is different then print it, otherwise don't. Question 2: I would order by the category and then the itemname (ORDER BY category, itemname) ~judda
  4. Your connection to your database is wrong (probably your username / password). ~judda
  5. Another way to connect to the database? http://lmgtfy.com/?q=PDO ~judda
  6. ASP.NET has lots of stuff already built-in for you ... so that can be both helpful and detrimental to your learning ... For example, ASP.NET has their membership provider so that in a matter of about 10 lines of code, you can have a complete login script done with user roles and everything. Whereas to do something similar in PHP, you need to do it manually. ~judda
  7. There are also a series of mysqli_* functions, and PDO methods ... if that is what you were asking ... ~judda
  8. In your form, you had action = '?admintext.php' which wasn't going to post there as you expected, it was going to post to the current page and have ?admintext.php in the URL . ~judda
  9. Does php have write permissions on the file? Can you post your updated code (with the code for the file_put_contents) on here so we aren't pulling at straws? ~judda
  10. On the page that is being posted to ... I just noticed that it is being posted to a .txt file ... so you are going to have to change that to a separate php file. ~judda
  11. if ( isset ($_POST ['file_contents']) ) { file_put_contents ('file.txt', $_POST ['file_contents'] ); }
  12. Removing the issues is a lot better than just suppressing them in terms of overhead ... ~judda
  13. The @ sign and the turning off of error reporting is only suppressing the errors. It tells PHP to not complain to the UI about them, however they are still being thrown. ~judda
  14. @jmz - you were doing a hard read of the array which causes the notice. The isset will do a soft read not causing it to do anything / grabbing any information that is potentially not yours. ~judda
  15. if ( !isset ( $_POST['wholesale'] ) ) { $wholesale = '.'; } That should remove the notice. That said, you shouldn't be ignoring the notices because there is a chance it could cause your script to do something you don't expect. And iirc, the throwing of notices slows the execution of the scripts a bit. ~judda
  16. Why are your expressions within the count a string? COUNT('CASE games.competition WHEN 3 THEN goals.goal_id ELSE NULL END CASE') AS gls3, It shouldn't be in quotes ... it should be: COUNT(CASE games.competition WHEN 3 THEN goals.goal_id ELSE NULL END CASE) AS gls3, ~judda
  17. How about having a conditional statement within your COUNTs? i.e. SELECT COUNT( CASE games.competition WHEN 1 THEN goals.goal_id ELSE NULL END CASE ) AS gls1, /* NULL shouldn't be counted */ COUNT( CASE games.competition WHEN 2 THEN goals.goal_id ELSE NULL END CASE ) AS gls2, goals.scorer, players.surname, games.competition FROM goals INNER JOIN players ON goals.scorer = players.player_id INNER JOIN games ON goals.match = games.match_id GROUP BY goals.scorer Etc? ... or group it by competition id, then you don't need the conditional, and it would return the counts for each of the competitions, even if there were more than what you originally expected. Does that make sense? ~judda
  18. Try using a CASE statement instead. UPDATE elec_products SET stats = CASE programmename WHEN 'Argos' THEN 1 WHEN 'stify' THEN 2 ELSE 3 END CASE WHERE programmename IS NOT NULL ~judda
  19. After the closing bracket, you need an alias. SELECT * FROM ( ... ) a That should do the trick. ~judda
  20. There is no need to order by the two queries. Try a similar fashion to what I have in my third post with the union bit being within a subquery. For example: SELECT SeatPosition FROM ( SELECT SeatPosition AS SeatOffset,SeatPosition FROM users WHERE TableID='2' AND SeatPosition > $MyCurrentSeatPosition UNION SELECT SeatPosition + 8 AS SeatOffset, SeatPosition FROM users WHERE TableID='2' AND SeatPosition <= $MyCurrentSeatPosition LIMIT 1 ) ORDER BY SeatPosition The other thing I noticed in your original query is that you wrote last post, you have two things being returned, whereas the second query only returns one. Which breaks what is required for a union (both tables must return the same number of columns). ~judda
  21. awjudd

    Whats best?

    You don't need to keep re-indexing tables. They will maintain their indices and add the new records with indices as needed. ~judda
  22. That's what I meant when I was mentioning the offset Let me know how it turns out ~judda
  23. Yup, just so that we can fit all of the groups in and in the order in which they belong. ~judda
  24. Would something like this work? SELECT ( post_id IN ( 121, 84, 376, 20, 3, 94, 1 ) ) AS excluded FROM posts ~judda
  25. Just an extension on what I said. If the current position is 8, you will get the following: Query Part 1: SELECT SlotID AS SlotRank, SlotID FROM UserSeats WHERE SlotID > 8 Returns an empty table because there are no seats greater than 8 (that is the maximum number of seats) Query Part 2: SELECT SlotID + 8 AS SlotRank, SlotID FROM UserSeats WHERE SlotID <= 8 Returns: SlotRank | SlotID ----------------------- 12 | 4 14 | 6 9 | 1 15 | 7 So, when we UNION these two sets, we will get (same as the results from the second part of the query because we are at the maximum value): SlotRank | SlotID ----------------------- 12 | 4 14 | 6 9 | 1 15 | 7 Then using that as the basis, we can order those results based on the SlotRank to see which should come first. For example: SELECT SlotID FROM ( SELECT SlotID AS SlotRank, SlotID FROM UserSeats WHERE slot > :current_slot UNION SELECT SlotID + 8 AS SlotRank, SlotID FROM UserSeats WHERE slot <= :current_slot ) ORDER BY SlotRank This will return the following result set (given that the current slot is : SlotID ----------- 1 4 6 7 Which would mean that the next used seat is seat 1 ... which satisfies your requirement? It wouldn't choose 4 first because you said you wanted the next used seat since if we are at 8 would be 1 ... Does this make sense? ~judda
×
×
  • 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.