jcbones
Staff Alumni-
Posts
2,653 -
Joined
-
Last visited
-
Days Won
8
Everything posted by jcbones
-
What steps have you taken to insure that $mface is empty, and/or that $row['cdata'] Notice: Use of undefined constant cdata - assumed 'cdata' contains the correct string? Perhaps a little more code than that is needed to find the problem.
-
Ideally what you need to do is create arrays that hold the id's of the rows to be updated, then do 1 update query. while($row_to_be_marked_new = mysqli_fetch_assoc($result_set)) { $mark_these_as_new[] = $row_to_be_marked_new['id']; } $sql = "UPDATE `maps` SET `Newest` = 'New' WHERE `id` IN (" . implode(',',$mark_these_as_new) . ')'; mysqli_query($con,$sql);
-
You need to put that query into the database, and view the return. I think you will find you are returning duplicate rows. So, my solution is: fix the query.
-
Coloring usernames in table based off IP Address?
jcbones replied to Lukeidiot's topic in PHP Coding Help
Run the following code with NO modifications. When you are sure that it works correctly, then you start modifying it. When it quits working, you will know that what you have tried is wrong. <?php include("colors.php"); function randomColor($colors) { $color = array_rand($colors,1); return (strpos($color,'*') === false) ? substr($colors[$color],1) : randomColor($colors); } // $sql = mysql_query("SELECT * FROM ph_referers WHERE owner = '$_SESSION[username]' ORDER BY id DESC"); // while($row = mysql_fetch_assoc($sql)){ // $ipaddress = $row['ipaddress']; $ipaddress = array('User1' => '127.0.0.1','User2' => '127.0.0.1','User3' => '44.43.44.44', 'User4' => '54.45.45.45'); $usedColors = array(); foreach($ipaddress as $user => $address) { if(array_key_exists($address,$usedColors)) { $color = $usedColors[$address]; } else { $color = randomColor($colors); $usedColors[$address] = $color; } echo '<font color="#' . $color . '">' . $address . '</font><br />'; } //echo "$new - $row[username]:$color<br>"; //} -
Coloring usernames in table based off IP Address?
jcbones replied to Lukeidiot's topic in PHP Coding Help
Second part: Whatever.php <?php include('colors.php'); function randomColor($colors) { $color = array_rand($colors,1); return (strpos($color,'*') === false) ? substr($colors[$color],1) : randomColor($colors); } $usedColors = array(); foreach($row['ipaddress'] as $address) { if(array_key_exists($address,$usedColors)) { $color = $usedColors[$address]; } else { $color = randomColor($colors); $usedColors[$address] = $color; } echo '<span style="background-color:#' . $color . '">' . $address . '</span><br />'; } -
Coloring usernames in table based off IP Address?
jcbones replied to Lukeidiot's topic in PHP Coding Help
Here you go: colors.php - provided by *unkown* (can't remember) <?php $colors = array("*TITLE01*" => "Reds", "Indian Red" => "#CD5C5C", "Light Coral" => "#F08080", "Salmon" => "#FA8072", "Dark Salmon" => "#E9967A", "Light Salmon" => "#FFA07A", "Crimson" => "#DC143C", "Red" => "#FF0000", "Fire Brick" => "#B22222", "Dark Red" => "#8B0000", "*TITLE02*" => "Pinks", "Pink" => "#FFC0CB", "Light Pink" => "#FFB6C1", "Hot Pink" => "#FF69B4", "Deep Pink" => "#FF1493", "Medium Violet Red" => "#C71585", "Pale Violet Red" => "#DB7093", "*TITLE03*" => "Oranges", "Light Salmon" => "#FFA07A", "Coral" => "#FF7F50", "Tomato" => "#FF6347", "Orange Red" => "#FF4500", "Dark Orange" => "#FF8C00", "Orange" => "#FFA500", "*TITLE04*" => "Yellows", "Gold" => "#FFD700", "Yellow" => "#FFFF00", "Light Yellow" => "#FFFFE0", "Lemon Chiffon" => "#FFFACD", "Light Goldenrod Yellow" => "#FAFAD2", "Papaya Whip" => "#FFEFD5", "Moccasin" => "#FFE4B5", "Peach Puff" => "#FFDAB9", "Pale Goldenrod" => "#EEE8AA", "Khaki" => "#F0E68C", "Dark Khaki" => "#BDB76B", "*TITLE05*" => "Purples", "Lavender" => "#E6E6FA", "Thistle" => "#D8BFD8", "Plum" => "#DDA0DD", "Violet" => "#EE82EE", "Orchid" => "#DA70D6", "Fuchsia" => "#FF00FF", "Magenta" => "#FF00FF", "Medium Orchid" => "#BA55D3", "Medium Purple" => "#9370DB", "Blue Violet" => "#8A2BE2", "Dark Violet" => "#9400D3", "Dark Orchid" => "#9932CC", "Dark Magenta" => "#8B008B", "Purple" => "#800080", "Indigo" => "#4B0082", "Slate Blue" => "#6A5ACD", "Dark Slate Blue" => "#483D8B", "*TITLE06*" => "Greens", "Green Yellow" => "#ADFF2F", "Chartreuse" => "#7FFF00", "Lawn Green" => "#7CFC00", "Lime" => "#00FF00", "Lime Green" => "#32CD32", "Pale Green" => "#98FB98", "Light Green" => "#90EE90", "Medium Spring Green" => "#00FA9A", "Spring Green" => "#00FF7F", "Medium Sea Green" => "#3CB371", "Sea Green" => "#2E8B57", "Forest Green" => "#228B22", "Green" => "#008000", "Dark Green" => "#006400", "Yellow Green" => "#9ACD32", "Olive Drab" => "#6B8E23", "Olive" => "#808000", "Dark Olive Green" => "#556B2F", "Medium Aquamarine" => "#66CDAA", "Dark Sea Green" => "#8FBC8F", "Light Sea Green" => "#20B2AA", "Dark Cyan" => "#008B8B", "Teal" => "#008080", "*TITLE07*" => "Blues", "Aqua" => "#00FFFF", "Cyan" => "#00FFFF", "Light Cyan" => "#E0FFFF", "Pale Turquoise" => "#AFEEEE", "Aquamarine" => "#7FFFD4", "Turquoise" => "#40E0D0", "Medium Turquoise" => "#48D1CC", "Dark Turquoise" => "#00CED1", "Cadet Blue" => "#5F9EA0", "Steel Blue" => "#4682B4", "Light Steel Blue" => "#B0C4DE", "Powder Blue" => "#B0E0E6", "Light Blue" => "#ADD8E6", "Sky Blue" => "#87CEEB", "Light Sky Blue" => "#87CEFA", "Deep Sky Blue" => "#00BFFF", "Dodger Blue" => "#1E90FF", "Cornflower Blue" => "#6495ED", "Medium Slate Blue" => "#7B68EE", "Royal Blue" => "#4169E1", "Blue" => "#0000FF", "Medium Blue" => "#0000CD", "Dark Blue" => "#00008B", "Navy" => "#000080", "Midnight Blue" => "#191970", "*TITLE08*" => "Browns", "Cornsilk" => "#FFF8DC", "Blanched Almond" => "#FFEBCD", "Bisque" => "#FFE4C4", "Navajo White" => "#FFDEAD", "Wheat" => "#F5DEB3", "Burly Wood" => "#DEB887", "Tan" => "#D2B48C", "Rosy Brown" => "#BC8F8F", "Sandy Brown" => "#F4A460", "Goldenrod" => "#DAA520", "Dark Goldenrod" => "#B8860B", "Peru" => "#CD853F", "Chocolate" => "#D2691E", "Saddle Brown" => "#8B4513", "Sienna" => "#A0522D", "Brown" => "#A52A2A", "Maroon" => "#800000", "*TITLE09*" => "Whites", "White" => "#FFFFFF", "Snow" => "#FFFAFA", "Honeydew" => "#F0FFF0", "Mint Cream" => "#F5FFFA", "Azure" => "#F0FFFF", "Alice Blue" => "#F0F8FF", "Ghost White" => "#F8F8FF", "White Smoke" => "#F5F5F5", "Seashell" => "#FFF5EE", "Beige" => "#F5F5DC", "Old Lace" => "#FDF5E6", "Floral White" => "#FFFAF0", "Ivory" => "#FFFFF0", "Antique White" => "#FAEBD7", "Linen" => "#FAF0E6", "Lavender Blush" => "#FFF0F5", "Misty Rose" => "#FFE4E1", "*TITLE10*" => "Greys", "Gainsboro" => "#DCDCDC", "Light Grey" => "#D3D3D3", "Silver" => "#C0C0C0", "Dark Gray" => "#A9A9A9", "Gray" => "#808080", "Dim Gray" => "#696969", "Light Slate Gray" => "#778899", "Slate Gray" => "#708090", "Dark Slate Gray" => "#2F4F4F", "Black" => "#000000" ); ?> -
Yes, you can reference a string by array. $str = 'A+At'; echo $str[1]; // output: +
-
Problme: passing variable to the next page and keeping it live
jcbones replied to learningPHP1's topic in PHP Coding Help
projectassessment.php <?php session_start(); //echo $_SESSION['taskid'] = $_GET['taskid']; //you are resetting $_SESSION to the $_GET['taskid'] which doesn't exist. echo $_SESSION['taskid']; ... ?> Don't overwrite with empty variables. -
That is fine, you could also use: file_put_contents('formdata.txt',$email,FILE_APPEND | FILE_EX);
-
Problme: passing variable to the next page and keeping it live
jcbones replied to learningPHP1's topic in PHP Coding Help
Don't reset it with the $_GET that doesn't exist. -
accessing a value in a multidimensional associative array
jcbones replied to dmikester1's topic in PHP Coding Help
You need to change it to: $POs[$jobID] = array('FSME' => $matTotal, ...); Or access it using: $POs[0][312]['FSMC']; -
To make a required input, you need to check if that input is empty. <?php // get posted data into local variables $EmailFrom = "offerpage@mirrorshow.com"; $EmailTo = "chris.rice@mirrorshow.com"; $Subject = "Offer Submission"; $Name = Trim(stripslashes($_POST['Name'])); $Company = Trim(stripslashes($_POST['Company'])); $Telephone = Trim(stripslashes($_POST['Telephone'])); $Email = Trim(stripslashes($_POST['Email'])); if(empty($Name)) { $message = 'You are required to input a name.'; }
-
You can use simpleHtmlDom. The syntax would be: <?php include('path/to/simple_html_dom.php'); $dom = file_get_html('demo.htm'); $table = $dom->find('table',0); $rows = $table->children(0)->children(); foreach($rows as $row) { foreach($row->children() as $column) { if(!empty($column->innertext)) { echo $column->innertext . '<br />' . PHP_EOL; } } } ?>
-
Seems the domDocument() doesn't like the way the table is formed. To be honest, I don't think anything I have ever fed it, was acceptable the without tweaking. Here is your first error: DomDocument cannot read the file correctly. It is throwing errors on every line that has ;="" in the attributes. This is because it cannot apply the attribute name. If you fix that, it still will not work, and is showing an empty nodeList. You can use echo '<pre>' . print_r($dom,true) . '</pre>'; to see what the object contains.
-
Yes, just include the reset.php into the file that uses $check.
-
This code works on my machine. <html> <body> <?php $month_Names = Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"); if (!isset($_REQUEST["month"])) $_REQUEST["month"] = date("n"); if (!isset($_REQUEST["year"])) $_REQUEST["year"] = date("Y"); $Current_Month = $_REQUEST["month"]; $Current_Year = $_REQUEST["year"]; $prev_year = $Current_Year; $next_year = $Current_Year; $prev_month = $Current_Month-1; $next_month = $Current_Month+1; if ($prev_month == 0 ) { $prev_month = 12; $prev_year = $Current_Year - 1; } if ($next_month == 13 ) { $next_month = 1; $next_year = $Current_Year + 1; } $today = date("d"); //Today's date (number e.e. 17) $month = date("F"); //This month (full name e.g. February) $year = date("Y"); //This year (4 digits, e.g. 2013) ?> <table width="200"> <tr align="center"> <td style="color:#FFFFFF"> <table width="100%" border="0" cellspacing="2" cellpadding="0"> <tr> <td align="left"> <a href="<?php echo $_SERVER["PHP_SELF"] . "?month=". $prev_month . "&year=" . $prev_year; ?>" style="color:#808080"> << </a></td> <td align="center" style="color:#000000"><strong><?php echo $month_Names[$Current_Month-1].' '.$Current_Year; ?></strong></td> <td align="right"><a href="<?php echo $_SERVER["PHP_SELF"] . "?month=". $next_month . "&year=" . $next_year; ?>" style="color:#808080"> >> </a></td> </tr> </table> </td> </tr> <tr> <td align="center" clspan="7"> <table width="100%" border="0" cellpadding="2" cellspacing="2"> <tr> <td align="center" style="color:#FF0000"><strong>S</strong></td> <td align="center" style="color:#000000"><strong>M</strong></td> <td align="center" style="color:#000000"><strong>T</strong></td> <td align="center" style="color:#000000"><strong>W</strong></td> <td align="center" style="color:#000000"><strong>T</strong></td> <td align="center" style="color:#000000"><strong>F</strong></td> <td align="center" style="color:#FF0000"><strong>S</strong></td> </tr> <?php $timestamp = mktime(0,0,0,$Current_Month,1,$Current_Year); $maxday = date("t",$timestamp); $thismonth = getdate ($timestamp); $startday = $thismonth['wday']; for ($i=0; $i<($maxday+$startday); $i++) { if(($i % 7) == 0 ) echo "<tr>"; if($i < $startday) echo "<td></td>"; else if(($i-$startday+1) == $today && $thismonth['month'] == $month && $thismonth['year'] == $year) echo "<td align='center' style=\"background-color: red;\" valign='middle' height='20px'>". ($i - $startday + 1) . "</td>"; else echo "<td align='center' valign='middle' height='20px'>". ($i - $startday + 1) . "</td>"; if(($i % 7) == 6 ) echo "</tr>"; } ?> </table> </td> </tr> </table> </body> </html>
-
People don't like to download files here. You will get a faster response by posting the code inside of [ code ] ... [ /code ] blocks.
-
Wrap code in [ code ] [ /code ] blocks. It makes it easier to read. There is no way to correctly answer your question without posting your controller class and your template class.
-
Yes, that is the exact code that replaces: mysql_query("INSERT INTO data_table (user_id,user_email,user_access_token,user_access_token_expire) values ('$user_id','$email','$accessToken','$date_baza')") or die (mysql_error()); I think this problem is caused by bad coding practices, which isn't your fault (since you bought the script). Anything string that heads to the database, needs to be run through mysql_real_escape_string. If it is a float, or integer, it needs to be cast as such.
-
Problems setting up a Database on 1and1 Linux server
jcbones replied to MrTIMarshall's topic in PHP Coding Help
Visitors IP (client IP) can usually be obtained by $_SERVER['REMOTE_ADDR']; -
requinix didn't write out the exact code for you, he gave you some valuable pointers though. You need to check out foreach and echo.
- 9 replies
-
- read directory
- explode
-
(and 1 more)
Tagged with:
-
Are you using an Apache Server? Do you have mod_rewrite enabled? Have you set up "pretty URLs" in an .htaccess file?
-
To answer the question explicitly, you should have a primary key column, most people call this the id, and make it an integer auto-incremented. I'm not sure that is what your id is set up as. Then you can call any row by "WHERE id=". For pointers, your posted structure is going to limit you for future expansion (scaling). I would suggest that you normalize your database, which would include making 2 tables. 1 for events, and 1 for video's. In this way, you could have many more than 6 video's for every event, and could easily add pics, comments, or any other thing you might think of. Example: tables CREATE TABLE IF NOT EXISTS `events` ( `id` int(11) NOT NULL AUTO_INCREMENT, `title` varchar(25) NOT NULL, `description` text NOT NULL, `event_date` datetime NOT NULL, PRIMARY KEY (`id`) ); CREATE TABLE IF NOT EXISTS `videos` ( `id` int(11) NOT NULL AUTO_INCREMENT, `event` int(11) NOT NULL, `title` varchar(20) NOT NULL, `url` varchar(255) NOT NULL, PRIMARY KEY (`id`) ); Now you can access all your video's for any event, 100's if you wish. To add pictures, music, comments, etc, just add the relevant table, and join it to the events with the event to event.id column. "SELECT e.title, e.description, v.title AS vidTitle, v.url FROM events AS e JOIN videos AS v ON e.id = v.event WHERE e.id = 1";
-
The problem may not even be related to that function, it is just that on line 499 PHP ran out of memory. It could have happened anywhere between line 1 and 499. The only way to solve this, is to benchmark every function (method) until you narrow it down. Then benchmark every line in that function until you get to the one using the most offensive amount of memory. Example: UN-TESTED [code] function WorkPanel() { $start_bench = memory_get_usage(); //benchmark $count = 0; $today = date("D", $this->Day1()); $day_change= $this->StoreInfo("day_change"); $arr = array(); $hr = date("H"); $min = (date("i") < 30) ? "00" : "30"; $now = strtotime($hr .":". $min); $sql = mysql_query("SELECT " .$today. " FROM work WHERE " .$today. " != '' AND area = '" .$this->area. "'"); while($row = mysql_fetch_array($sql)) { $working_hour = explode("~", $row[$today]); $start_hour = strtotime($working_hour[0]); $end_hour = strtotime($working_hour[1]); if($working_hour[1] >= "00:00" && $working_hour[1] <= "07:00") { $mid_nght = strtotime("23:59"); for($i = $start_hour; $i <= $mid_nght; $i += 1800) $arr[] = $i; array_push($arr, $i); $over_mid_start = strtotime("00:30"); $over_mid_end = strtotime($bitis); for($i = $over_mid_start; $i <= $over_mid_end; $i += 1800) $arr[] = $i; } else { if($working_hour[1] == "00:00") $mid_nght = "23:59"; for($i = $start_hour; $i <= $mid_nght; $i += 1800) $arr[] = $i; if($working_hour[1] == "00:00") array_push($arr, $i); } if(in_array($now, $arr)) $count++; unset($arr); } echo memory_get_usage() - $start_bench; //print amount of memory this function uses. return $count; }
-
I created a new function to try and help you understand the concept. It is fully commented. Note that I left your function and calls in the script, but commented them out. I also added error_reporting to the script as well. You should really set error reporting in you php.ini though. <?php //turn on error_reporting error_reporting(-1); ini_set('display_errors',1); #tax rate is constant $price = 0; $tax = 0.08; $total_price = 0; $total_tax = 0; $shipping = 0; $total_shipping = 0; $grand_total = 0; ?><ul><?php // function tallyTotals($grand_total) { // $total_price += $price; // $total_tax += $tax * $price; // $total_shipping += $shipping * $price; // $grand_total = ($total_price + $total_tax + $total_shipping); // } ///////////////////Any variable created in a function, is only available to that function. //////////////////To get information out of a function, you must return the information. function totalPrice($price, $shipping, $percentage = FALSE) { //create new function with 3 arguments, first 2 MUST be supplied, the third is optional. if($percentage == TRUE) { //if the 3rd argument is changed to true, then run this block of code. return $price + ($price * $shipping); //and return the price + a percentage of the price for shipping charges. } return $price + $shipping; //if the shipping is not a percentage, then just add it to the price, and return the result. } $product = "Candle Holder"; $price = 11.95; $shipping = 0; //free shipping echo "<li>".$product.": $".$price; $grand_total += totalPrice($price,$shipping); //Send the arguments to the function, notice there is no 3rd argument supplied, the function will use the pre-defined FALSE. returned data will be stored in $grand_total. //tallyTotals($grand_total); $product = "Coffee Table"; $price = 99.50; $shipping = 0.10; //shipping as a percentage of price echo "<li>".$product.": $".$price; $grand_total += totalPrice($price,$shipping,TRUE); //Another call to totalPrice, this time with 3 arguments, since we need to change the shipping to a percentage by setting the 3rd argument to TRUE. //tallyTotals($grand_total); $product = "Floor Lamp"; $price = 44.99; $shipping = 0.10; //shipping as a percentage of price echo "<li>".$product.": $".$price; $grand_total += totalPrice($price,$shipping,TRUE); //same as above. //tallyTotals($grand_total); ?> </ul> <hr> <br> <B>Total (including tax and shipping): $<?php echo number_format($grand_total, 2); ?></B>