PHP - Resetting Arrays?
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 ) Similar TutorialsThat'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, I have a battle script that has a monster and player fighting. The hit points keep resetting on both characters. I set my session variables in intro.php, and included a session_start(); on the pages leading up to my main battle page. I set the array names of both $monster stats and $player stats to $_SESSION variables and initialized them on a separate page before the main page. My monster and players hitpoints keep resetting so no one dies. Any help GREATLY appreciated. Thanks. Derek here is the intro page where I initialize the stat session variables. Code: [Select] <?php //include("connect1.php"); session_start(); // include('bouncer_final.php'); //include("bouncer.php"); // kicks the person off if session is not set, its the bouncer, big and fat man. $_SESSION['charname']=''; $_SESSION['player']['stats']['playerHP'] = 100; $_SESSION['player']['stats']['playerMana'] = 100; $_SESSION['player']['stats']['playerDmgLow'] = 1; $_SESSION['player']['stats']['playerDmgHigh'] = 10; $_SESSION['player']['stats']['playerHitRollLow'] = 1; $_SESSION['player']['stats']['playerHitRollHigh'] = 20; $_SESSION['player']['stats']['playerDefense'] = 5; $_SESSION['player']['stats']['Teardrop_Ocean_Protectors'] = 3; $_SESSION['monsters']['Ocean']['octalisk']['exp']=10; $_SESSION['monsters']['Ocean']['octalisk']['mana']=100; $_SESSION['monsters']['Ocean']['octalisk']['hp']=100; /* End */ ?> here is the main battle page where all my battle coding goes on, and I declare the session variables equal to my array names near the top . Code: [Select] <?php session_start(); // include("connect1.php"); //include('bouncer_final.php'); // include('frames/encounters.php'); require_once("shoutbox/dbconnect.php"); // include("bouncer.php"); // kicks the person off if session is not set, its the bouncer, big and fat man. //turned these off while we are developing // ini_set('display_errors',1); //error_reporting(E_ALL|E_STRICT); //or if you only want to see Warning Messages and not Notice Messages: //ini_set('display_errors',1); error_reporting(E_ALL); //and if you just want all Error Reporting off, simply use this: //error_reporting(0); // error_reporting (E_ALL ^ E_NOTICE); //declare vars //$oceanBackground='';//we dont need this because it's bad practice and its already set in the program. $player=''; $monsters=''; $_SESSION['player'] = $player;// set this right after they log in, run this once, eventually in database. $_SESSION['monsters']=$monsters; $currentMonsterLevel='';//get rid of this eventually and put in session variable cuz we use it on other pages. $currentPlayerLevel=''; $error=''; $playerHp='';//get rid and make session var. $monsterHp=''; $echoPlayerMana=''; $echoMonster=''; $echoSpell=''; $player=''; $monsters=''; $playerMessage=''; $monsterMessage=''; $currentPLayerLevel =''; function encounter($monsterSeeInvis,$monsterAggro, $playerFaction) { if($monsterSeeInvis==true && $monsterAggro==true || $playerFaction<5) { return true;//return yes, for attack function } else { return false; } } function monsterAttack($currentMonster,$hitRollLow,$hitRollHigh,$dmgLow,$dmgHigh,$playerDefense, &$playerHp) { $monsterRoll= rand($hitRollLow, $hitRollHigh); if($monsterRoll>=$playerDefense) { $monsterDamage= rand($dmgLow,$dmgHigh); $monsterMessage = "You have been hit by a ". $currentMonster." for "."<strong>". $monsterDamage."</strong> points of damage!"; $playerHp= $playerHp- $monsterDamage; $monsterMessage.=" your hp is now ".$playerHp; } else { $monsterMessage= " the ".$currentMonster." missed you!<br />"; } return $monsterMessage; } function playerAttack($currMonster,$playerHitRollLow,$playerHitRollHigh,$playerDmgLow,$playerDmgHigh,$monsterDefense, &$monsterHp,$playerFaction,$playerMana) { $playerRoll= rand($playerHitRollLow, $playerHitRollHigh); if($playerRoll>=$monsterDefense) { $playerDamage= rand($playerDmgLow,$playerDmgHigh); $playerMessage = "You have hit a ". $currMonster." for "."<strong>". $playerDamage."</strong> points of damage!"; $monsterHp= $monsterHp- $playerDamage; $playerMessage.=" The ".$currMonster."'s hp is now ".$monsterHp; if($monsterHp<=0) { if($playerFaction<=0) { $playerMessage="Your faction standing with ".$playerFaction. "could not possibly get any worse."; } $playerMessage.=" You have killed the ".$currMonster. "Your faction standing with ".$playerFaction." is now ".$playerFaction-1; } } else { $playerMessage; //WTF i dont know what im doing. $playerMessage= " Whoa! You missed the ".$currMonster; } return $playerMessage; } //ini_set('display_errors',1); //error_reporting(E_ALL); $spells = array ( "red" => "red", "green"=>"green", "blue" =>"blue" ); ////////////////////////////////////////////////////////////// $player = array ( 'inventory'=>'', 'spells'=>'', 'stats'=> array ( 'int'=>16, 'playerHp'=>100, 'playerMana'=>100, 'playerDmgLow'=>1, 'playerDmgHigh'=>10, 'playerHitRollLow'=>1, 'playerHitRollHigh'=>20, 'playerDefense'=>5, 'Teardrop_Ocean_Protectors'=>3 ), 'armor'=> array ( 'shield'=>'gold' ), 'weapons' =>array ( 'sword'=>'silver' ) , 'faction'=> array ( 'Teardrop_Ocean_Protectors'=>3 //zero means the worst faction you can have, 10 being best , 5 being indifferent. ) ); /////////////////////////////////////////////////////////////// $monsters = array ( 'Ocean'=>array ( 'octalisk'=>array ( 'name'=>'octalisk', 'hp'=>100, 'exp'=>10, 'mana'=>100, 'dmgLow'=>1, 'dmgHigh'=>10, 'seeInvis'=>true, 'aggro'=>true, 'defense'=>5, 'faction'=>'Teardrop_Ocean_Protectors', 'hitRollLow'=>1, 'hitRollHigh'=>20), 'shark' , 'eel' ), 'Desert'=>array ( 'sand_snake' ), 'Forest'=>array ( 'frog', 'lizard', 'spider' ) ); //*/IF ATTACK BUTTON PRESSED, INCLUDE ENCOUNTERS FILE WHICH HAS THE BATTLE FUNCTION AND RUN IT /*if(!empty($_POST['attack'])) { include('frames/encounters.php'); battle(); }*/ $currentMonster='octalisk'; ///////////////////////////////////////////////////////////battle//////////////////////////// //function monsterEncounter($echoMonster,$monsterImage) if(!empty($_POST['attack'])) { $echoMonster="<img src='sundragon_monsters_source/water/octalisk/octalisk_transp_FRAME.png'/>"; // instead of using globals we make the return of playerAttack == to $playerMessage to be used outside function. $playerMessage = playerAttack($currentMonster,$player['stats']['playerHitRollLow'],$player['stats']['playerHitRollHigh'], $player['stats']['playerDmgLow'],$player['stats']['playerDmgHigh'],$monsters['Ocean']['octalisk']['defense'],$monsters['Ocean']['octalisk']['hp'],$player['faction']['Teardrop_Ocean_Protectors'],$player['stats']['playerMana']); //insert octalisk stats into monsterattack function. if(encounter($monsters['Ocean']['octalisk']['seeInvis'],$monsters['Ocean']['octalisk']['aggro'],$player['faction']['Teardrop_Ocean_Protectors'])) { //BELOWE CODE instead of using globals, we set the output of monsterAttack //to $monsterMessage becasue it can be used outside the function. $monsterMessage = monsterAttack($currentMonster,$monsters['Ocean']['octalisk']['hitRollLow'],$monsters['Ocean']['octalisk']['hitRollHigh'] , $monsters['Ocean']['octalisk']['dmgLow'],$monsters['Ocean']['octalisk']['dmgHigh'], $player['stats']['playerDefense'],$player['stats']['playerHp'],$monsters['Ocean']['octalisk']['hp']); } else { echo "do nothing"; } } ////////////////////////////////////////////////////////////////////////////// //CHANGING BACKGROUND FOR OCEAN GOES HERE, 1 IMAGE FOR EACH LEVEL OF DEEPNESS WHEN further // BUTTON PRESSED if(empty($_POST['further'])) { $oceanBackground=' <img src="sundragon_environments/ocean/ocean1_FRAME.jpg"/>'; } elseif(!empty($_POST['further'])) { $oceanBackground=' <img src="sundragon_environments/ocean/ocean1_FRAME2.jpg"/>'; $echoMonster="<img src='sundragon_monsters_source/water/octalisk/octalisk_transp_FRAME.png'/>"; $monsterMessage='You see an Octalisk, it looks very scary'; } else { $oceanBackground='SHIT where the hell am I?'; $echoMonster="<img src='sundragon_monsters_source/water/octalisk/octalisk_transp_FRAME.png'/>"; $monsterMessage='You see an Octalisk, it looks very scary'; } ////////////////////////////////////////////////////////////////////////////////// if(!empty($_POST['search'])) { //include('frames/search.php'); //I CANT GET THIS BELOW TO RUN IN A FUNCTION INSIDE THE SEARCH.PHP FILE, WTF IS UP WITH THAT //and it returns random ALL monsters instead of ocean monsters. $random = 'Ocean'; $monster = array_rand($monsters[$random]); if(is_array($monsters[$random][$monster])) { $currentMonster = $monsters[$random][$monster]['name']; } else { $currentMonster = $monsters[$random][$monster]; } //instead of echoing out $currentMonster , we set it so we can get random monster images with it output. $monsterImage=$currentMonster; //make the below into a function, note what changes , those will be your parameters. //i dont know how to do it. i tried. //function monsterEncounter($echoMonster,$monsterImage) if($monsterImage=='octalisk') { $echoMonster="<img src='sundragon_monsters_source/water/octalisk/octalisk_transp_FRAME.png'/>"; $monsterMessage='You see an Octalisk, it looks very scary'; } elseif($monsterImage=='eel') { $echoMonster="<img src='sundragon_monsters_source/water/eel/eel_transp_FRAME.png'/>"; $monsterMessage='You see an electric Eel , look out.'; } elseif($monsterImage=='shark') { $echoMonster="<img src='sundragon_monsters_source/water/shark/shark_transp_FRAME.png'/>"; $monsterMessage='You see a Hammerhead Shark, it looks powerful.'; } else $echoMonster="no monster here"; }//end elseif ////////////////////////////////////////////////////////////////////////// if(!empty($_POST['spell'])) { $spellColor = array_rand($spells); if(is_array($spells)) { $currentSpell= $spellColor; } else { return 0; } //instead of echoing out $currentMonster , we set it so we can get random monster images with it output. if($currentSpell=='red') { $echoSpell=" <img src='sundragon_interface_template/spells/red.gif' align='center'/> "; $monsterMessage=' You cast <strong> BLOOD OF BEATHULE </strong>'; $player['stats']['playerMana']-=5; $echoPlayerMana=$player['stats']['playerMana']; } elseif ($currentSpell=='green') { $echoSpell=" <img src='sundragon_interface_template/spells/green.gif' align='center'/> "; $monsterMessage='You cast <strong> POISONOUS PLAGUE </strong> spell'; $player['stats']['playerMana']-=5; $echoPlayerMana=$player['stats']['playerMana']; } elseif($currentSpell=='blue') { $echoSpell=" <img src='sundragon_interface_template/spells/blue.gif' align='center'/> "; $monsterMessage='You cast <strong> HEART OF DARKNESS </strong>'; $player['stats']['playerMana']-=5; $echoPlayerMana=$player['stats']['playerMana']; } else { echo "nothing"; } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Realm of the Sun Dragon</title> <link rel="stylesheet" type="text/css" href="css/gamestyles.css"> <style type="text/css"> body { margin-top:-32px; padding:0; color: gold; } table { color: black; } .style8 {color: #000000} </style> </head> <body> <div id="container"> <div id="monster_message"><?php if(!empty($battleResult)){echo $battleResult;} // if isset battleresult, then echo ?><?php echo $error;?><?php echo "<br />". $playerMessage. "<br />". $monsterMessage."<br />";?></div> <div id="currentWeapon"> <img src="sundragon_interface_template/items/swords/sword_shrunk.png" width="190" height="65" /> </div> <div id="iframe_player_top_lft" > <div id="left_player_stats"><table align="center" width="30" border="0"> <tr> <td><strong>HP</strong></td> <td><strong><font color="red"><?php echo $playerHp;?></font></strong></td> </tr> <tr> <td><strong>MANA</strong></td> <td><strong><font color="green"><?php echo $echoPlayerMana;?></font></td> </tr> <tr> <td><strong>EXP</strong></td> <td><strong><font color="blue">999</font></strong></td> </tr> <tr> <td><strong>PLAT</strong></td> <td><strong><font color="white">999</font></strong></td> </tr> </table></div> <p> </p> <p> </p> <p> </p> <p align="center"><strong><br /> <span class="style8">Octalisk (Level <?php echo $currentMonsterLevel;?>) </span></strong> <br/> <strong><span class="style8">HP</span><font color="red"> <?php echo $monsterHp;?></font></strong> </p> <div id="spelleffectsleft" > <div class="divcenter"> <div align="center"> <div class="inline"> <div align="center">spell</div> </div> <div class="inline"> <div align="center">spell</div> </div> <div class="inline"> <div align="center">spell</div> </div> </div> </div> <!--end divcenter--> </div><!--end spell effects--> <div id="bottomspellsleft" > <div class="divcenter"> <div class="inline"> <div align="center">spell</div> </div> <div class="inline"> <div align="center">spell</div> </div> <div class="inline"> <div align="center">spell</div> </div> </div> <!--end div center--> </div><!--end bottomspells--> </div><!-- end player div--> <div id="iframe_spell_foreground"><?php echo $echoSpell;?></div> <div id="iframe_monster_background"> <?php echo $oceanBackground; ?></div> <div id="iframe_transparent_monster"><?php echo $echoMonster;?></div> <!--not here--> <div id="iframe_player_top_right" > <table width="160" height="64" border="0" align= "center"> <tr> <td width="160"><div align="center"> <p><strong><br /> Silverglade (Level: <?php echo $currentPLayerLevel;?>)<br /> </strong></p> </div></td> </tr> </table> <div class="spelleffects" > <div class="divcenter"> <div class="inline"> <div align="center">spell</div> </div> <div class="inline"> <div align="center">spell</div> </div> <div class="inline"> <div align="center">spell</div> </div> </div> </div> <div class="bottomspells" > <div class="divcenter"> <div class="inline"> <div align="center">spell</div> </div> <div class="inline"> <div align="center">spell</div> </div> <div class="inline"> <div align="center">spell</div> </div> </div> </div> </div> <div id="iframe_chat_right"> the data from the chat message box will be output to this div</div> <!--not here--> <div id="iframe_player_center_bottom" align="center" > <div align="center"> <form action='gamestart.php' method='post'><input type='submit' name='attack' value='Attack'/><input type="submit" name="search" value="search" /><input type="submit" value="cast spell" name="spell" /><input type="submit" value="go further" name="further" /> <input type="submit"value="Go back" name="back"/><input type="submit" name="inventory" value="Inventory"/></form> <div id="chat"> <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <strong>Message:</strong> <textarea name="message"></textarea> <input type="submit" name="submit" value="Chat"> <input type="hidden" name="ip" value="<?php echo $_SERVER['REMOTE_ADDR']; ?>"> </form> </div></div></div> <!--not here--> <div id="log_off"> <a href="logout.php"><strong>LOG OFF</strong></a> </div> <!--not here--> </div> </body> </html> 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 Hi, 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! Hi, I want to create a forgotten password page, where the user enters in their email address, the script queries the database for that email address, creates a unique ID, stores that unique ID in the database, then emails the unique ID and the User ID off to the user in an HTML link e.g. http://somesite.com/reset-password.php?userId=2&uniqueId=132832189312978312. The reset page would then match the unique ID to the one in the database and let them enter in a new password into the form. Ok so I can do most of that so far except from the emailing to the user. I'm running an Ubuntu Server 10 at the moment as my test server which is on my local network. Do I need to set up a mail server on that for php mailing to work, or can I use some external SMTP for sending? I've had a play round with the PHP mail() function but it won't send anything at the moment. I'll also need some code for when the site is running in the hosted live environment as it will likely use their mail servers. What's the best way to go about doing this? Many thanks! I have this thing that i am trying to make but i cant get it to work.. can anyone help? Code: [Select] function sql_read( $dbname,$dbusername,$dbpassword ) { $names = array(); $password = array(); $connect = @mysql_connect("mysql11.000webhost.com",$dbusername,$dbpassword) or die("Could Not Connect"); @mysql_select_db ($dbname) or die("Could not find DataBase"); $query = mysql_query("select * from users"); $numrows = mysql_num_rows($query); if ($numrows > 0){ while($row = mysql_fetch_assoc($query)){ $names[] = $row["uname"]; $password[] = $row["password"]; $id = $row["id"]; } $return = array($names,$password,$id); }else{ $return = array(); } return $return[]; } $names = array(); $names = sql_read("XXXXXX","XXXXXX","XXXXXXX")[0]; The error i get is Code: [Select] Parse error: syntax error, unexpected '[' in /home/a5480952/public_html/sql/index.php on line 28 Line 28 is "$names = sql_read("XXXXXX","XXXXXX","XXXXXXX")[0];" Please help... i REALLLLD need help with this.. ask questions if you want to know more about what i am trying to do... thanks! I'm having troubling with trying to create a function to spit out a single array with the following array. I can write it in a away that looks through the arrays manually. the results i am trying to generate is that each item in generated array. Array to convert array( "account" => array( "login", "register", "logout", "edit", ), "p" => array( "report", ), "array1.0" => array( "array2.0" => array( "array3.0", "array3.1 ), "array2.1", ), generating the array will look like this
Array ( [0] => account [1] => account/login [2] => account/register [3] => account/logout [4] => account/edit [5] => p [6] => p/report [7] => array1.0 [8] => array1.0/array2.0 [9] => array1.0/array2.0/array3.0 [10] => array1.0/array2.0/array3.1 [11] => array1.0/array2.1 ) The idea is that id generates a single array with combined labels and arrays inside, etc. I just can't figure out how to create a script that will create this array even If I add a new value or array.
Forgive me if I am using the word "globally" incorrectly... I want to reset the content of a particular field in all rows of a table to a specific value, I was thinking of nesting a query inside a query for the same table, but was not sure that this would work: ... $query = "SELECT * FROM music WHERE picked >'0'"; $result = mysql_query($query) or die ("Couldn't execute query."); /* reset the picked field to zero (0) */ while ($row = mysql_fetch_array($result)) { $picked = 0; $query= "UPDATE music SET picked='$picked' WHERE title='$title'"; $selectresult = mysql_query($query) or die ("Problem with the query: $query<br>" . mysql_error()); } ... Is this the correct approach or is there a better way of doing this? I have two arrays, both with the same key values. I'd like to combine them. So for instance... Code: [Select] <?php $array1['abcd'] = array( 'value1' => "blah", 'value2' => "blahblah"); $array1['efgh'] = array( 'value1' => "ha", 'value2' => "haha", 'valuex' => "xyz"); $array2['abcd'] = array('value3' => "three", 'value4' => "four"); $array2['efgh'] = array( 'value3' => "hohoho", 'value6' => "six6"); function combine_arrays($array1,$array2) { //*combining* return $single_array; } echo "<pre>"; print_r(combine_arrays($array1,$array2)); echo "</pre>"; /* would produce ['abcd'] = ( 'value1' => "blah", 'value2' => "blahblah", 'value3' => "three", 'value4' => "four" ) ['efgh'] = ( 'value1' => "ha", 'value2' => "haha", 'valuex' => "xyz", 'value3' => "hohoho", 'value6' => "six6" ) */ ?> What's the easiest way to do this? Ok so this link returns HTML $hitlist = file_get_contents($iMobLink."get_hit_list?user_id=".$iStore[2]."&level=10&auth_key=".$iStore[3]); now to parse it out I have this $entry = explode('<entry>', $hitlist); $hitlist = file_get_contents($iMobLink."get_hit_list?user_id=".$iStore[2]."&level=10&auth_key=".$iStore[3]); $user_id = explode('<user_id>', $hitlist); $user_id = explode('</user_id>', $user_id[1]); $mobname = explode('<mob_name>', $hitlist); $mobname = explode('</mob_name>', $mobname[1]); $paiduser = explode('<paid_user>', $hitlist); $paiduser = explode('</paid_user>', $paid_user[1]); $amount = explode('<amount>', $hitlist); $amount = explode('</amount>', $amount[1]); $paid_time = explode('<placed_time_ago>', $hitlist); $paid_time = explode('</placed_time_ago>', $paid_time[1]); $level = explode('<level>', $hitlist); $level = explode('</level>', $level[1]); $entry = explode('</entry>', $entry[1]); echo $user_id[0]."\n"; echo urldecode($mobname[0])."\n"; echo $amount[0]."\n"; echo $paid_time[0]."\n"; echo $level[0]."\n"; echo $entry[0];} Ok now.... this only returns one entry of the xml when there are more than 10. I need it to return all ten+ of the entrys here is what the xml looks like <outer> − <xml> − <entry> − <target_user> <user_id>512433892</user_id> <mob_name>MR%2025TATT00S%2C%20Level%2015</mob_name> </target_user> − <paid_user> <user_id>554190549</user_id> <mob_name>PRINCE%20OF%20NEW</mob_name> </paid_user> <amount>48000000000</amount> <is_npc>false</is_npc> <placed_time_ago>3 days ago</placed_time_ago> <level>15</level> </entry> − <entry> − <target_user> <user_id>530120192</user_id> <mob_name>EVILNESS%20SIMPLIFIED%2C%20Level%2013</mob_name> </target_user> − <paid_user> <user_id>539494114</user_id> <mob_name>StompinDatAzz</mob_name> </paid_user> <amount>1478608800</amount> <is_npc>false</is_npc> <placed_time_ago>1 day ago</placed_time_ago> <level>13</level> </entry> − <entry> − <target_user> <user_id>526183645</user_id> <mob_name>snatch%20rider%2C%20Level%20112</mob_name> </target_user> − <paid_user> <user_id>450207248</user_id> <mob_name>ShiftyShellShock</mob_name> </paid_user> <amount>999999999</amount> <is_npc>false</is_npc> <placed_time_ago>22 hours ago</placed_time_ago> <level>112</level> </entry> − <entry> − <target_user> <user_id>542145086</user_id> <mob_name>Riding%20Raider%2C%20Level%2043</mob_name> </target_user> − <paid_user> <user_id>513441119</user_id> <mob_name>Level%20U%20uP</mob_name> </paid_user> <amount>334616000</amount> <is_npc>false</is_npc> <placed_time_ago>18 hours ago</placed_time_ago> <level>43</level> </entry> − <entry> − <target_user> <user_id>554043828</user_id> <mob_name>klaibers%20limited%2C%20Level%2011</mob_name> </target_user> − <paid_user> <user_id>522432052</user_id> <mob_name>Sloppy%20Seconds</mob_name> </paid_user> <amount>39344504405</amount> <is_npc>false</is_npc> <placed_time_ago>17 hours ago</placed_time_ago> <level>11</level> </entry> − <entry> − <target_user> <user_id>496266215</user_id> <mob_name>Geheim%20Abwher%2C%20Level%207</mob_name> </target_user> − <paid_user> <user_id>216904061</user_id> <mob_name>yve1</mob_name> </paid_user> <amount>2499912800</amount> <is_npc>false</is_npc> <placed_time_ago>16 hours ago</placed_time_ago> <level>7</level> </entry> − <entry> − <target_user> <user_id>524874924</user_id> <mob_name>MYLILFRIEND%2C%20Level%20104</mob_name> </target_user> − <paid_user> <user_id>536745842</user_id> <mob_name>SUC%20MY%20GLOCK</mob_name> </paid_user> <amount>1615247200</amount> <is_npc>false</is_npc> <placed_time_ago>15 hours ago</placed_time_ago> <level>104</level> </entry> − <entry> − <target_user> <user_id>531185082</user_id> <mob_name>THE%20RAGE%20WITHIN%2C%20Level%2031</mob_name> </target_user> − <paid_user> <user_id>512862859</user_id> <mob_name>The%20Kozmik%20Slop</mob_name> </paid_user> <amount>16536800</amount> <is_npc>false</is_npc> <placed_time_ago>14 hours ago</placed_time_ago> <level>31</level> </entry> − <entry> − <target_user> <user_id>494326270</user_id> <mob_name>RIDE%20HIS%20CUCUMBER%2C%20Level%2016</mob_name> </target_user> − <paid_user> <user_id>554794332</user_id> <mob_name>STDS%20R%20BAD%20MMKAY</mob_name> </paid_user> <amount>337825600</amount> <is_npc>false</is_npc> <placed_time_ago>14 hours ago</placed_time_ago> <level>16</level> </entry> − <entry> − <target_user> <user_id>558355598</user_id> <mob_name>DEATH%20TO%20HITLIST%2C%20Level%2011</mob_name> </target_user> − <paid_user> <user_id>558349535</user_id> <mob_name>Gangsta%20Love</mob_name> </paid_user> <amount>181600000</amount> <is_npc>false</is_npc> <placed_time_ago>10 hours ago</placed_time_ago> <level>11</level> </entry> − <entry> − <target_user> <user_id>545114043</user_id> <mob_name>Ridin%20Dirty%2C%20Level%20130</mob_name> </target_user> − <paid_user> <user_id>510805692</user_id> <mob_name>iced%20baby</mob_name> </paid_user> <amount>481680800</amount> <is_npc>false</is_npc> <placed_time_ago>10 hours ago</placed_time_ago> <level>130</level> </entry> Notice there is more than one energy.. now how to I parse it out to where I can define each entry by a variable or something... any help is appreciated.. Thanks I have created two classes. One is called 'move' and the other 'unit'. To make my example easier to follow, I shall use the much loved pokemon series to explain my dilemma. Here are the class declarations. new class unit { var $name, $moves; public function newUnit($name, $moves) { $this->name = $name; $this->moves = $moves; } } new class move { var $name, $attack; public function newMove($name, $attack) { $this->name = $name; $this->moves = $moves; } } Now I shall instantiate these classes (if that makes sense xD) - I just started OOP yesterday, do mind my ignorance. $unit = array(); $move = array(); $unit[0] = new unit; $unit[0]->newUnit("picachu",array("thunderbolt","quick-attack")); Now, let's say I want to populate the $move array with the moves in the unit object (thunderbolt and quick-attack). I can retrieve their attack values from a database: $thunderboltAttack = 200; $quick-attackAttack = 40; I now want to create a function that will create instances of the 'move' class to produce: $move[0] = new move; $move[0]->newMove("thunderbolt",200); $move[1] = new move; $move[1]->newMove("quick-attack",40); Here is my dire attempt to do so: function createUnits($moves){ //$moves is the array holding the unit's moves for($i; $i < count($moves); $i++) { $arr[] =new move; $arr[count($units) - 1]->name = $moves[0]; $arr[count($units) - 1]->attack = $someAttackData; } return $arr; } $moves[] = createUnits; I'm ending up with a multi-dimensional array when I want a linear one like this: $move[0] = new move; $move[0]->newMove("thunderbolt",200); $move[1] = new move; $move[1]->newMove("quick-attack",40); What do I need to do. Do I have to resort to making $move global from within the function and do things that way? Code: [Select] $data=array('user1'=>'pass1','user2'=>'pass2'); now i would like that echo prints out the user1 word. Code: [Select] echo $data[?what here?]; Okay so here is a very simplified version of my code in order to try and illustrate what I am trying to do: $C1 = array (174,30); $C2 = array (165,80); $S = array($C1, $C2); foreach ($S as $cluster) { $number = '5000'; $another_number = '4565'; $cluster[0] = $number; } I feel like this should be really simple but its not working. So basically I'm trying to change the first value of the array select (e.g. C1 or C2) to whatever is in the variable $number. Any help would be greatly appreciated. Thanks Hello, I'm trying to extract information about a ticket through osTicket SOAP API, but I can't seem to figure out how! This is the return from the script (var_dump): array(1) { [0]=> object(stdClass)#2 (2) { ["question"]=> object(stdClass)#3 (4) { ["id"]=> int(25) ["created"]=> string(25) "2011-01-05T01:19:43+01:00" ["name"]=> string(4) "test" ["message"]=> string(4) "qasd" } ["answers"]=> array(1) { [0]=> object(stdClass)#4 (4) { ["id"]=> int(25) ["created"]=> string(25) "2011-01-05T01:25:06+01:00" ["name"]=> string(17) "Andreas Haakonsen" ["message"]=> string(3) "ler" } } } } A ticket can have several answers. I just can't seem to figure out how to extract/use this data and present it on my webpage. Too many arrays for me to understand I guess :p Is there anyone who can help me with some small code to help me figure this one out? Thanks! Hello, I have an array, $solutions, and a separate indexing array, $solution_order. From the $solution_order array (developed from the $order variable, where each $order variable looks like '0321' or '3021'), I'd like to create a new array $ordered_solutions, which indexes on the values picked from the $solution_order array. For example, if my $solutions array is (Big, Small, Fat, Skinny) and my $solution_order array is (2,3,1,0), then the final results should be (Fat, Skinny, Small, Big). I've written down what I have so far. Any thoughts about how to move this forward would be appreciated. Thanks! function GetOrder($solution, $wrong1, $wrong2, $wrong3, $order) { $solutions = array( $solution, $wrong1, $wrong2, $wrong3); $solution_order = array(substr($order,0,1), substr($order,1,1), substr($order,2,1), substr($order,3,1)); $ordered_solutions = array(); //what do to here?? return $ordered_solutions; } I can't work out the quotes around this... $bookingID['$row['id']'] = $row['id']; echo $bookingID['$row['id'];']; Parse error: parse error, expecting `']'' What would fix this? Hi, I need to do this: Write a method to quickly find the array index position of a given number in a ascending sorted array of numbers. e.g. in an array { 1, 2, 5, 10, 102 }, the array index position of a given number 5, would have an answer of 2. We're looking for an answer that's better than O(n). I was using php's built in methods but I need to do this with a basic function using no helper methods. Can anybody help me out with this? Thanks in advance. Hi i'am try to insert multiple data on a single submit, but i'm a total noob to Arrays, can any one help me out here... one of the members send me this out, but still i can figure it out how to insert the fields onto my database. it inserts but doesnt get the valuee.. Please help! if(isset($_POST['save'])) { unset($_POST['save']); $i = count($_POST['id']); $x = 0; for($x=0; $x <$i;$x++){ foreach($_POST as $data =>$d){ echo $data.'-'.$d[$x].'<br/>'; $insert = mysql_query("insert into tbl_grades"); //sql statement here (example): insert into table name (value of $data) values( value of$d[$x]) -- can anyone help me with this , how can i query to get the value of this, //HOW DO I MAKE MY SQL QUERY TO SAVE THIS OUT, I KNOW THIS IS MY PROBLEM IN THE QUERY.... here's my HTML <input name="id[]" type="hidden" value="<?php echo $row['id'];?>" /> 1st<input name="fg[]" type="text" id="fg[]" size="1" value="<?php $g_sub['sub_id'];?>"/> 2nd<input name="sg[]" type="text" id="sg[]" size="1" value="<?php $g_sub['sub_id'];?>"/> 3rd<input name="tg[]" type="text" id="tg[]" size="1" value="<?php $g_sub['sub_id'];?>"/> 4th <input name="forg[]" type="text" id="forg[]" size="1" value="<?php $g_sub['sub_id'];?>"/> ---- sub_id stands for subject id I have some similar arrays. How I can combine them to shuffle the new array? I'm not sure if this can be done, but I would like to get the sum for each $.row[''] result ex: if $row['robotics'] had values of 100,150,300 I would like to be able to show a total of 550 Code: [Select] <?php echo "<Table border=1>"; echo "<tr><td></td><td>Robotics</td><td>Chiral Stuctors</td><td>Enriched Uranium</td><td>Mechanical Parts</td><td>Coolant</td><td>Consumer Electronics</td><td>Precious Metals</td><td>Reactive Metals</td><td>Oxygen</td><td>Toxic Metals</td></tr>"; $result = mysql_query("select * from `pi`"); while ($row = mysql_fetch_array($result)) { echo "<tr><td>".$row['pilot']."</td>"; echo "<td>".$row['robotics']."</td>"; echo "<td>".$row['chiralstuctors']."</td>"; echo "<td>".$row['enricheduranium']."</td>"; echo "<td>".$row['mechanicalparts']."</td>"; echo "<td>".$row['collant']."</td>"; echo "<td>".$row['consumerelectronics']."</td>"; echo "<td>".$row['preciousmetals']."</td>"; echo "<td>".$row['reactivemetals']."</td>"; echo "<td>".$row['oxygen']."</td>"; echo "<td>".$row['toxicmetals']."</td></tr>"; } echo "</table>"; ?> |