Psycho
Moderators-
Posts
12,157 -
Joined
-
Last visited
-
Days Won
129
Everything posted by Psycho
-
As I stated the code is a mess. Putting all those beginning and ending PHP tags on every line makes the code unreadable and unwieldy. After deconstructing all of it I can see you have a ton of invalid HTML content. You have opening/closing tags that do not match up and there are tags that are simply out of place (e.g. <li> tags around table rows. I have rebuilt the entire script in a more logical, readable format that may work for you. <?php $columns = 2; $total1 = count($this->item->extra_fields); echo "<span class='catItemExtraFieldsLabel'>{$total1}</span>\n"; if($this->item->params->get('catItemExtraFields') && $total1) { $addlInfo = JText::_('K2_ADDITIONAL_INFO'); $counter = 0; //begin page output echo "<!-- Item extra fields -->\n"; echo "<div class='catItemExtraFields'>\n"; echo "<h4>{$addlInfo}</h4>\n"; echo "<table width='400px' border='0'>\n"; foreach ($this->item->extra_fields as $key=>$extraField) { if($extraField->value) { $counter++; //open new row if ($counter%$columns == 1) { echo "<tr>\n"; } //Prepare data for current record $oddEven = ($key%2) ? "odd" : "even"; $type = ucfirst($extraField->type); $class = "{$oddEven}type{$type}group{$extraField->group}"; //Display current record echo "<td class='{$class}'>\n"; echo "<span class='catItemExtraFieldsLabel'>{$extraField->name}</span>\n"; echo "<span class='catItemExtraFieldsValue'>{$extraField->value}</span>\n"; echo "<span class='catItemExtraFieldsLabel'>{$counter}</span>\n"; echo "</td>\n"; //Close completed row if ($counter%$columns == 0) { echo "</tr>\n"; } } //Close last row if not already closed if($counter%$columns != 0) { echo "</tr>\n"; } } //Close table echo "</table>\n"; echo "<div class='clr'></div>\n"; } ?>
-
I would try to help, but that is some god awful code you have there. It would take me 5-10 minutes just to deconstruct it to try and understand. I assume you are using DreamWeaver or some other WYSIWYG editor. Get yourself a decent code editor (even Notepad ++ would be a good choice). Anyway, if you want to put your coed in [ CODE ] tags as you are supposed to, I *might* be included to help.
-
If you have a need to re-size the images, then by all means re-size them. It is up to you to decide what is worth your time, effort and cost. Not some blowhard that has a blog on the internet. But, that' snot to mean you don't get the proper information before your decision and reassess your decisions thereafter. Go ahead and implement a resizing script then do some tests of images with sizes you think would represent what users may upload. Is the performance acceptable? Also, be sure to try very large images - ones that you think would be much, much bigger than would be submitted. At some point the process will probably fail. You should then set a maximum size that you will accept where performance is still acceptable and the process does not fail - and reject ones that are larger.
-
Show the exact code you have implemented
-
You will need to do a foreach on each array separately. However, if the two arrays have values that should be "associated" with each other and the arrays can have different number of elements you need to explain how they should be associated so we can help you. Again, providing an example of the contents of those arrays and an example of how you want them to be output would help.
-
OK, it took some googling, and I'm not sure this is the most efficient method, but it works. I wouldn't have done this, but I like a challenge. This assumes that the points table has a date column (in the query I used the field name "date" but you can change as needed. But, that field should be a FULL date field (i.e. with hours, minutes, and seconds). If there are any records with the exact same date value for a team id you could get incorrect results. But, as long as the records are on different days or are different by at least 1 second you should be fine. SELECT team, sum(points1.points) as total_points, points2.last_five FROM test_teams LEFT JOIN test_team_points AS points1 ON test_teams.teamid = points1.teamid LEFT JOIN (SELECT teamid, SUM(points) as last_five FROM test_team_points JOIN (SELECT t1.teamid, t1.points, t1.date, COUNT(t2.teamid) AS rank FROM test_team_points t1 LEFT JOIN test_team_points t2 ON t1.teamid = t2.teamid AND t1.date < t2.date GROUP BY t1.teamid, t1.date HAVING rank < 5) AS dt USING (teamid, date) GROUP BY teamid ) as points2 ON test_teams.teamid = points2.teamid GROUP BY test_teams.teamid
-
use urlencode() for the names and values that you append to the URL and then use urldecode() when you access them
-
What?! You must have no idea what you are doing because what you've stated makes absolutely no sense. The => operator does not prevent you in any way from accessing all the values of the array. If I had to guess, I would say that the arrays $_POST['course'] and $_POST['program'] do not have the same keys. So, why are you trying to use the key of one array to access the values of a different array? Since I do not understand the relationship of $_POST['course'] and $_POST['program'] in your application I cannot provide any advice on what you could do to solve your problem. Post what the typical values of the two arrays will hold and explain what you want to achieve
-
Your query is failing - you need to add some error handling. Are you sure the field is name "User name"? I didn't think you could have spaces in a field name. Even if you can - it is bad practice. Besides you shouldn't be trying to extract the results before you have even checked if there were results. Lastly, only SELECT the fields you need - don't use "*" $query = "SELECT `User name`, `Password` FROM `users` WHERE `User name` = '$fusername' AND `Password` = '$fpassword'"; $result = mysql_query($query) or die(mysql_error()); if(!mysql_num_rows($result)) { echo "No results returned."; } else { $dbusername=mysql_result($result, 0, "User name"); $dbpassword=mysql_result($result, 0, "Password"); echo "Username: $dbusername<br>\n"; echo "Password: $dbpassword;<br>\n"; }
-
Users are able to access other users information.
Psycho replied to joeNmass's topic in PHP Coding Help
There is absolutely no difference with respect to security between GET and POST data. I can easily view and modify POST data. The only thing POST does obfuscate the values from the run of the mill users. But, it is the users that really know what they are doing that you have to worry about. But, as stated by PFMaBiSmAd, the values should be stored in session data. -
Well, it would have been nice to see the actual error you received. I believe your problem is due to the line where you do the actual calculation echo ' . . . <td class="col4">' . $eventCost*eventAttendees[$x] . '</td> . . . '; Because you are trying to calculate something while at the same time append it to the echo. The PHP parser is getting confused, because it first tries to append "$eventCost" to the string and then it encounters the asterisk indicating you want to multiply the previous value (which is the entire string up to the point) and the next value "eventAttendees[$x]". Well, there are two problems there, the entire string preceding that asterisk is not a mathematical value and "eventAttendees[$x]" isn't a variable. I assume there should be a dollar sign precedence that. Just like in match, you sometimes need to put some operations within parens to determine the order. You can do that within the echo, but a better way is to simply calculate the total and assign to a variable before you start the echo. You can also make that code much more readable than it is now. <!-- Body --> <tbody> <?php // Fetch Comment record. $x=0; while (mysqli_stmt_fetch($stmt)) { //<!-- Row 1 --> $sub_total = $eventCost * $eventAttendees[$x]; echo " <tr> <th scope='row' class='headerCol'> $eventName<br /> $eventLocation<br /> $eventDate </th> <td class='col2'> $eventPrice <input type='hidden' name='eventCost[$x]' value='$eventPrice' /> </td> <td class='col3'> <select name='eventAttendees[$x]'> <option value=''>--</option> <option value='1'>1</option> <option value='2'>2</option> <option value='3'>3</option> <option value='4'>4</option> </select> </td> <td class='col4'>$sub_total</td> <td class='col5'> <input name='eventChosen[$x]' type='submit' value='Buy Tickets' /> </td> </tr>"; } ?> </tbody>
-
Not displaying page because of for/foreach loops
Psycho replied to Xtremer360's topic in PHP Coding Help
A better question would be why you have that foreach() loop inside the for() loop. As xtopolis stated your problem is the ">=" condition. I think you meant to use "<=". But, you don't need that at all. You need two sets of foreach loops. A couple other things. The ternary operator to determine the name will be the same value on every iteration of the loop since you are not comparing any values that are dynamically determined in the loop. So, you should determine the $name before the loop since doing it on each iteration is inefficient. In fact, you are not using ANY values of the arrays in the loops at all. Very odd. I assume that must be a mistake. Also, in my opinion, you should do "positive" tests in your conditions if it makes sense rather than negative tests. Makes it much easier to read the code. Lastly, the line to determine the separator - it looks like you are trying to put the separator after each line, except the last. It would probably be moire efficient to redefine the values of the array as you loop through them with the output you want and then do an implode. But, your whole output is wrong, so it's hard to really suggest a better method foreach($topRankings as $rank) { foreach($rank as $key => $value) { //$seperator = ($elements == $count) ? '' : '<hr />'; //Putputput in array and then do an implode $name = (isset($row['character_name'])) ? $row['character_name'] : 'TBD'; echo "<li><span class='red'>{$name}</span></li>\n"; } } -
You would pass the values the same as you always would - either as form fields passed via POST or GET or you could simply append the values to a URL. Since you are using buttons, make each button the submit button for a form. Then you can store the three values as hidden fields for each form.
-
That is a much, much different situation. $regex = "#<figure><img src='([^']*)' alt='([^']*)' /><figcaption>([^']*)</figcaption></figure>#"; $replace = "{{$1||$2||$3}}"; $output = preg_replace($regex, $replace, $input);
-
If you are going to use flat files you don't have much of a chice other than reading data from the beginning of the file until you get to the records for the page you want to display. You should really consider using a database.
-
You first need to go read up on coding with PHP and MySQL. Once you have the basics, create your database, then start building the pages. There is just so much that you need to know and trying to present that information in a forum is not realistic
-
User-Defined Query to Display Table of Results
Psycho replied to javinladish's topic in PHP Coding Help
Seriously? What is the difficulty you face. If you've ever done any queries this should be a piece of cake: //Get query submitted from form $query = $_POST['user_query']; //Run query $result = mysql_query($query); //Output results if(!$result) { echo "There was an error running the query: " . mysql_error(); } elseif(!mysql_num_rows($result)) { echo "No results returned"; } else { $header = false; echo "<table border='1'>\n"; while($row = mysql_fetch_assoc()) { if(!$header) { echo "<tr>\n"; foreach($row as $header => $value) { echo "<th>{$header}</th>\n"; } echo "</tr>\n"; $header = true; } echo "<tr>\n"; foreach($row as $value) { echo "<th>{$value}</th>\n"; } echo "</tr>\n"; } echo "</table>\n"; } -
That makes absolutely no sense. What is in "$content" and what are you trying to search for and what are you wanting to replace it with?
-
Just be aware that you should put some validation on that code. The first query could result in -1 or -2 - which would likely result in an error when running the 2nd query (never tired a negative value on the LIMIT clause). Or, if the result of the first query is 0, you would get 0 for the second query (even though there were records for the vehicle_id, but only 2). So says the amazing Kalamazan!
-
Looks fine to me. How are you setting your cookies? There's a chance the names of the cookies are "escaped", so try this function deleteCookie(cookieName) { if(document.cookie.length>0) { cookieName = escape(cookieName); document.cookie = cookieName + "=; expires=Thu, 01-Jan-70 00:00:01 GMT"; } }
-
Is it possible to run an infinite loop with jQuery each() function
Psycho replied to drayarms's topic in Javascript Help
I'm not too up to speed on JQuery, but I would think all you need to do is put the each() loop inside of another loop. Something like while(1==1) { $.each($('.slide'), function(i, val) { setTimeout(function() { $(val).animate({width:"toggle"}, '4000').delay(3000).animate({width: "toggle"},'4000'); },4500 + (i*4500)); } } So, on each loop of the outer loop, the each() loop is reset. -
Probably because the string starts with a "-", so the explode() splits the string on that first character and assigns an empty string to the first index. If you want to skip ANY empty values you can do this foreach($lines as $line) { if(!empty($line) { echo "* {$line}<br />\n"; } } Or if you want to skip lines that are empty OR only have white-space (i.e. spaces, tabs) foreach($lines as $line) { $line = trim($line); if(!empty($line) { echo "* {$line}<br />\n"; } } Lastly if you only want to skip the first index, but still output all other elements even if they are blank array_shift($lines); //remove first element foreach($lines as $line) { echo "* {$line}<br />\n"; }
-
In the first query why are you using "SELECT *, COUNT(miles)"? Remove the "*," from the SELECT. Also, why are you using a while() loop onthat query result? You only want ONE record returned. As for the second query - you need to reference the av_miles value from the query; you don't need to reference 'data_set' at all. However, when you create a "dynamic" table as is done with the subquery you need to give it a name. $query = "SELECT (COUNT(miles) - 2) AS record_count FROM mpg WHERE vehicle_id='$id'"; $result = mysql_query($query) ; $record_count = mysql_result($result, 0); echo "<br/>There are {$record_count} items<br>\n"; $query = "SELECT AVG(miles) AS av_miles FROM (SELECT miles FROM mpg WHERE vehicle_id='$id' ORDER BY date DESC LIMIT {$record_count}) as data_set"; $result = mysql_query($query) ; $avg_miles = mysql_result($result, 0); echo "<br/>The average miles are {$avg_miles}<br />\n";
-
<< Moved to Regex Forum >> $input = "some text before {{http://en.wikipedia.org/wiki/File:Wiki.png||wikipedia logo||This is the wikipedia logo}} some text after"; $regex = "#{{([^|]*)\|\|([^|]*)\|\|([^|]*)}}#"; $replace = "<figure><img src='$1' alt='$2' /><figcaption>$3</figcaption></figure>"; $output = preg_replace($regex, $replace, $input); echo $output; //Output: //some text before <figure><img src='http://en.wikipedia.org/wiki/File:Wiki.png' alt='wikipedia logo' /><figcaption>This is the wikipedia logo</figcaption></figure> some text after
-
This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=346278.0