PHP - I Can't Figure How To Work Output Buffer
I'm working on a basic structure for websites containing user management and a template engine.
I've run into troubles with the template engine when I try to allow for including scripted pages. This function is supposed to include and buffer the scripted page: function parse_file($file) { ob_start(); include($file); $buffer = ob_get_clean(); return $buffer; } In my template class I check to see if the data entered is a file or not, if it is then I run these lines to replace place holder-tags with the output buffer of the file included: foreach ($tags as $tag => $data) { if (file_exists($data)){ $data = $this->parse_file($data); } $this->page = preg_replace('/{' . $tag . '}|<!-- '.$tag.' -->/', $data, $this->page); } now here is the hitch, it seems the preg_replace is only replacing one of several identical place holder-tags and I am puzzled as of why this happens, could it be the buffer or what? Similar TutorialsI am using shell_exec, and it runs a ping on a server, is there any way to flush the buffer of the shell_exec as the data is getting written to the buffer? Because I sometimes ping a site 10 times and nothing get written until the function finishes, so is there anyway to write out the output as soon as it is available? btw, this isn't only for doing a ping it is for other things as well. Hi all, I post a strange behavior that could be reproduced (at least on apache2+php5). I don't know if I am doing wrong but let me explain what I try to achieve. I need to send chunks of binary data (let's say 30) and analyze the average Kbit/s at the end : I sum each chunk output time, each chunk size, and perform my Kbit/s calculation at the end. Code: [Select] <?php // build my binary chunk $var= ''; $o=9000; while($o--) { $var.= "testtest"; } // get the size, prepare the memory. $size = strlen($var); $tt_sent = 0; $tt_time = 0; // I send my chunk 30 times for ($i = 0; $i < 30; $i++) { // start time $t = microtime(true); echo $var."\n"; ob_flush(); flush(); $e = microtime(true); // end time // the difference should reprenent what it takes to the server to // transmit chunk to client right ? // add this chuck bench to the total $tt_time += round($e-$t,4); $tt_sent += $size; } // total result echo "\n total: ".(($tt_sent*8)/($tt_time)/1024)."\n"; ?> In this example above, it works so far ( on localhost, it oscillate from 7000 to 10000 Kbit/s through different tests). Now, let's say I want to shape the transmission, because I know that the client will have enough of a chunk of data to process for a second. I decide to use usleep(1000000), to mark a pause between chunk transmission. Code: [Select] <?php // build my binary chunk $var= ''; $o=9000; while($o--) { $var.= "testtest"; } // get the size, prepare the memory. $size = strlen($var); $tt_sent = 0; $tt_time = 0; // I send my chunk 30 times for ($i = 0; $i < 30; $i++) { // start time $t = microtime(true); echo $var."\n"; ob_flush(); flush(); $e = microtime(true); // end time // the difference should reprenent what it takes to the server to // transmit chunk to client right ? // add this chuck bench to the total $tt_time += round($e-$t,4); $tt_sent += $size; usleep(1000000); } // total result echo "\n total: ".(($tt_sent*8)/($tt_time)/1024)."\n"; ?> I am doing something wrong ? Does the buffer output is not synchronous ? Thanks a Lot Nunja I need someone to look over this and just see if they can see why this won't work anymore? It worked when the site was in development but when it came down to the day it's not working. Basically it reads a CSV and inserted the driver into a Quali or Results table in the correct order but it's not working anymore? If someone could have a read over it and suggest what might be going wrong that would be great. Edit: It basically just added the same driver 24 times in the table. Code: [Select] Public Function ProcessUpload($UR, $RaceID, $RaceName) { Global $MDB; // Configuration - Your Options $allowed_filetypes = array('.csv'); // These will be the types of file that will pass the validation. $max_filesize = 524288; // Maximum filesize in BYTES (currently 0.5MB). $upload_path = './resultsfiles/'; // The place the files will be uploaded to (currently a 'files' directory). $filename = $_FILES['userfile']['name']; // Get the name of the file (including file extension). $ext = substr($filename, strpos($filename,'.'), strlen($filename)-1); // Get the extension from the filename. If (strpos($filename, "Quali") == True) { $tbl_name = "QualiPositions"; $FN = " - Qualifying"; } Else { $tbl_name = "RacePositions"; $FN = " - Race"; } $SQL = "SELECT count(*) FROM $tbl_name WHERE RaceID = $RaceID"; $Count = $MDB->prepare($SQL); $Count->execute(); $Count = $Count->fetchColumn(); If ($Count == 24) { $Msg = "<div class='error'>Error: We already have 24 Results for this Session.</div>"; } // Check if the filetype is allowed, if not DIE and inform the user. if(!in_array($ext,$allowed_filetypes)) $Msg = "<div class='error'>Error: The file you attempted to upload is not allowed.</div>"; // Now check the filesize, if it is too large then DIE and inform the user. if(filesize($_FILES['userfile']['tmp_name']) > $max_filesize) $Msg ="<div class='error'>Error: The file you attempted to upload is too large.</div>"; // Check if we can upload to the specified path, if not DIE and inform the user. if(!is_writable($upload_path)) $Msg ="<div class='error'>Error: You cannot upload to the specified directory, please CHMOD it to 777.</div>"; If (strpos($Msg, "Error:") == False) { // Upload the file to your specified path. $filename = str_replace(" ", "", $RaceName)."$FN.csv"; if (move_uploaded_file($_FILES['userfile']['tmp_name'],$upload_path . $filename)) { $FilePath = $upload_path . $filename; if (($handle = fopen($FilePath, "r")) !== FALSE) { $Pos = 0; while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { $num = count($data); for ($c=0; $c < $num; $c++) { $Pos++; If ($Pos <= 24) { $Driver = explode(" ", $data[$c]); $FName = $Driver[0]; $LName = $Driver[1]." ".$Driver[2]." ".$Driver[3]; $STH = $MDB->query("SELECT * FROM Drivers WHERE FirstName = '$FName' AND LastName = '$LName'"); $STH->setFetchMode(PDO::FETCH_OBJ); while($row = $STH->fetch()) { $DriverID = $row->DriverID; $ChassisID = $row->ChassisID; $EngineID = $row->EngineID; } $STH = $MDB->prepare("INSERT INTO $tbl_name(RaceID, DriverID, ChassisID, EngineID, Position, DSQ) VALUES (:RID, :DID, :ChaID, :EngID, :Pos, :DSQ)"); $STH->execute(array('RID' => $RaceID, 'DID' => $DriverID, 'ChaID' => $ChassisID, 'EngID'=>$EngineID, 'Pos'=>$Pos, 'DSQ' => 0)); $Msg = "<div class='team_confirm'>The Results have been uploaded for the $RaceName</div>"; } Else { If ($tbl_name == "RacePositions") { $Driver = explode(" ", $data[$c]); $FName = $Driver[0]; $LName = $Driver[1]." ".$Driver[2]." ".$Driver[3]; $STH = $MDB->query("SELECT * FROM Drivers WHERE FirstName = '$FName' AND LastName = '$LName'"); $STH->setFetchMode(PDO::FETCH_OBJ); while($row = $STH->fetch()) { $DriverID = $row->DriverID; } $sql = "UPDATE RacePositions SET FastLap = 'Yes' WHERE RaceID=? AND DriverID = ?"; $q = $MDB->prepare($sql); $q->execute(array($RaceID, $DriverID)); } } } } fclose($handle); } } else { $Msg = 'There was an error during the file upload. Please try again.'; // It failed :(. } } Return $Msg; } That is the code, the CSV is basically like this: Code: [Select] Lewis Hamilton, Jenson Button, Romain Grosjean, Michael Schumacher, Mark Webber, Sebastian Vettel, Nico Rosberg, Pastor Maldonado, Nico Hulkenberg, Daniel Ricciardo, Jean-Eric Vergne, Fernando Alonso, Kamui Kobayashi, Bruno Senna, Paul di Resta, Felipe Massa, Kimi Raikkonen, Heikki Kovalainen, Vitaly Petrov, Timo Glock, Charles Pic, Sergio Perez, Pedro de la Rosa, Narain Karthikeyan Thanks for any help! Hello guys, I devised the code block below, to retrieve all US zip codes that are located within a specified radius from the user's own zip code. So basically, the user selects a maximum distance option from a form element (not shown here)which is appended to the variable $distance. What the code below does is as follows: The longitude and latitude corresponding to the user's zip code are retrieved in the first query. Then in the second query, the longitudes and latitudes corresponding to every zip code in the database are retrieved. In the ensuing while loop, a distance calculation is made between the user's zip and every other zip using the longitudes and latitudes and if that distance falls within the selected $distance, that particular zip code is listed in a defined array called $range. Now everything works fine up to this point as tested. The problem is with the very last line. I try to implode the $range array into a string with the same name, separating the array elements with commas (,). Then when I print out the resulting string, I get the list of desired zip codes but not separated by commas. For example: 9001190015900179003490037900439004790048900569006 19006290301 9030190301 90302 Well when I use a foreach loop as follows: foreach ($range as $r) {echo $r.",";} the $range array behaves like any normal array yielding: 90011,90015,90017,90034,90037,90043,90047,90048,90056,90061,90062,90301 ,90301,90301 ,90302, So why in the world is the implode function not working? Here is my code. //Retrieve the zip codes within range. // Connect to the database. require('config.php'); //Retrieve longitude and latitude of logged in member. $query = "SELECT* FROM members INNER JOIN zip_codes ON members.zip = zip_codes.zip WHERE members.member_id = '{$_SESSION['id']}'"; $result = mysql_query($query); $row = mysql_fetch_assoc($result); $my_lon = $row['lon']; $my_lat = $row['lat']; //Query all longitudes and latitudes in database. $query2 = "SELECT* FROM zip_codes INNER JOIN members ON members.zip = zip_codes.zip "; $result2 = mysql_query($query2); while ($row2 = mysql_fetch_assoc($result2)) { //Define array to hold zips found within range. $range = array(); if((rad2deg(acos(sin(deg2rad($my_lat))*sin(deg2rad($row2['lat'])) +cos (deg2rad($my_lat)) * cos (deg2rad($row2['lat'])) * cos(deg2rad($my_lon - $row2['lon'])) ) ) )*69.09 <= $distance ) { $range[] = $row2['zip']; } //Implode the range arrary. $range = implode(',' , $range); echo $range; }//End of while loop. Hi there, Can anyone show me how I can grab the value "c87cc576092fe1a0f5ac3d50091694b4" out of this string, it changes. Also its coming from a socket a $buffer variable, so How can I do this without grabbing everything else aswell, ie all the data after it too Quote $buffer = fgets($fp, 4096); /*** recieve data looks like this - <dd><input type="hidden" name="sid" value="c87cc576092fe1a0f5ac3d50091694b4" /> fclose($fp); } fclose($Handle); If someone could show me how to do this, I think you can do it with the split function, i just dont know how. if someone could show. i'd be SO greatful PHP Buffer Flushing is it good or bad? thank you all. I have this inside of a method: if($output){ $opt = fread($pointer, 10000); if(!$headers){ $opt = preg_replace("/http.+(\r\n\r\n|\n\n|\r\r)/isU", "", $opt); } echo $opt; } one of my methods uses fsocketopen to open a file and start processing it. I then have this method which reads out the data to the page. as the file is being processed. Here is the file that is being processed Code: [Select] <?php function flush_buffers(){ ob_end_flush(); flush(); ob_start(); } for($i=0;$i<10;$i++){ echo "Test1: $i"; flush_buffers(); usleep(500000); } ?> when http outputs the data it also outputs the buffer size as well. I ran it on two files, and here was my output: Code: [Select] Test1: cats b Test1: cats b Test1: cats b Test1: cats b Test1: cats b Test1: cats b Test1: cats b Test1: cats b Test1: cats b Test1: cats 0 Test2: 0 8 Test2: 1 8 Test2: 2 8 Test2: 3 8 Test2: 4 8 Test2: 5 8 Test2: 6 8 Test2: 7 8 Test2: 8 8 Test2: 9 Is there any way to remove the buffer size (the "8" and the "b")? I basically went off of this and converted it to a class: http://phplens.com/phpeverywhere/?q=node/view/254 Well I have a script that executes a scan on a system set to run infinitely, and I need it to echo out a message each time it loops through, but I don't want it to echo out the message with the next loop message below it, and the next one below that etc... I've tried using the flush(); function and been messing around with that with no luck. For security reasons I don't want to release any of the processing code, but here is the basic construction of the script: <?PHP ***PROCESSING AND SCAN CODE*** ***PROCESSING AND SCAN CODE*** ***PROCESSING AND SCAN CODE*** ***PROCESSING AND SCAN CODE*** $RepeatIt = -1; for($g=1; $g!=$RepeatIt+1; $g++) { ***PROCESSING AND SCAN CODE*** ***PROCESSING AND SCAN CODE*** ***PROCESSING AND SCAN CODE*** ***PROCESSING AND SCAN CODE*** $ScanMessage = ":.:.: SCANNING THE HITLIST FOR MOBSTER: ".$MobName." (SCAN #$g) :.:.:"."<br/><br/>"; echo $ScanMessage; ***PROCESSING AND SCAN CODE*** ***PROCESSING AND SCAN CODE*** ***PROCESSING AND SCAN CODE*** ***PROCESSING AND SCAN CODE*** } ?> At the moment it's returning: :.:.: SCANNING THE HITLIST FOR MOBSTER: DEUS EX DESTROYER (SCAN #1) :.:.: :.:.: SCANNING THE HITLIST FOR MOBSTER: DEUS EX DESTROYER (SCAN #2) :.:.: :.:.: SCANNING THE HITLIST FOR MOBSTER: DEUS EX DESTROYER (SCAN #3) :.:.: :.:.: SCANNING THE HITLIST FOR MOBSTER: DEUS EX DESTROYER (SCAN #4) :.:.: So what I want it to do is just delete the scanning message and replace it with the next scan message so while running this script you would see just the number increment on the same line. Any suggestions? Thanks. The page that I'm working on is a quiz results page. In this section of code I am simply printing the question, then each answer choice is printed depending on a few if statements. Let's say the answer choice in this first statement was "Baseball." The four possibilities depending on the student answer I want a Baseball - You Got This Right or Baseball - Correct Answer or Baseball - Your Answer or Baseball So if the student gets a question wrong one choice should say "Correct Answer" next to it and one other would have "Your Answer" next to it. Pretty simple and straightforward. I can get the correct results from everything but the second ifelse statement (Baseball - Your Answer). No matter what i do I can't get this to work. Here is the code below and some clarifications: $StudAns = Student's answer $Choices = The particular answer choice being evaluated $CorrectAnswer = obvious Code: [Select] $StudAns = array($QChoices['Q1Choice'], $QChoices['Q2Choice'], $QChoices['Q3Choice']); $ContentsQuery = mysql_query("SELECT Question, Choice1, Choice2, Choice3, Correct_Answer FROM Module_1_Quiz") or die(mysql_error()); while ($Contents = mysql_fetch_array($ContentsQuery)) { $i =0; $Choices = array($Contents['Choice1'], $Contents['Choice2'], $Contents['Choice3']); $CorrectAnswer = $Contents['Correct_Answer']; echo "<span id='answers'><table width = '600' border='0' align='center' id='answers' bgcolor='#FFFFCC'><tr><td>"; echo $Contents['Question']; echo "</td></tr>"; echo "<tr><td><ol type = 'a'><li>"; // Checks what should be printed for the first answer option if ($Choices[$i] == $CorrectAnswer && $StudAns[$i] == $CorrectAnswer) { echo $Choices[$i]; echo " - You Got This Right!"; } elseif ($Choices[$i] == $CorrectAnswer && $StudAns[$i] != $CorrectAnswer) { echo $Choices[$i]; echo " - Correct Answer"; } elseif ($StudAns[$i] != $CorrectAnswer && $CorrectAnswer[$i] != $Choices[$i]) { echo $Choices[$i]; echo " - Your answer"; } else { echo $Choices[$i]; } echo "</li><li>"; $i++; // Checks what should be printed for the second answer option if ($Choices[$i] == $CorrectAnswer && $StudAns[$i] == $CorrectAnswer) { echo $Choices[$i]; echo " - You Got This Right!"; } elseif ($Choices[$i] == $CorrectAnswer && $StudAns[$i] != $CorrectAnswer) { echo $Choices[$i]; echo " - Correct Answer"; } elseif ($StudAns[$i] != $CorrectAnswer && $CorrectAnswer[$i] != $Choices[$i]) { echo $Choices[$i]; echo " - Your answer"; } else { echo $Choices[$i]; } echo "</li><li>"; $i++; // Checks what should be printed for the third answer option if ($Choices[$i] == $CorrectAnswer && $StudAns[$i] == $CorrectAnswer) { echo $Choices[$i]; echo " - You Got This Right!"; } elseif ($Choices[$i] == $CorrectAnswer && $StudAns[$i] != $CorrectAnswer) { echo $Choices[$i]; echo " - Correct Answer"; } elseif ($StudAns[$i] != $CorrectAnswer && $CorrectAnswer[$i] != $Choices[$i]) { echo $Choices[$i]; echo " - Your answer"; } else { echo $Choices[$i]; } echo "</li></ol></table></span>"; } Thanks everyone! Hi, good pm masters! So i have this code Code: [Select] <td><img src="images/layout/<?php echo base64_decode($_GET['layout']); ?>" width="50%" height="50%" /></td> $_GET['layout'] is encoded that's y i have a decode there, the image name will then be combined to the src like this -> image/layout/1.jpg.. when i view the source the src is correct but it doest show the image.. cant seem to find whats wrong.. my folder structure is sandbox>images>layout>file.jpg the php file (where the code above is) inside the sandbox. sorry if am i missing something sooo eaasy.. i was doin alot of coding this morning until now so i don't know what to think anymore.. guys is it possible to somehow compare something like these two together and make a choice depending on the out come SystemKeyv1.0 and PasswordCrackerv2.0 PasswordCrackerv2.0 is grater than SystemKeyv1.0 can these be compared somehow? thank for advise guys; Cheers hey all; i created a script that just allows a user to record an IP address and it presents them in a table.. issue: each record draws its own row and a colum for an image (for deleting).. I can't igure out how I can delete the one row when they click on image(little x) to delete... issue2: it's showing the error message when you bring up the screen telling them they didn't enter anything even prior to them hitting submit... issue3: it's allowing me to enter the same IP again code: <?php session_start(); if (!isset($_SESSION['username'])) { echo "Sorry you must be logged in to view this page<BR>"; echo "Please <a href='index.php'>GO BACK</a> and try again"; exit(); } else { if ($_SESSION['username']) { $username = $_SESSION['username']; $userid = $_SESSION['userid']; } } //script v1.0 ipdatabase.php - create a list of IP addresses that the user has added to their list to remember. can add or remove IPs ?> <style type="text/css"> <!-- .style1 {color: #FFFFFF} --> </style> <table align="center" width="550" border="0" cellpadding="0" cellspacing="0" bgcolor="#000000"> <!--DWLayoutTable--> <tr> <td height="106" colspan="3" valign="top"><img src="images/myvpc.png" width="550" height="106"></td> </tr> <tr> <td width="16" height="57"> </td> <td width="516" valign="top"><div align="center" class="style1"> <p>IP DATABASE</p> <p align="left">add or remove IP address you have encountered in the game thus far for later use!</p> </div></td> <td width="18"> </td> </tr> <tr> <td height="100"> </td> <td valign="top"> <form action="ipaddressadd.php" method="POST"> <p> </p> <p><span class="style1">IP ADDRESS</span>: <input type="text" name="ipaddress" size="16"> <input type="submit" name="submit" value="submit"> </p> </form></td> <td> </td> </tr> <tr> <td height="17"></td> <td valign="top"><img src="images/filler.jpg" width="516" height="19"></td> <td></td> </tr> <tr> <td height="296"></td> <td valign="top"> <?php $submit = $_POST['submit']; if ($submit) { $ipaddress = ip2long($_POST['ipaddress']); } //script to add IP to database include('connectdb.php'); mysql_select_db('heaven_users') or die (mysql_error()); if (isset($ipaddress,$submit)) { mysql_query("INSERT INTO ipdatabase (userid,ipaddress) VALUE ('$userid','$ipaddress')") or die ("Could Not write to database, Please try again"); } else echo "<center><font color='#ff0000'>You didn't add anything mate!</font></center>"; echo "<br />"; echo "<table align='center' border='1'><tr align='center'><th><font color='#ffffff'>SAVED IPADDRESS</font></th></tr><tr>"; $query = mysql_query("SELECT * FROM ipdatabase WHERE userid = '$userid'"); while ($result = mysql_fetch_assoc($query)) { $ip = long2ip($result['ipaddress']); echo "<tr align=\"center\"><td><font color='#ffffff'>".$ip."</font></td><td><a href='deleteip.php'><img border='0' src='images/delete.png'></a></td></tr>"; } echo "</table>"; ?> </td> <td></td> </tr> </table> I'm terrible at designing websites (that's pretty much out of the question), but I would like to work on my php skills. I just can't figure out anything I can write that isn't extremely hard.. ideas? i was wondering how i would go about making a single page that would have sections on it and if you click a section the page reloads and shows the information that is within that section? i got my code to show both the section and its information at the same time but cannot figure out how to do the above. please help. thank you -Adam I get this 2 errors everytime i hit "Sign Up" in my registration form i'm creating for my new website: Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in [php file location] on line 64 Deprecated: Function eregi() is deprecated in [php file location] on line 87 I have created a database in, MySQL with phpMyAdmin, named "membership" and a table named "users" with these fields: Field Type Collation Attributes Null Default Extra username varchar(20) latin1_swedish_ci No None first_name varchar(30) latin1_swedish_ci No None last_name varchar(30) latin1_swedish_ci No None password varchar(30) latin1_swedish_ci No None email varchar(50) latin1_swedish_ci No None gender text latin1_swedish_ci No None birth_day date No None This is the 2 parts of the php code where i get the 2 errors: public function user_exists() { mysql_connect("localhost","root","101Dalmatiner") or die(mysql_error()); mysql_select_db("membership") or die (mysql_error()); $data = mysql_query("SELECT ID FROM users WHERE username = '{$this->username}'"); return mysql_num_rows($data) > 0 ? 1 : 0; <---- the line where the first error appears } if(empty($this->email) || !eregi('^[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z]{2,4}$',$this->email)) $this->errors[] = 'Invalid Email'; There is all the neccesary informationg you'll need if your willing to look through it all and help my i think! I'm kinda new to php and MySQL so don't blame me if the code is messed up or something look really wrong, i'd appreciate any help i can get on this! Hi im still learning php and have been running through the tutorials on making a user authentication system but im getting an error on one line but ive got the same code else where and its fine... Code: [Select] // Must have at least one character if (strspn($_POST['user_name'],$span_str) == 0) { return false; } Im getting the error on the if statment but no matter what i try it still tells me theres an error... Heres the full function code: Code: [Select] function account_namevalid() { // parameter for use with strspan $span_str = "abcdefghijklmnopqrstuvwxyz" . "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-"; // Must have at least one character if (strspn($_POST['user_name'],$span_str) == 0) { return false; } // Must contain all legal characters if (strspn($_POST['user_name'],$span_str) != srnlen($name)) { return false; } // Min and Max length if ($strlen($_POST['user_name']) < 5) { return false; } if strlen($_POST['user_name']) > 25 { return false; } // Illegal names if (eregi("^((root)|(bin)|(deamon)|(adm)|(lp)|(sync)|(shutdown)|(halt)|(mail)|(news)|(uucp)|(operator)|(games)|(mysql)| (httpd)|(nobody)|(dummy)|(www)|(cvs)|(shell)|(ftp)|(irc)|(debian)|(ns)|(download)))$", $_POST['user_name'])) { return false; } if (eregi("^(anoncvs_)", $_POST['user_name'])) { return false; } return true; } Any help or info would be greatfull... Cheers Chris So I'm sitting at my desk scratching my head on how to do a task where I pull information form a database (that i know how to do) but then i need to see if two variables equal a string and if they do count out how many times that two variables equal there two string checks and out put the counted number ? this is what I have thought of but dose not to work because I cant figure out a way to code it? $dbPull = mysql_fetch_array($result) if( $dbPull['Foo'] == 'string1' && $bdPull['Bar'] == 'string2') this is were I get lost I'm looking for (how many times in the DB dose String2 show up in the array were the above, IF statement is true ) any ideas would be most appreciated i have an array called $imageArray like this Array ( [0] => 'Dashka'_Darren_Sheehan_1.jpg [1] => 'Dashka'_Darren_Sheehan_10.jpg [2] => 'Dashka'_Darren_Sheehan_2.jpg [3] => 'Dashka'_Darren_Sheehan_3.jpg [4] => 'Dashka'_Darren_Sheehan_4.jpg [5] => 'Dashka'_Darren_Sheehan_5.jpg [6] => 'Dashka'_Darren_Sheehan_6.jpg [7] => 'Dashka'_Darren_Sheehan_7.jpg [8] => 'Dashka'_Darren_Sheehan_8.jpg [9] => 'Dashka'_Darren_Sheehan_9.jpg [10] => . [11] => .. [12] => Aaron_Kidney_1.jpg [13] => Aaron_Kidney_10.jpg [14] => Aaron_Kidney_11.jpg [15] => Aaron_Kidney_12.jpg [16] => Aaron_Kidney_13.jpg [17] => Aaron_Kidney_14.jpg [18] => Aaron_Kidney_15.jpg [19] => Aaron_Kidney_16.jpg [20] => Aaron_Kidney_17.jpg [21] => Aaron_Kidney_18.jpg and i also have another array called $_names Array ( [0] => 'Dashka'_Darren_Sheehan [1] => Beefit_Gyms [2] => Aaron_Kidney [3] => Dean_Mitchell [4] => Colin_O_Neill [5] => Keith_McManus ) if a name in array $_names exists in the $imageArray i want to insert the images for that person into one column of a table like this <tr> <?php foreach ($names as $name): ?><th><?php htmlout($name); ?></th><?php endforeach; ?> </tr> <tr> <td><img src="../images/'Dashka'_Darren_Sheehan_1.jpg" width="204"/></td> <td><img src="../images/Aaron_Kidney_1.jpg" width="204"/></td> <td>row 1, cell 1</td> <td>row 1, cell 2</td> <td>row 1, cell 1</td> <td>row 1, cell 2</td> </tr> <tr> <td><img src="../images/'Dashka'_Darren_Sheehan_2.jpg" width="204"/></td> <td><img src="../images/Aaron_Kidney_2.jpg" width="204"/></td> <td>row 1, cell 1</td> <td>row 1, cell 2</td> <td>row 1, cell 1</td> <td>row 1, cell 2</td> </tr> can anyone help me write the logic for this?? I cant figure it out... hello all, i can't get this to work; i'm able to echo both accts entered into the form via the _get but can't pull both balances using the $from_acct and $to_acct only the first query working do I have it formated wrong <?php //check for submit $submit = $_GET['submit']; //end looking for submit //set varibles if submit is present if (!$submit) { echo "Sorry Mate I don't see you have submitted anything for me to process"; } else { //make the connecting and set some varibles from _get $from_acct = $_GET['from_acct']; $to_acct = $_GET['to_acct']; $amount = $_GET['amount']; $connect = mysql_connect("localhost","root","") or die (mysql_error()); mysql_select_db('users') or die ("no such database exisit"); $query = mysql_query("SELECT * from members WHERE bankaccount=$from_acct") or die ("Could not locate to account"); $query2 = mysql_query("SELECT * from members WHERE bankaccount=$to_acct") or die ("Could not locate to account"); while ($result = mysql_fetch_assoc($query) && $result2 = mysql_fetch_assoc($query2)) { $fromb = $result['balance']; $tob = $result2['balance']; } //make a check to see if the account that is sending has the money to send if ($fromb<$amount) { echo "Mate you don't have enough cash to transfer " .$amount. "to this account<br />"; echo "Your Current Balance available for transfer is " .$fromb; } else { $newbalancefrom = $fromb - $amount; $newbalanceto = $tob + $amount; //make the transfer $transfer = mysql_query("UPDATE 'users' . 'members' SET 'balance' = '$newblanceto' WHERE bankaccount='$to_acct'") or die ("could not write to profile"); $transfer2 = mysql_query("UPDATE 'users' . 'members' SET 'balance' = '$newblancefrom' WHERE bankaccount='$from_acct'") or die ("Could Not Write to From Account"); if ($transfer) { echo "Transfer Complete Thanks!"; } else { echo "There was a error in the transfer process please try again"; } } } echo $fromb . "<br />"; echo $tob . "<br />"; echo $from_acct . "<br />"; echo $to_acct . "<br />"; ?> <h2>Peer to Peer Transfer</h2><br><br> <form action="testtrans.php" method="get"> Amount to Transfer: <input type="text" size="8" name="amount"><br> From Account: <input type="text" size="15" name="from_acct"> To Account: <input type="text" size="15" name="to_acct" /><br /> <input type="submit" name="submit" value="transfer" /> </form> |