Psycho
Moderators-
Posts
12,157 -
Joined
-
Last visited
-
Days Won
129
Everything posted by Psycho
-
OK, I've tried to incorporate my script into your original script (although I really don't like the flow of the page) <?php ///:)///////////////////////////////////////////////////// // Jamroom Band-Banner Script // // Build by: Gilbert Romero // // Lizens: // // Date: today // ////////////////////////////////////////////////////// //The DB details (change to your details) $res=mysql_connect("localhost","","") or die(); mysql_select_db(""); //just a little db helper function SQLSelectRow($SQL) { $Res = mysql_query( $SQL ); if ( $Res ) { $Row = mysql_fetch_row( $Res ); return $Row; } else { return false; } } //Get the DB DATA //($Loginteile is given in the image name, first number is Login/Band ID (7_2_222_050_050.jpg)) $LoginteileRaw = explode('.', $_SERVER['PATH_INFO']); $Loginteile = explode('_', substr($LoginteileRaw [0],1)); $BandID = $Loginteile[0]; $SQL="SELECT band_name FROM jamroom_band_info WHERE band_active = '1' AND band_id = '$BandID'"; list($dbBandName) = SQLSelectRow($SQL); $dbBCA = unserialize($dbBandCounts); //BACKGROUND (the "Banner") $image_file = "wwbad2a.png"; $image = imagecreatefrompng($image_file); //FONT Types($Loginteile is given in the image name, second number (7_2_222_050_050.jpg)) //change YOURFONT to your chosen TTF fonts if ($Loginteile[1]=='1' OR !$Loginteile[1]) $fontTTF = "Friday13.ttf"; elseif ($Loginteile[1]=='2') $fontTTF = "fivecent.ttf"; elseif ($Loginteile[1]=='3') $fontTTF = "damnarc.ttf"; else $fontTTF = "/trab/jamroom/verdanab.ttf"; //TXT COLOR ($Loginteile is given in the image name, last 3 numbers RGB (7_2_222_050_050.jpg)) if ( $Loginteile[2] AND $Loginteile[3] AND $Loginteile[4] ) $TXT_color = imagecolorallocate($image, $Loginteile[2], $Loginteile[3], $Loginteile[4]); else $TXT_color = imagecolorallocate($image, 154, 180, 166); // Text Shadow color $TXT_colorShadow = imagecolorallocate($image, 0, 0, 0); //TXT SIZES $FontSmall = 2.2; //The TEXT (Infos) imagestring($image, $FontSmall, 7, 5, " $dbBCA[FAN_COUNT]", $TXT_color); imagestring($image, $FontSmall, 7, 17, " $dbBCA[sONG_COUNT]", $TXT_color); imagestring($image, $FontSmall, 7, 29, " $dbBCA[VIDEO_COUNT]", $TXT_color); imagestring($image, $FontSmall, 7, 41, " $dbBCA[PHOTO_COUNT]", $TXT_color); list($Continent,$Country)=split(":",$dbBandLocation); imagestring($image, $FontSmall, 100, 29, "$Country", $TXT_color); imagestring($image, $FontSmall, 100, 41, " $dbBandSoundslike", $TXT_color); imagestring($image, $FontSmall, 417, 41, "$Recorde", $TXT_color); //NamePosition Top $nameTop = 45; //NamePosition Left $nameMargin = 45; //Image Size $image_size = getimagesize($image_file); //Available text width $nameWidthAvail = $image_size[0] - (2 * $nameMargin); //Font size for band name $band_font=35; $font_size = $font_max_size; $text_sizes = imagettfbbox($font_size, 0, $fontTTF, $dbBandName); $text_width = ($text_sizes[2] - $text_sizes[0]); //Decrease font size until it will fit in image while ($text_width > $nameWidthAvail) { $font_size--; $text_sizes = imagettfbbox($font_size, 0, $fontTTF, $dbBandName); $text_width = ($text_sizes[2] - $text_sizes[0]); } //Center horizontally $nameLeft = ($image_size[0] - $text_width)/2; //build the Band Name (shadow) for ($ox = -2; $ox <= 2; $ox++) { for ($oy = -2; $oy <= 2; $oy++) { imagettftext($image, $band_font, 0, $nameLeft+$ox, $nameTop+$oy, $TXT_colorShadow ,$fontTTF, $dbBandName); } } //Write the band name text imagettftext($image, $band_font, 0, $nameLeft, $nameTop, $TXT_color ,$fontTTF, $dbBandName); //Set the header header("Content-type: image/png"); //DISPLAY IMAGE imagepng($image); ; //DELETE IMAGE(from server "CACHE") imagedestroy($image); ?>
-
I am assuming those IFrames are for external pages that you are trying to post the same information to. Don't use frames - use curl. You wouldn't be able to do what you are asking with PHP anyway. PHP is server-side. If the frames ahve content already loaded there is no way for PHP to interact with those pages. If they are external pages I don't think there is even a way to do it with JavaScript if you don't have access to modify those pages.
-
Checkboxes that are not checked are not included in the post data. So using a numerically indexed array as you have will not work because if the user does not check the 1st checkbox, then the 2nd checkbox (if checked) would be associated with the 1st text field. Can you not create a loop when creatingyour fields so you can specify an index: for ($i=0; $i<$max_fields; $i++) { echo "<label>200mm x 200mm</label>"; echo "<input name=\"sizes[$i]\" type=\"checkbox\" value=\"200 x 200\" checked=\"true\">"; echo "<input name=\"sprice[$i]\" type=\"text\" class=\"dropdown\"><br/>"; }
-
Check out the tutorial right on this site: http://www.phpfreaks.com/tutorial/basic-pagination
-
If I may, I will make one suggestion. Your script is only replacing "*^$%&()#@!'". What about other "odd" characters that may cause a problem? I always prefer to use a "white list" of approved characters and strip out/replace any others. But, it all depends on your usage. In some situations you may need to keep the original input in other's you don't. Here's one possibility: $_POST['title'] = "This is_a test!@#$%^&*().jpg"; //Change all spaces to underscore $file = str_replace(' ', '_', $_POST['title']); //Remove all NON a-z, 0-9, and underscores $file = preg_replace('/[^\w\.]/i', '', $file); echo $file; //Output: This_is_a_test.jpg
-
There is no loop needed. The script already loops until the test string ($found_word) is of a greater length than the word you are trying to find ($search_word). The only time it will not find the word is if it includes characters not within the search parameters - which the script also handles. However, it would be more efficient to do a simple validation of the user's word to see if it has any disallowed characters before running the loop to begin with.
-
Did you even run the script or are you saying that from just looking at it? When I run it for 'aaa' I get this result: Found your word 'aaa' in 1333 attempts And I do understand the difference between permutations and combninations. This script goes in a very systematic,logical sequence to come up will all permutations. If the code only used three letters (a, b & c) it runs in this manner a b c aa ab ac ba bb bc ca cb cc etc. Which will cover every permutation at each character count and then increases the character count by one.
-
OK, here's some working code. But beware that this is not a worthwile exercise. The number of combinations needed to find a work increases exponentially with every letter. The word 'apple' took 2,447,285 iterrations to find (and that's only because it starts with the letter a). It took so long for th eword 'house' that I gave up. Of course I didn't write this for efficiency - nonetheless it is a very intensive process. <?php if (isset($_POST['search_word'])) { $letters = array('a','b','c','d','e','f','g','h','i','j','k','l','m', 'n','o','p','q','r','s','t','u','v','w','x','y','z', '0','1','2','3','4','5','6','7','8','9'); $search_word = trim($_POST['search_word']); $found_array = array(); $found_word = ''; $found = false; while ( !$found && count($found_array)<=strlen($search_word) ) { $attempts++; $change_letter = false; //Starting from the last index (letter) check if the last letter is used //If not increase by one for ($found_idx=(count($found_array)-1); $found_idx>=0; $found_idx--) { if ($found_array[$found_idx]<(count($letters)-1)) { $found_array[$found_idx]++; $change_letter = true; //Reset remaining letters to 0 letter index for($found_idx++; $found_idx<count($found_array); $found_idx++) { $found_array[$found_idx] = 0; } break; } } //If no letters can be increased reset all to first letter and add one more if (!$change_letter) { //Reset all values to 0 letter and add 1 more foreach($found_array as $key => $value) { $found_array[$key] = 0; } $found_array[] = 0; } //Create the found word for comparisson $found_word = ''; foreach ($found_array as $letter_index) { $found_word .= $letters[$letter_index]; } //Compare with user entered value if (strtolower($found_word)==strtolower($search_word)) { $found=true; } } if ($found==true) { $result = "Found your word '$found_word' in $attempts attempts"; } else { $result = "Did not find your word. You may have used some invalid characters"; } } ?> <html> <head></head> <body> <?php echo $result; ?> <form action="" method="POST"> Your Word: <input type="text" name="search_word"><br> <button type="submit">Submit</button> </form> </body> </html>
-
I think there's a problem with the logic. I have a similar script I wrote just recently to come up with permutations for a project I am working on. Let me see if I can adapt it for your needs.
-
Well, you could have the popup page make the call to the db to get the email addresses. Not sure what criteria you may have on the main page to do that now though (although you could set those values via SESSION also). But, I think ghqwerty is right on. Sessions would be the way to go. You should build the solution so the user doesn't have to have JS enabled anyway. The only reason to use JS for a popup would be to configure the popup window. But there's no reason you couldn't use a traditional link with the target attribute. With sessions you take all the need for JS out of the problem.
-
I'm not really sure what you are tyring to accomplish, but your array is jacked up. The letters need to be enclosed in quotes.
-
Well, you're not providing all the necessary informatioin so I'll give it a shot. How does the array of email addresses exist in the original page? Is it converted to a JavaScript array? If it is you can reference javascript values on the parent page from the popup using the parent.opener.variable_name If it's in a form, as your post suggests, "how" is it in a form? Do you have multiple form fields for each email address? You could again use parent.opener to iterrate through all of those form fields. There are a lot of other possibilities based upon your actual implementation. If you have something different please post some specifics.
-
It look like all you did was tack the code I provided at the end of the code you already had?! The code I provided isn't even getting displayed becuase you have already sent the data to the browser. The logic in that code is all over the palce. Have the code build one piece of the puzzle in a logical sequence. For example the code to determine the band name font size & color comes before you put the other text on the page. I tried to rewite it to work accordingly, but since I dont have your database at my disposal I have not tested it. ///:)///////////////////////////////////////////////////// // Jamroom Band-Banner Script // // Build by: Gilbert Romero // // Lizens: // // Date: today // ////////////////////////////////////////////////////// //The DB details (change to your details) $res=mysql_connect("localhost","","") or die(); mysql_select_db(""); //just a little db helper function SQLSelectRow($SQL) { $Res = mysql_query( $SQL ); if ( $Res ) { $Row = mysql_fetch_row( $Res ); return $Row; } else { return false; } } //Get the DB DATA //($Loginteile is given in the image name, first number is Login/Band ID (7_2_222_050_050.jpg)) $LoginteileRaw = explode('.', $_SERVER['PATH_INFO']); $Loginteile = explode('_', substr($LoginteileRaw[0],1)); $BandID = $Loginteile[0]; $SQL="SELECT band_name FROM jamroom_band_info WHERE band_active = '1' AND band_id = '$BandID' "; list($dbBandName) = SQLSelectRow($SQL); $dbBCA = unserialize($dbBandCounts); //BACKGROUND (the "Banner") $image = imagecreatefrompng("wwbad2a.png"); //TXT SIZE $FontSmall = 2.2; //TXT COLOR ($Loginteile is given in the image name, last 3 numbers RGB (7_2_222_050_050.jpg)) if ( $Loginteile[2] AND $Loginteile[3] AND $Loginteile[4] ) $TXT_color = imagecolorallocate($image, $Loginteile[2], $Loginteile[3], $Loginteile[4]); else $TXT_color = imagecolorallocate($image, 154, 180, 166); //The TEXT (Infos) imagestring($image, $FontSmall, 7, 5, " $dbBCA[FAN_COUNT]", $TXT_color); imagestring($image, $FontSmall, 7, 17, " $dbBCA[sONG_COUNT]", $TXT_color); imagestring($image, $FontSmall, 7, 29, " $dbBCA[VIDEO_COUNT]", $TXT_color); imagestring($image, $FontSmall, 7, 41, " $dbBCA[PHOTO_COUNT]", $TXT_color); list($Continent,$Country)=split(":",$dbBandLocation); imagestring($image, $FontSmall, 100, 29, "$Country", $TXT_color); imagestring($image, $FontSmall, 100, 41, " $dbBandSoundslike", $TXT_color); imagestring($image, $FontSmall, 417, 41, "$Recorde", $TXT_color); //FONT Types($Loginteile is given in the image name, second number (7_2_222_050_050.jpg)) //change YOURFONT to your chosen TTF fonts if ($Loginteile[1]=='1' OR !$Loginteile[1]) $fontTTF = "Friday13.ttf"; elseif ($Loginteile[1]=='2') $fontTTF = "fivecent.ttf"; elseif ($Loginteile[1]=='3') $fontTTF = "damnarc.ttf"; else $fontTTF = "/trab/jamroom/verdanab.ttf"; // Text Shadow color $TXT_colorShadow = imagecolorallocate($image, 0, 0, 0); //Name max font size $font_max_size = 35; //Angle of name text $angle = 0; //NamePosition Top $y_position = 45; //Left and right margins $x_margins = 100; //NamePosition Left $image_size = getimagesize("wwbad2a.png"); $x_width = $image_size[0] - (2 * $x_margins); $font_size = $font_max_size; $text_sizes = imagettfbbox($font_size, $angle, $fontTTF, $dbBandName); $text_width = ($text_sizes[2] - $text_sizes[0]); while ($text_width > $x_width) { $font_size--; $text_sizes = imagettfbbox($font_size, $angle, $fontTTF, $dbBandName); $text_width = ($text_sizes[2] - $text_sizes[0]); } //Center horizontally $x_position = ($image_size[0]-$text_width)/2; imagettftext($image, $font_size , $angle, $x_position, $y_position, $text_color, $fontTTF, $band_name); //Set the header header("Content-type: image/png"); //DISPLAY IMAGE imagepng($image); ; //DELETE IMAGE(from server "CACHE") imagedestroy($image
-
So, do you still want help with this or what? Post the code you have. The code I posted worked perfectly for me, so there's probably just something with your implementation that needs correcting.
-
So is that what you want? It looks like there is a letter at the very end that supposed to start a new word, so I'm guessing not. Post the current code if you want help.
-
Here's a quick script that will reduce the font so the text will fit within the image width (including defined margins) and will also center the text. The result seems to be a little off center to the right. Not sure why and I need to get back to work so I don't have time to investigate further. Adding a space to the end of the text makes it look better for a quick fix. $image = imagecreatefrompng("wwbad2a.png"); $image_size = getimagesize("wwbad2a.png"); $fontTTF = "verdanab.ttf"; $text_color = imagecolorallocate($image, 255, 255, 255); $font_max_size = 35; $angle = 0; $x_position = 20; $y_margins = 30; $y_width = $image_size[0] - (2 * $y_margins); $band_name = "Michael"; $font_size = $font_max_size; $text_sizes = imagettfbbox($font_size, $angle, $fontTTF, $band_name); $text_width = ($text_sizes[2] - $text_sizes[0]); //Decrease font size until it will fit in image while ($text_width > $y_width) { $font_size--; $text_sizes = imagettfbbox($font_size, $angle, $fontTTF, $band_name); $text_width = ($text_sizes[2] - $text_sizes[0]); } //Center horizontally $y_position = ($image_size[0] - $text_width)/2; imagettftext($image, $font_size , $angle, $y_position, 250, $text_color, $fontTTF, $band_name); //Set the header header("Content-type: image/png"); //DISPLAY IMAGE imagepng($image); ; //DELETE IMAGE(from server "CACHE") imagedestroy($image);
-
[Help] Creates new page overwrites previous.
Psycho replied to David And Evan's topic in PHP Coding Help
Well, your query grabs every record from the business table and creates a file for each. I see nothin in the script that would restrict it to updating only 1 ID. here is your script with some logical spacing and comments added with some lines left out for clarity. //Select every record from the business table $data = mysql_query("SELECT * FROM business"); //Go through each record in the result set. while($info = mysql_fetch_array( $data )) { //Create body content and write to new file--FOR EACH RECORD ID $body_content="<html>"; echo $body_content; // Store some text to enter inside the file $file_name = "ads/".$info['ID'].".php"; $fp = fopen ($file_name, "w"); fwrite ($fp,$body_content); fclose ($fp); // closing the file pointer chmod($file_name,0777); // changing the file permission. } If you only want it to update the file for record ID 5 you need to have some logic to handle that. -
Here is an existing PHP OCR class that may be a good starting point for you. http://www.phpclasses.org/browse/package/2874.html
-
The query WILL get all the results for all songs. You just need to loop through all of the results like WildTeen showeed above (although he used the wrong variable name which might have confused you). $query = "SELECT songID, COUNT(songID) as count FROM vote GROUP BY songID ORDER BY COUNT(songID) DESC"; $result = mysql_query($query) or die (mysql_error()); echo "<table border=\"1\">\n"; echo "<tr><th>ID</th><th>Count</th></tr>\n"; while ($record = mysql_fetch_assoc($result)) { echo "<tr><th>{$record['songID']}</th><th>{$record['count']}</th></tr>\n"; } echo "</table>\n";
-
SELECT songID, COUNT(songID) as count FROM vote GROUP BY songID
-
Since client.php is using a random number there is no way for server.php to determine if the value sent was a legitimate value or a made up one. server.php needs to validate the key against something. Not sure what you are really trying to accomplish here. If client.php and server.php are on the same server, then client.php could save a value to the database and server.php could validate the value against that.
-
Hell, I thought that there "should" be such a function but couldn't find it when I did a quick search through the manual and through Google.
-
Here's an article on how to center text in an image (which includes a section on determining the length of text in an image). http://www.bitrepository.com/web-programming/php/how-to-center-a-text-on-an-image-using-gd.html However, I question the validity of imagefontwidth() to determine the width of a string of text. imagefontwidth() only takes one parameter (the font size). So while it would work fine for a fixed-width font such as courier, I don't see how it could work for a non fixed-width font such as times.
-
<?php if((isset($_SESSION['one_to_many_input_choice']) && ($_SESSION['one_to_many_input_choice'] == "one_by_one"))) { // IF 27 $body_onload = ' onload="one_to_many_show_recipient_list();"'; $input_onkeyup = ''; } else { $body_onload = ''; $input_onkeyup = ' onkeyup="one_to_many_show_recipient_list();"'; } ?> <html> <body<?php echo $body_onload; ?>> <input name="number_of_recipients" id="number_of_recipients"<?php echo $input_onkeyup; ?> /> </html>
-
Hmm, you are defining checkTime() inside of startTime(). So it is getting redefined everytime startTime() is run. It should be moved outside of that function. There's also a more efficient way of doing that in my opinion. 1. To determine AM/PM you just need to determine if the original hours variable is less than 12. If so, the value is AM, else it is PM var am_pm = ( h < 12 ) ? 'am' : 'pm'; To determine the server time you will need to use server-side code to generate an offset to use on the page. I would use the 24 hour value for that purpose. Full code with some modifications: <html> <head> <script type="text/javascript"> var clientTime = new Date(); var clientHours = clientTime.getHours(); var serverHours = <?php echo date('H'); ?>; var serverOffset = clientHours - serverHours; function startTime() { var today = new Date(); var h = today.getHours() - serverOffset; var m = padZero(today.getMinutes()); var s = padZero(today.getSeconds()); var am_pm = ( h < 12 ) ? 'am' : 'pm'; if (h > 12) { h = h-12; } if (h == 0) { h = 12; } document.getElementById('txt').innerHTML=(h+':'+m+':'+s+' '+am_pm); t=setTimeout('startTime()', 500); } function padZero(numStr) { numStr = '0' + numStr; return numStr.substr(numStr.length-2); } </script> </head> <body onload="startTime()"> <div id="txt"></div> </body> </html>