-
Posts
422 -
Joined
-
Last visited
-
Days Won
1
Posts posted by awjudd
-
-
I personally use vim for all of my development. It is nice, light weight and can be opened in a screen session and then accessed from anywhere (if hosted on a server).
All around powerful editor
~judda
-
$_POST[foo] and $_POST['foo'] both work because PHP will automatically upconvert single words of text that it doesn't know as a constant to a string.
That said, using $_POST[foo] is slower because not only does it cause notices to be thrown but it has to check for any definitions before it can assume that it is a string.
Sample:
<?php $arr = array (); for ( $x = 0; $x < 1000000; $x++ ) { $arr [ foo ] = 'bar'; } ?>
Time of execution:
$ time php test.php real 0m1.641s user 0m1.424s sys 0m0.044s
Versus:
<?php $arr = array (); for ( $x = 0; $x < 1000000; $x++ ) { $arr [ 'foo' ] = 'bar'; } ?>
Run Time:
$ time php test.php real 0m0.467s user 0m0.292s sys 0m0.052s
Yes, this is a highly exaggerated case but it is a decent example of how it is bad
~judda
-
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
-
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
-
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
-
Your connection to your database is wrong (probably your username / password).
~judda
-
-
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
-
There are also a series of mysqli_* functions, and PDO methods ... if that is what you were asking ...
~judda
-
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
-
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
-
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
-
if ( isset ($_POST ['file_contents']) ) { file_put_contents ('file.txt', $_POST ['file_contents'] ); }
-
Removing the issues is a lot better than just suppressing them in terms of overhead ...
~judda
-
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
-
@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
-
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
-
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
-
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
-
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
-
After the closing bracket, you need an alias.
SELECT * FROM ( ... ) a
That should do the trick.
~judda
-
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
-
You don't need to keep re-indexing tables. They will maintain their indices and add the new records with indices as needed.
~judda
-
That's what I meant when I was mentioning the offset
Let me know how it turns out
~judda
I need help
in Miscellaneous
Posted
While you are at it ... can you help me download the interwebs?