PHP - Help - Variable Keeps Resetting - Dynamic Text
Hello,
I'm working on a dynamic text form (I guess thats what its called). Basically, I have a html page that echos in some PHP code. What the PHP code does is show different strings of text depending on a variable: Code: [Select] <PHP? $brief1_info = "brief info goes here"; $brief1 = 0; if (isset($_POST['brief1Go'])) { $brief1 = $brief1 + 1; } else if (isset($_POST['brief1Back'])) { $brief1 = $brief1 - 1; } $breif1Controller = " <form action=\"".$_SERVER['PHP_SELF']."\" method=\"post\"> <input type=\"submit\" name=\"brief1Back\" id=\"brief1Back\" value=\"BACK\" /> </form> <form action=\"".$_SERVER['PHP_SELF']."\" method=\"post\"> <input type=\"submit\" name=\"brief1Go\" id=\"brief1Go\" value=\"CONTINUE\" /> </form>"; if($brief1 == 0){ $brief1_info = "<b>Welcome Commander,</b> you are currently viewing the Mission Control Brief page, here you can view all your missions that you need to complete in order to advance through your prestiges. You will need to follow your briefs carefully in order to succeed. <br /><br /> "; } else if($brief1 == 1){ $brief1_info = "Okay, let me show you around the place ..."; } else if($brief1 == 2){ $brief1_info = "brief is on 2"; } ?> The problem is, the BACK and CONTINUE buttons don't work. If $brief1 equals 0, and the user presses continue, the is should go to 1, and the brief1_info string is changed (so some different text shows in my html). It actually works when brief1 is on '0', but when its on 1 and the user pressed continue, the brief1 is changed to 1, but because the submit button refreshes the page, the variable is re-read again, and thus is reset back to 0. Is there a way around this? Or is there a better method than what I'm doing? Thanks Similar TutorialsHi, I think this is probably a logical error rather than a syntax one I have a function that displays the first image in a photo album in large and all the photos in it as thumbnails. I have a next and previous button that allows you to scroll through them (in large) and by clicking a specific thumbnail you can load that picture in large. My problem is that the pictures are stored in an array and the one to be shown large is selected by $keyid. My problem is that selecting a thumbnail resets the $keyid so that clicking next doesn't load the next image but the second. i.e. if you press the next arrow then click the 4th thumbnail and then click the next arrow again it loads the 2nd picture rather than the 5th as it should. How can I avoid this happening? This is my code: generateThumbnails(); $act = 0; $keyid = (isset($_GET['keyid']) ? $_GET['keyid']:'0'); $Picturecount = (count(glob("" . $dir . "*.jpg")))/2; $thumb_selected = (isset($_GET['thumb']) ? $_GET['thumb']:''); $picture_array = glob("$dir*"); if ($thumb_selected !==""){ $dirName = substr($thumb_selected,0,strpos($thumb_selected,basename($thumb_selected))); $thumbName = basename($thumb_selected); $thumbFile = $dirName.$thumbName; $selected = str_replace('_th.jpg','.jpg',$thumbFile); foreach ($picture_array as $search){ $keyid = array_search($selected,$picture_array); $large = $picture_array[$keyid]; }} else{ if($keyid > (2*$Picturecount-1)){ $keyid = ($keyid - (2*$Picturecount));} if($keyid < 0){ $keyid = (2*$Picturecount+$keyid);} $large = $picture_array[$keyid];} echo " <tr><td><a href='?album=$album&keyid=" . ($_GET['keyid']-2) . "'>Previous</a></td><td></td><td align='right'><a href='?album=$album&keyid=" . ($_GET['keyid']+2) . "'>Next</a></td></tr> <tr><td colspan='3' height='300' width='400' align='center'><img src='$large' alt=''></td></tr><tr><td height='50'></td></tr>"; Any help would be massively appreciated. Thanks very much! Folks, I need help (Php code ) to generate a Dynamic Text on a Base Image. What i want to do is, to make this Image as header on my Site and to make this Header Specific to a Site, i want to Add the Domain Name on the Lower Left of the Image. Got the Idea? Here is the Image link: Quote http://img27.imageshack.us/i/shoppingheader1.jpg/ PHP Variable that holds the Domain name is: $domain All i need the Dynamic PHP Codes that i can put on all my sites to generate this Text on Image (Header) Dynamically... May Anyone Help me with this Please? Cheers Natasha T. Hi ! I'd like to count all occurences in "$thiscodestring" into a "dynamic?" array and print it out after the end of the loop, how do I assign the variablenames dynamically ? $query = "SELECT codes, status FROM table"; while ($row = mysql_fetch_assoc($result)) { $thiscodestring = $row[codes]; // looks like "a1 c2 d3 10 15 1 a1 a1"; $singlecodes = explode(" ", $thiscodestring); foreach($singlecodes as $thiscode) { $$thiscode[count] = $$thiscode[count] + 1; } } After all Mysql-Stuff is done I'd like to print out the counted codes, for example the code "a1" was found 100 times in all querys then $$a1[count] should be 100, c2 was found 15 times, then $$c2[count] should be 15 and so on. Question: How do I tell php to assign a "dynamic" variable with the name of the found string which was exploded (in this example a1, c2, d3... ) before ?! $$ does not seem to work. And how can I then print_r() the value if I dont know the name ? Thanks ! <?php $foo = 5; $too = 7; ${"foo"}++; ${"too"}++; echo $foo; echo '<br />' . $too; $my_var_name = "foo"; ${$my_var_name}++; echo $foo; ?> I understand the part that $my_var_name is going to increment $foo. But I don't understand that when we used ${"foo"} we did not add the $ sign with it. But when we use ${$my_var_name} we have to add another $ sign. why is that? I have a form that inserts information into a mysql, the only prolem is I need to add different surrounding html to the information when entering it into the database depending what the value is...(essentially I want to store font color around different levels) How would I define the same variable with different information depending on the value? The information is called using: if ($_SERVER['REQUEST_METHOD'] == 'POST') { $editLEVEL=$_POST['level']; I want it so if 'Level1' is the posted value then $editLEVEL would be '<color=1>$editLEVEL</color>' but if 'Level2' is the posted value the $editLEVEL would be '<color=2>$editLEVEL</color>' If you dont understand just let me know I'll try explain best I can. OK, what I am trying to do is generate a dynamic variable name. I want to setup a foreach statement that will generate variable names based on an array of data. $numbers = array('one', 'two', 'three', 'four', 'five', 'six', 'seven'); foreach ($numbers as $number) { } What I need, is for a bunch of variables to be generated and filled with content. $variable_one_label = "Blah"; $variable_two_label = "Blah Again"; How can I generate the dynamic variable based on the array value? Hello. I want to create some variables dynamically. I have this so far: for($i = 1; $i <= 4 ; $i++){ $a = 'member' . $i; $$a = array(); } Does that give me this 4 arrays?: $member1, $member2, $member3 and $member4? Of course I want some process inside of the loop, but that would depend on the variables. Would that work? thanks! hi guys I just could not find the answer on forum. I have a url like this http://www.example.com/deal.php?id=367 and my question is : how can i use curl function to get the html and the id value which is 367 thanks Hi I'm trying the following code: Code: [Select] $t = '12<-- AB_C -->'; $AB_C = 'abc'; echo preg_replace('/\<-- ([A-Z_]+) --\>/', "$$1", $t);I want to get "12abc" , but it outputs: 12$AB_C , so, it not recognize the replacement as dynamic variable. Is it any way to use the matched word in preg_replace() as a variable, or dynamic variable? Hi all, here's my code: Code: [Select] <?php foreach ($_SESSION['topping'] as $value) { echo "<tr><td width='30%'>Topping</td><td width='50%'>$value</td><td width='20%'><select name='notopping'>"; foreach ($_SESSION['cupcake'] as $number) { '<option name="notoppings[]" value="'.$number.'">".$number."</option>'; } echo "</select></td></tr>"; } ?> $_SESSION['cupcake'] is a value from either 6, 12, 24 or 36. What I want to do is put them into a drop down box (second foreach) as the value and the displayed value - counting up from 1 (so 1,2,3,4,5,6 or up to 12,24 etc). Also by creating this as an array, does this mean than for each topping (say Vanilla and Chocolate) the value dynamically created can be used on the next page by using $_POST['notoppings'] to display each type (two different numbers - one for Vanilla and one for Chocolate). Does that make sense? Thanks! Jason Hi there. How do I reflect the text content of the variable $a in this text form: <input type="text" name="artist"> Regards Morris Hi All, i am trying to Generate a image dynamically. Up to here i am able to do it . But when i give any echo statement with this its not working.. Here is my code pls help me in this <?php // Create a 55x30 image $im = imagecreatetruecolor(79, 79); $unknow = imagecolorallocate($im, 0, 255, 255); $white = imagecolorallocate($im, 255, 255, 255); // Draw a white rectangle imagefilledrectangle($im, 4, 4, 75, 25, $unknow); imagefilledrectangle($im, 4, 29, 75, 50, $unknow); imagefilledrectangle($im, 4, 54, 75, 75, $unknow); // Save the image echo 'hi hello'; header("Content-type: image/png"); //imagepng($im, './imagefilledrectangle.png'); imagepng($im); imagedestroy($im); ?> Thanks in advance. I have a form that you can add email boxes and recipients to. when you add the boxes it actually submits. I did it this way to change the session that determines how many boxes you get. The problem is if I (as a web user) have entered X number of emails and recipients then submit to add another set of text fields then how can I keep the 3 already entered populated? <?php $start = $_SESSION['NOCStart']; $stop = $_SESSION['NOCStop']; for($m = $start; $m < $stop; $m++){ echo " <tr> <td>$m: <input id='text' type='text' name='invEmail[]' value='WHATS GOES HERE??' /></td> <td><input id='text' type='text' name='invName[]' value='WHATS GOES HERE??' /></td> </tr> "; } ?> The submitted info is captured with the following code: For testing it simply outputs the info... if (isset($_SESSION['NOC']) && $current_page == "invitations.php"){ if(isset($_POST['addemail'])){ $impEmail = implode(",", $_POST['invEmail']); $expEmail = explode(",", $impEmail); $impName = implode(",", $_POST['invName']); $expName = explode(",", $impName); $sendit = array_combine($expEmail, $expName); foreach ($sendit as $key => $value) { echo "$key belongs to $value<br />\n"; } if ($_SESSION['NOCStop'] == $_SESSION['NOC'] + 1){ $message = "<script>alert('Max Emails Reached')</script>"; }else{ $_SESSION['NOCStart'] = 1; $_SESSION['NOCStop'] = $_SESSION['NOCStop'] + 1; } }else{ $stopper = $_SESSION['NOC'] * .5; $rounder = round($stopper) + 1; $_SESSION['NOCStart'] = 1; $_SESSION['NOCStop'] = $rounder; } } Thank you for your help! I'm having trouble with some foreach statements. I'm pretty sure I've narrowed it down to one foreach statement. Not sure where to go from here. Code: [Select] // output column headers $rows=1; $cols=0; foreach ($colarr as $col){ //echo "<pre>"; print_r($col); echo "</pre>"; $text=str_replace("<br>", "\r\n", $col['desc']); $objPHPExcel->getActiveSheet()->SetCellValue($xlcols[$cols].$rows, $text); $objPHPExcel->getActiveSheet()->getStyle($xlcols[$cols].$rows)->getAlignment()->setWrapText(true); $objPHPExcel->getActiveSheet()->getStyle($xlcols[$cols].$rows)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT); $cols++; } $rows++; // output data rows if (isset($apptable['retarr']) && isset($apptable['retarr']['rs']) && count($apptable['retarr']['rs'])>0){ foreach ($apptable['retarr']['rs'] as $row=>$r){ if (is_numeric($row)){ //echo '<pre>'.print_r($apptable).'</pre>';//exit; $cols=0; foreach ($r as $col=>$c){ if (isset($colarr[$col])){ //echo '<pre>'.print_r($colarr[$col]).'</pre>';//exit; //echo "this is xlcols: ".$xlcols[$cols].$rows; echo " "; //echo "This is col: ".$col; echo " "; //echo "This is r[col]: ".$r[$col]; echo "<br>"; $objPHPExcel->getActiveSheet()->SetCellValue($xlcols[$cols].$rows, $r[$col]); $objPHPExcel->getActiveSheet()->getStyle($xlcols[$cols].$rows, $r[$col])->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT); $cols++; } } $rows++; } } } The first section (output column headers) prints column names to an excel spreadsheet. The next part (output data rows) puts the data in an excel spreadsheet. The problem I have is that the data rows don't match the header columns. I think this is because the array $colarr is not after the first foreach loop. I've tried to reset, asort, and sort to move it back to the beginning, but none of those worked. And this $reset_array_keys = array_values($numerically_indexed_array); Any suggestions on what I should do? Output of print_r($colarr[$col]). Code: [Select] Array ( [dbcolumn] => tr_ngfg_statement_date [desc] => Ngfg Statement Date [align] => l [format] => [pdfalign] => L [pdfwidth] => [ajaxupdate] => y [ajaxdropdown] => [sort] => y [link] => [options] => [fttype] => none ) 1 Array ( [dbcolumn] => tr_transaction_reconciled_y_or_n [desc] => Reconciled [align] => l [format] => [pdfalign] => L [pdfwidth] => [ajaxupdate] => [ajaxdropdown] => [sort] => y [link] => [options] => [fttype] => none ) 1 Array ( [dbcolumn] => tr_priority_level [desc] => Priority Level [align] => l [format] => [pdfalign] => L [pdfwidth] => [ajaxupdate] => y [ajaxdropdown] => [sort] => y [link] => [options] => [fttype] => none ) 1 Array ( [dbcolumn] => tr_id [desc] => ID [align] => l [format] => [pdfalign] => L [pdfwidth] => [ajaxupdate] => [ajaxdropdown] => [sort] => y [link] => [options] => [fttype] => none ) 1 Array ( [dbcolumn] => tr_decisioned_date [desc] => Decisioned Date [align] => l [format] => [pdfalign] => L [pdfwidth] => [ajaxupdate] => [ajaxdropdown] => [sort] => y [link] => [options] => [fttype] => none ) That's really the only way i can categorize this particular question. I have a site loading a form into an iframe. probably not the smartest thing to do but I've built a one-page portfolio site that scrolls to each anchor point with the scrollTo script. None the less, my form loads into my frame. I started thinking about usability and how odd it might be to a non-techie, non-webby visitor to go to the form, submit and then maybe want to send another message. Although not very probable, it's the stuff we don't anticipate happening that usually gets us in deep. Really, what I'm looking for is something where after the visitor submits the form and it says "thank you for sending us an email" that it would either automatically reset my index page OR give the visitor the option of manually resetting the page. my form Code: [Select] <form method="POST" action="mailer.php"><br /> Name:<br /> <input type="text" name="name" size="50"><br> <br /> E-Mail:<br> <input type="text" name="email" size="50"><br> <br /> Comments:<br> <textarea wrap="soft" rows="5" name="message" cols="48"></textarea> <br> <br> <input type="submit" value="Submit" name="submit"> </form> php script Code: [Select] <?php if(isset($_POST['submit']) || isset( $_POST['submit_x'] )) { $to = "email@mydomain.com"; $subject = "Contact from a visitor"; $name = $_POST['name']; $email = $_POST['email']; $message = $_POST['message']; $body = "From: $name\n E-Mail: $email\n Message:\n $message"; echo "Your email has been sent to $to!"; mail($to, $subject, $body); } else { echo "blarg!!!"; } ?> Hi there, I have a simple question - is it possible to send out an html email containing PHP/MySQL code so that when the user receives the email it checks the date and serves up content from a database? I have created a page that works fine online, but when I try to email the page, it doesn't work from within the user's email client (such as outlook, or gmail). When I look at the raw email source, it looks like the PHP code isn't getting executed by the email program. If anyone knows a reason or workaround, I would appreciate it! Thanks in advance, Rick Code: [Select] <?php $day = date("Y-m-d"); // Connects to your Database mysql_connect("empowermentoftheday.com", "username", "password") or die(mysql_error()) ; mysql_select_db("etd_emails") or die(mysql_error()) ; if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $query = sprintf("SELECT * FROM daily WHERE date = '%s'", mysql_real_escape_string($day)); // Perform Query $Recordset1 = mysql_query($query); // Check result // This shows the actual query sent to MySQL, and the error. Useful for debugging. if (!$Recordset1) { $message = 'Invalid query: ' . mysql_error() . "\n"; $message .= 'Whole query: ' . $query; die($message); } $row_Recordset1 = mysql_fetch_assoc($Recordset1); $totalRows_Recordset1 = mysql_num_rows($Recordset1); ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="description" content="Free inspirational Picture of the Day as well as a Free daily Wellness Break. Start your day off right and Empower Yourself Today. Empowerment of the Day is meant to inpire you each and every day and is brought to you by the Remakable Success Group Team.Empower Yourself Today." /> <meta name="keywords" content="inspirational quote, picture of the day, wellness quote, inspirational saying, inspirational story, today's wellness break, empowerment, empower yourself, empowerment of the day, health tip, wellness tip" /> <title>Empowerment Of The Day</title> </head> <body marginheight="0" marginwidth="0" topmargin="0" leftmargin="0"> <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td width="100%" align="center"> <div style="background:#DBAE13"> <img src="http://www.empowermentoftheday.com/email/images/header.jpg" alt="Empowerment of the Day" width="650" height="77" /></div> <div> <table width="650" border="0" cellpadding="0" cellspacing="0"> <tr> <td align="center" valign="middle"><img src="http://www.empowermentoftheday.com/email/images/message2.jpg" alt="Picture of the Day" width="306" height="34" vspace="15" /></td> </tr> <tr> <td align="center" valign="middle"> <table border="0" cellspacing="0" cellpadding="5" bgcolor="#000000"> <tr height="10px"> <td height="10px"></td> <td height="10px"></td> <td height="10px"></td> </tr> <tr> <td> </td> <td><img src="http://www.empowermentoftheday.com/email/images/photos/<?php echo $row_Recordset1['photo']; ?>" alt="Picture of the Day" /></td> <td> </td> </tr> <tr> <td> </td> <td align="center"> <div><font color="#FFFFFF" face="Helvetica, Arial, sans-serif"><?php echo $row_Recordset1['quote']; ?></font></div> </td> <td> </td> </tr> </table> </td> </tr> <tr> <td align="center" valign="middle"> <img src="http://www.empowermentoftheday.com/email/images/message3.jpg" alt="Today's Wellness Break" width="360" height="44" vspace="15" /></td> </tr> <tr> <td align="center" valign="middle"><p><font color="#000000" face="Helvetica, Arial, sans-serif"><?php echo $row_Recordset1['wellness']; ?><br> <br> </font></p></td> </tr> </table> <script language="JavaScript1.2" type="application/javascript"> /* Disable right click script II (on images)- By Dynamicdrive.com For full source, Terms of service, and 100s DTHML scripts Visit http://www.dynamicdrive.com */ var clickmessage="Right click disabled on images!" function disableclick(e) { if (document.all) { if (event.button==2||event.button==3) { if (event.srcElement.tagName=="IMG"){ alert(clickmessage); return false; } } } else if (document.layers) { if (e.which == 3) { alert(clickmessage); return false; } } else if (document.getElementById){ if (e.which==3&&e.target.tagName=="IMG"){ alert(clickmessage) return false } } } function associateimages(){ for(i=0;i<document.images.length;i++) document.images[i].onmousedown=disableclick; } if (document.all) document.onmousedown=disableclick else if (document.getElementById) document.onmouseup=disableclick else if (document.layers) associateimages() </script> </div> <div style="background:#D0A615"> <img src="http://www.empowermentoftheday.com/email/images/footer.jpg" alt="Copyright 2010 Remarkable Success Group Inc. Design by Ortega.ca" width="650" height="74" border="0" usemap="#Map" /> <map name="Map"><area shape="rect" coords="456,28,617,55" href="http://www.ortega.ca" alt="Design by Ortega.ca" target="_blank"></map> </map></div> <!-- GOOGLE ANALYTICS --> <script type="text/javascript"> var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-2910054-6']); _gaq.push(['_trackPageview']); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })(); </script> </td> </tr> </table> </body> </html> <?php mysql_free_result($Recordset1); ?> I am looking for a dynamic image script that handles word wrapping and possible font resizing. Basically, I have a dimensions, a font and a company name. So, lets say I am trying to make a 300x300 image for Bob's Boats in verdana. I want a script that not only creates the image, but tries to use up the available space (putting each word on a line, using a large font, horizontally and vertically aligning everything) Worst case I'll write my own, but the algorithm seems pretty complex. For example, lets say the companies name was: Chocolates in a Basket, it could be: Chocolates in a Basket Or: Chocolates in a Basket But never: Chocolates in a Basket Worst case, I might make it so that it supports 3 lines, but only ever puts the company name on 2 by default, and if the user wants to manually change it, they can. Even that isn't perfect though, because if the dimensions are something like 300x35, you wouldn't want a second line, let alone a 3rd. I am not very advanced in web programming I need help..
I am using an API and my sql database. I would to implement live/ dynamic updates in the text field where user will input their text, and the web should first check the database then the api live. I would also like to retrieve the user input without refreshing the page, so the retrieved information regarding the inputted text should be automatically loaded without refreshing the page.
please help .
Hi guys, Here is what I have so far: http://www.autoshopgarage.com/new-era/generate.php What I am trying to do is instead of having Line 1 and Line 2, I want to just have one big textarea so I don't have to limit the user so much. I did it this way because I want to have two versions of text, the light version and the bold version. Is it possible to have two different fonts with just one textarea of text? Right now I have two functions: Quote ImageTTFText($image, $fontSize, $fontRotation, 435, 80, $color, $font1, wordwrap($first, 18, "\n", true)); ImageTTFText($image, $fontSize, $fontRotation, 485,120, $color_black, $font2, wordwrap($last, 18, "\n", true)); So I would limit that to just 1, and it would automatically wordwrap but what would I put for the $font variable? Is this even possible? I was thinking of just using BBCode so they could type in [b*]Bold Text[/b*] and it would use the Bold version of the font if it sees that. Any help is appreciated. Thanks! Here is the full code: Quote <?php $first = $_GET['first']; $last = $_GET['last']; $font_color = $_GET['color']; header("Content-type: image/png"); $image = imagecreatefrompng ( "banner_blank.png" ); $color_black = imagecolorallocate($image, 0, 0, 0); $color_red = imagecolorallocate($image, 255, 0, 0); if($font_color == "Red") { $color = $color_red; } elseif($font_color == "Black") { $color = $color_black; } $font1 = 'HelveticaNeueLTStd-BdEx.ttf'; $font2 = 'HelveticaNeueLTStd-LtEx.ttf'; $fontSize = "21"; ImageTTFText($image, $fontSize, $fontRotation, 435, 80, $color, $font1, wordwrap($first, 18, "\n", true)); ImageTTFText($image, $fontSize, $fontRotation, 485,120, $color_black, $font2, wordwrap($last, 18, "\n", true)); imagepng ( $image ); imagedestroy ( $image ); ?> I want to add some text between dynamic text like in newspapers but i don't know how to do that. |