PHP - Php Streaming File Loops When It's Not Suppose To
Hi all, I've been running into some issues trying to stream .mp3 files, specifically Safari/Flash... Firefox works great. I'm about to throw in the towel on this one and try another streaming solution, so I thought I'd reach out and connect with the PHP pros here before trying something else.
Basically, the PHP streamer takes a track guid variable and token variable(MD5), looks up the field in the DB, gets the url and then proceeds to stream the file with no caching, and keeping the URL hidden from the user so they can't download it. The token variable is there to assure that the url is only used once. Once it is, the script will not allow the stream if the token/track guid combo already exists in the DB. The problem with the looping is that once that token has been used it won't stream the track, which is how it's suppose to work, sans looping. I've put an MYSQL INSERT into the code to verify that it does loop.. usually I see 3- :wtf:5 consecutive entries in the DB for that token. So Firefox does not do this.. and I gather it's something to do with how the client streams with the "readfile" function. Pasted below is some code to show the headers and the readfile function I am using. I can post the rest of the script if need be. //$path and $tokenApproved are variables i set earlier in the script date_default_timezone_set('GMT'); $date = date(DATE_RFC822); $filesize = ffilesize($path); $shortlen = $filesize - 1; //ffilesize() is a custom filesize function if($tokenApproved) { header("Content-type: audio/mpeg"); header("Content-Length: $filesize"); header('Content-Range: bytes 0-'.$shortlen.'/'.$filesize); header("Expires: $date"); header('Content-Disposition: filename="eztunesaudio.mp3"'); header("Cache-Control: no-store, no-cache, must-revalidate"); header("Cache-Control: post-check=0, pre-check=0", false); readfile($path); } //eztunesaudio.mp3 is just a default name I give the stream Similar TutorialsHello all
Was hoping someone could help. I have a .htaccess file that contains the following:
RewriteEngine On RewriteRule ^sites/([a-z0-9]+)/?$ sites.php?letter=$1 [NC,L,QSA] RewriteRule ^network-devices/([a-z0-9]+)/?$ network-devices.php?letter=$1 [NC,L,QSA] RewriteRule ^site/([0-9]+)/?$ site.php?site_id=$1 [NC,L] RewriteRule ^network-device/([0-9]+)/?$ network-device.php?device_id=$1 [NC,L] RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.php -f RewriteRule ^(.*)$ $1.php?%{QUERY_STRING} I'm getting 2 x Quote unexpected T_ENCAPSED_AND_WHITESPACE for: $query = "select zone from delivery where country = '$_POST['country']'"; Am I suppose to be braking out of '$_POST['country']' or something? I suspect I am: 1. They are the only two things in the code; 2. I got a gut feeling about those quadruple quotes. I've tried braking out with about 15 quote/full stop combinations, but it hasn't helped. Any suggestions? registration.php Code: [Select] <html> <body> <form name="register" method="post" action="login.php" //onsubmit="return a()"> <table border='0'> <tr><td>Username:</td><td><input type='text'name='username' maxlength='60'></td></tr> <tr><td>Password:</td><td><input type='password' name='pass' maxlength='10'></td></tr> <tr><td>Confirm Password:</td><td><input type='password' name='pass2' maxlength='10'></td></tr> <tr><th colspan=2><input type='submit' name='sub' value='Register'></th></tr> </table> </form> <body> </html> and this direct to login page where the code is Code: [Select] <?php mysql_connect("localhost","root") or die(mysql_error()); mysql_select_db("Regis") or die(mysql_error()); if (isset($_POST['sub'])) { $message=strip_tags($message); if (!$_POST['username'] | !$_POST['pass'] | !$_POST['pass2'] ) { echo("<SCRIPT LANGUAGE='JavaScript'>window.alert('You did not complete all of the required fields')</SCRIPT>"); return false; } // checks if the username is in use if (!get_magic_quotes_gpc()) { $_POST['username'] = addslashes($_POST['username']); } $usercheck = $_POST['username']; $check = mysql_query("SELECT username FROM registration WHERE username = '$usercheck'") or die(mysql_error()); $check2 = mysql_num_rows($check); //if the name exists it gives an error if ($check2 != 0) { print ('Sorry, the username '.$_POST['username'].' is already in use.'); } if ($_POST['pass'] != $_POST['pass2']) { print ('Your passwords did not match. '); } // here we encrypt the password and add slashes if needed $_POST['pass'] = md5($_POST['pass']); if (!get_magic_quotes_gpc()) { $_POST['pass'] = addslashes($_POST['pass']); $_POST['username'] = addslashes($_POST['username']); } // now we insert it into the database if($_POST['username'] && $_POST['pass'] && $_POST['pass2'] ) { $insert = "INSERT INTO registration (username, password) VALUES ('".$_POST['username']."', '".$_POST['pass']."')"; $add_member = mysql_query($insert); echo("<SCRIPT LANGUAGE='JavaScript'>window.alert('Registration had been succesfully added :)')</SCRIPT>"); } } //if the login form is submitted /* if (isset($_POST['submit'])) { // makes sure they filled it in if(!$_POST['username'] | !$_POST['pass']) { die('You did not fill in a required field.'); } // checks it against the database if (!get_magic_quotes_gpc()) { $_POST['email'] = addslashes($_POST['email']); } $check = mysql_query("SELECT * FROM registration WHERE username = '".$_POST['username']."'")or die(mysql_error()); //Gives error if user dosen't exist $check2 = mysql_num_rows($check); if ($check2 == 0) { die('That user does not exist in our database. <a href=register.php>Click Here to Register</a>'); } while($info = mysql_fetch_array( $check )) { $_POST['pass'] = stripslashes($_POST['pass']); $info['password'] = stripslashes($info['password']); $_POST['pass'] = md5($_POST['pass']); //gives error if the password is wrong if ($_POST['pass'] != $info['password']) { die('Incorrect password, please try again.'); } } } else { // if they are not logged in ?> <form action="submit.php" method="post"> <table border="0"> <tr><td colspan=2><h1>Login</h1></td></tr> <tr><td>Username:</td><td> <input type="text" name="username" maxlength="40"> </td></tr> <tr><td>Password:</td><td> <input type="password" name="pass" maxlength="50"> </td></tr> <tr><td><a href=register.php>Register</a></td> <td><input type="submit" name="submit" value="Login"> </td></tr> </table> </form> <?php } */ ?> My problem is when the code is reading this statement if (!$_POST['username'] | !$_POST['pass'] | !$_POST['pass2'] ) { echo("<SCRIPT LANGUAGE='JavaScript'>window.alert('You did not complete all of the required fields')</SCRIPT>"); return false; } ya it is appear that alert box but it will direct to login page im want it to be in registration page any modification on my code? So i have a large video files, 1.5 gigs even. I made an html5 video player where the source is a php file. The php file is supposed to go below the web root and serve the video file to the html5 video tag. This all works just fine if the video using a script that uses HTTP_RANGE to serve the file in parts to the client. The problem is, once one video is playing - i can't do anything else. Its like the server locks up. I mean i can scrub that video, i can do anything to that page. I just can't navigate away. But i can open a new browser and play a new video. But again, once that first one is playing, or even paused, i can't do anything else. That is of course until i restart apache. Any ideas on how to stream these large files better? I have a feeling they are set to stream and never stop. This is the code for that Code: [Select] function rangeDownload($file) { $fp = @fopen($file, 'rb'); $size = filesize($file); // File size $length = $size; // Content length $start = 0; // Start byte $end = $size - 1; // End byte // Now that we've gotten so far without errors we send the accept range header /* At the moment we only support single ranges. * Multiple ranges requires some more work to ensure it works correctly * and comply with the spesifications: http://www.w3.org/Protocols/rfc2616/rfc2616-sec19.html#sec19.2 * * Multirange support annouces itself with: * header('Accept-Ranges: bytes'); * * Multirange content must be sent with multipart/byteranges mediatype, * (mediatype = mimetype) * as well as a boundry header to indicate the various chunks of data. */ header("Accept-Ranges: 0-$length"); // header('Accept-Ranges: bytes'); // multipart/byteranges // http://www.w3.org/Protocols/rfc2616/rfc2616-sec19.html#sec19.2 if (isset($_SERVER['HTTP_RANGE'])) { $c_start = $start; $c_end = $end; // Extract the range string list(, $range) = explode('=', $_SERVER['HTTP_RANGE'], 2); // Make sure the client hasn't sent us a multibyte range if (strpos($range, ',') !== false) { // (?) Shoud this be issued here, or should the first // range be used? Or should the header be ignored and // we output the whole content? header('HTTP/1.1 416 Requested Range Not Satisfiable'); header("Content-Range: bytes $start-$end/$size"); // (?) Echo some info to the client? exit; } // If the range starts with an '-' we start from the beginning // If not, we forward the file pointer // And make sure to get the end byte if spesified if ($range == '-') { // The n-number of the last bytes is requested $c_start = $size - substr($range, 1); } else { $range = explode('-', $range); $c_start = $range[0]; $c_end = (isset($range[1]) && is_numeric($range[1])) ? $range[1] : $size; } /* Check the range and make sure it's treated according to the specs. * http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html */ // End bytes can not be larger than $end. $c_end = ($c_end > $end) ? $end : $c_end; // Validate the requested range and return an error if it's not correct. if ($c_start > $c_end || $c_start > $size - 1 || $c_end >= $size) { header('HTTP/1.1 416 Requested Range Not Satisfiable'); header("Content-Range: bytes $start-$end/$size"); // (?) Echo some info to the client? exit; } $start = $c_start; $end = $c_end; $length = $end - $start + 1; // Calculate new content length fseek($fp, $start); header('HTTP/1.1 206 Partial Content'); } // Notify the client the byte range we'll be outputting header("Content-Range: bytes $start-$end/$size"); header("Content-Length: $length"); // Start buffered download $buffer = 1024 * 8; while(!feof($fp) && ($p = ftell($fp)) <= $end) { if ($p + $buffer > $end) { // In case we're only outputtin a chunk, make sure we don't // read past the length $buffer = $end - $p + 1; } set_time_limit(0); // Reset time limit for big files echo fread($fp, $buffer); flush(); // Free up memory. Otherwise large files will trigger PHP's memory limit. } fclose($fp); } Hi, I've been trying,for a while now, to stream mp3 using MING extension. I have the later XAMPP 1.7.4 installed. So the code goes something like : Code: [Select] <?php $m = new SWFMovie(); $m->setRate(12.0); $m->streamMp3(file_get_contents('a.mp3',"r")); $m->setFrames(1420); header('Content-type: application/x-shockwave-flash'); $m->output(); ?> 'a.mp3' is in the same directory as of the php file. It opens the file, reads the file - but i've no idea what is it doing after that. There are no errors or warnings. A white ' FLASH ' screens comes up. Thats all. I've tried googling this thing up. I didn't find anything. What am I doing wrong? Hi, i am trying to stream a video from Rackspace clould files account. I could simply get the url of the video file and stream the video using the php api they have provided. But they have provided a stream function which they suggest to be used for video streaming or for large images. Here is the code of the api : /** * Streaming read of Object's data * * Given an open PHP resource (see PHP's fopen() method), fetch the Object's * data and write it to the open resource handle. This is useful for * streaming an Object's content to the browser (videos, images) or for * fetching content to a local file. * * Pass in $hdrs array to set specific custom HTTP headers such as * If-Match, If-None-Match, If-Modified-Since, Range, etc. * * Example: * <code> * # ... authentication/connection/container code excluded * # ... see previous examples * * # Assuming this is a web script to display the README to the * # user's browser: * # * <?php * // grab README from storage system * // * $my_docs = $conn->get_container("documents"); * $doc = $my_docs->get_object("README"); * * // Hand it back to user's browser with appropriate content-type * // * header("Content-Type: " . $doc->content_type); * $output = fopen("php://output", "w"); * $doc->stream($output); # stream object content to PHP's output buffer * fclose($output); * ?> * * # See read() above for a more simple example. * # * </code> * * @param resource $fp open resource for writing data to * @param array $hdrs user-defined headers (Range, If-Match, etc.) * @return string Object's data * @throws InvalidResponseException unexpected response */ function stream(&$fp, $hdrs=array()) { list($status, $reason) = $this->container->cfs_http->get_object_to_stream($this,$fp,$hdrs); #if ($status == 401 && $this->_re_auth()) { # return $this->stream($fp, $hdrs); #} if (($status < 200) || ($status > 299 && $status != 412 && $status != 304)) { throw new InvalidResponseException("Invalid response (".$status."): " .$reason); } return True; } Here is the sample code they shared : $output = fopen("test.jpg", "w"); $pic->stream($output); fclose($output); If i echo the $pic variable, it just contains the name of the file. How do i display the image and how do i use this for streaming a video? Iam very new to php, so kindly help me. Thanks. I am currently streaming my mp4 files perfectly fine using php. My issue is, how do I detect when the video is either no longer being watched, or disconnected? I need to run a function after this so that I know the video is no longer being watched for analytics. Is there a way maybe with sockets or something? I'm currently using this.
if (file_exists($request)) { $fp = @fopen($request, 'rb'); $size = filesize($request); $length = $size; $start = 0; $end = $size - 1; header("Content-Type: video/mp4"); header('Accept-Ranges: 0-' . $length); if (isset($_SERVER['HTTP_RANGE'])) { $c_start = $start; $c_end = $end; list(, $range) = explode('=', $_SERVER['HTTP_RANGE'], 2); if (strpos($range, ',') !== false) { header('HTTP/1.1 416 Requested Range Not Satisfiable'); header('Content-Range: bytes ' . $start . '-' . $end . '/' . $size); exit(); } if ($range == '-') { $c_start = $size - substr($range, 1); } else { $range = explode('-', $range); $c_start = $range[0]; $c_end = (isset($range[1]) && is_numeric($range[1]) ? $range[1] : $size); } $c_end = ($end < $c_end ? $end : $c_end); if (($c_end < $c_start) || (($size - 1) < $c_start) || ($size <= $c_end)) { header('HTTP/1.1 416 Requested Range Not Satisfiable'); header('Content-Range: bytes ' . $start . '-' . $end . '/' . $size); exit(); } $start = $c_start; $end = $c_end; $length = ($end - $start) + 1; fseek($fp, $start); header('HTTP/1.1 206 Partial Content'); } header('Content-Range: bytes ' . $start . '-' . $end . '/' . $size); header('Content-Length: ' . $length); ob_end_flush(); $buffer = 8192; $time_start = time(); $bytes_read = 0; while (!feof($fp) && (($p = ftell($fp)) <= $end)) { $response = stream_get_line($fp, $buffer); echo $response; $bytes_read += strlen($response); if (30 <= time() - $time_start) { file_put_contents('/var/www/html/movieCon/'.$user.'_'.$token.'_'.$movie_id.'.con', time()); $time_start = time(); $bytes_read = 0; } } fclose($fp); exit(); }
I have a website http://www.pbm-biz.com/cricket/ where I am streaming Live Cricket world cup matches. My question is that during the streaming, I would like to keep the code in PHP so that others don't copy it. I can't find any solution. Any suggestions. Thanks, Faisal i am a student and trying to figure out why this is not working for me i am trying to pull from my .txt file and add the lines. $numOrders should be 20 and $numCopies should be 52. it keeps telling me --Warning: feof() expects parameter 1 to be resource, string given on line 25. i really am having big trouble trying to understand how to use the while loop for this. any help would be great. here is my html code <html> <head> <title>Software1</title> <link rel ="stylesheet" type="text/css" href="sample.css" /> </head> <body> <h1>SOFTWARE ORDERS: REPORT</h1> <form action = "software1Boles.php" method = "post" > <p><input type = "submit" value = "Display the Report" /></p> </form> </body> </html> my php code <?php $totalCopies = $_POST['totalCopies']; $totalOrders = $_POST['totalOrders']; $nextOrder = $_POST['nextOrder']; $totalCopies = 0; $totalOrders = 0; $orderFile = fopen("ordersBoles.txt", "r"); $nextOrder = fgets ($orderFile); while (!feof($nextOrder)) { list($totalCopies, $totalOrders) = explode (":", $nextOrder); if ($totalCopies >=1 and $totalCopies >=1) { $totalCopies = $totalCopies + $nextOrder; $totalOrder = $totalOrder + $nextOrder; } $nextOrder = fgets($orderFile);} fclose($orderFile); print ("<h1>SOFTWARE ORDERS: REPORT</h1>"); print ("<p>TOTAL COPIES ORDERED: $totalCopies</p>"); print ("<p>TOTAL ORDERS: $totalOrders</p>"); ?> </body> </html> and my .txt file 1 Linux:1 2 Macintosh:1 3 Windows:1 4 Macintosh:1 5 Macintosh:2 6 Linux:5 7 Macintosh:10 8 Windows:10 9 Macintosh:1 10 Windows:1 11 Windows:1 12 Linux:1 13 Macintosh:5 14 Linux:4 15 Windows:1 16 Macintosh:1 17 Windows:1 18 Linux:2 19 Macintosh:2 20 Windows:1 21 anything you can give me would help alot, thanks i have been given this task in in uni. i was wondering it some one would be so kind to help me with it. all i have so far is this <?php for($x=1; $x<=3; $x=$x+1) { print "$x <br>"; } if ($x== "A") { } ?> the task is below Generate a number between 1 & 3 If 1 then assign A, If 2 then assign B, If 3 then assign C Add to a wordstring (using string concatenation with .) We need 3 letters generated to give a 3 letter word For loop (3) Generate a number between 1 & 3 If 1 then assign A, If 2 then assign B, If 3 then assign C Add to a wordstring (string concatenation with .) End loop Print 3 letter word Hello everyone, I've already posted a question trying to resolve my problem, but I've changed my code so much, I figured it may be best just to post a new thread with a better explanation of what I'm trying to do. Anyway, here's what I've got: I have a database with 2 tables: products and reservations. I have 3 products for now, that can be reserved for any date. I'm trying to create a page that will display all of the available products for a specific date. The user selects the date they want to check, and then the code should check their selected date and compare it with the database to display everything that is available on that date. The database looks like this: Products Table: prodid prodname 01 item 1 02 item 2 03 item 3 Reservations Table: prodid resdate 01 02/22/2012 01 02/23/2012 03 02/22/2012 Here is the code that I have now: Code: [Select] <?php $resultres = mysql_query("SELECT `prodid` FROM reservations WHERE `resdate` = '$resdate'") or die (mysql_error()); while ($rowres = mysql_fetch_row($resultres)) { $resprodid = $rowres[0]; $resultavail = mysql_query("SELECT `prodid` FROM products WHERE `prodid` != '$resprodid'") or die (mysql_error()); while ($rowavail = mysql_fetch_row($resultavail)) { $prodid = $rowavail[0]; echo $prodid; echo $proname; } } ?> When I select 02/21/2012, I get no results, where I should get all three products as a result, because none of them are reserved on this date. When I select 02/22/2012, I get a result of these products, in this order: 02, 03, 01, 02. I should get a result of ONLY 02, because this is the only product that isn't reserved for this date. When I select 02/23/2012, I get a result of 02 and 03, which in this case would be the correct return, because 01 is the only one reserved for this date. Any idea what I'm doing wrong here and how to fix it? Any help is GREATLY appreciated! I do not have the option that I know of to do a LIMIT 10 in my odbc query. How can I get it to count the number of while loops and stop at 10? Code: [Select] while (odbc_fetch_row($rs)) { } Hi All, and thanks for your help on my last problem now solved. What i am doing is building a job site and it needs info put in from job seekers regarding their qualifications. Some will have 2 some may have 10 and so on. I need to set up a system that I can put say 10 text boxes in a form that can then go in a MySQL. I only want the filled out boxes to go into the database and not the ones left blank. I have no idea as to where to start with but I think I need to loop through until it comes to the last filled out box but not enter the blank text boxes. i have no idea where to start on this one so if any one has thoughts on this it would be great. Thank you all for your help in the past. Did PHP a few years ago and for the life of me i can't work out why this doesn't work: Code: [Select] for ( $counter2=1; $counter2 < 1000; $counter2++) { for ( $counter1=1; $counter1 < 1000; $counter1++) { echo "Fixed bug"; } } and yet this does Code: [Select] for ( $counter2=1; $counter2 < 100; $counter2++) { for ( $counter1=1; $counter1 < 100; $counter1++) { echo "Fixed bug"; } } I tested it because I have a rather large amount of data to retrieve from an XML file and i kept receiving errors Hi guys
I just wanted to make a short post and talk about an issue im having and maybe get some advice. I know that loops aren't that hard to grasp and I shouldn't be having this much trouble understanding them but im just not getting it. I dont really know how to explain it but loops (like looping through mysql in an update statement) is foren to me and i was wondering if anyone had any advice for maybe learning them or maybe something im just over looking or maybe some good tutorials. I really want to get them down and start using them in scripts i right but im getting so frustrated because i constantly hear how easy they are and im just not getting it. if i wasn't clear please let me know and ill try to explain more clearly thanks guys JL i am having issues with my class work. this needs to start at the $startNum and end with the $endNum and display results in the increments submitted by the html. I can not get it to print out correctly it is supposed to say: The square of $startNum is $square //until it hits the end number and is going up by the correct increments, It wont go up by any increments and only shows a list if i leave out the increment-----any suggestions??? please i have to keep it very simple since i am just learning-ty html </head> <body> <h1>Squares</h1> <p> <form action = "squares2Boles.php" method = "post" > <p>Start with: <input type = "text" size = "5" name = "startNum" /> </p><p>End with: <input type = "text" size = "5" name = "endNum" /> </p><p>Increment by: <input type = "text" size = "5" name = "increment" /> </p><p><input type = "submit" value = "Display the Squares" /></p> </form> </body> </html> my php: <html> <head> <title>Squares</title> <link rel ="stylesheet" type="text/css" href="sample.css" /> </head> <body> <?php $startNum = $_POST['startNum']; $endNum = $_POST['endNum']; $increment = $_POST['increment']; $square = $_POST['square']; print ("<h1>SQUARES</h1><hr />"); for ($startNum = $startNum; $startNum <= $endNum; $startNum = $startNum + $increment) { $square = $startNum * $startNum; print ("The square of $startNum is $square<br />"); } print ("<hr />"); ?> </body> </html> I created the code below and it outputs the following number output: 1111111773526604115551144611337112281111221111345 6789101121111100352004110051100611007110081100221 1003456789101141111100352004110051100611007110081 1002211003456789101151111100352004110051100611007 1100811002211003456789101123111110035200411005110 06110071100811002211003456789101134 Anyways if you look at the code, I need to be able to add the values on a single colony, idcol, with the same type and subtype, btid/stid, generated as the $prod variable. buildings with the same subtype generate the same resource, in this case, several iron mines and a single copper mine are present, but there are also 9 other types of resource buildings. How do I collect on the prods which go together? Code: [Select] <?php $dbhost = 'localhost:3306'; $dbuser = 'lordofth_aos'; $dbpass = 'flarge'; $dbname = 'lordofth_aos'; $conn = mysql_connect($dbhost,$dbuser,$dbpass) or die ('Error connecting to mysql'); mysql_select_db($dbname); $query="SELECT id FROM users"; $result=mysql_query($query); $num=mysql_num_rows($result); $i=0; $idn=1; while($i<$num){ $queryii="SELECT idcol FROM colony WHERE id=$idn"; $resultii=mysql_query($queryii); $numt=mysql_num_rows($resultii); $id=mysql_result($result, $i); echo $id; $ii=0; $ibt=1; while($ii<$numt){ $querypty="SELECT btid FROM ptypes WHERE btid=$ibt"; $resultpty=mysql_query($querypty); $numpty=mysql_num_rows($resultpty); $idcol=mysql_result($resultii, $ii); echo $idcol; $bt=0; $btid=mysql_result($resultpty, $bt); echo $btid; $bte=1; while($bt<$numpty){ $querystid="SELECT stid FROM ptypes WHERE stid=$bte"; $resultstid=mysql_query($querystid); $numstid=mysql_num_rows($resultstid); $st=0; $stid=mysql_result($resultstid, $st); echo $stid; $ste=1; while($st<$numstid){ $bidum=0; $querybpid="SELECT bpid FROM blueprints WHERE btid=$btid AND stid=$stid"; $resultbpid=mysql_query($querybpid); $numbpid=mysql_num_rows($resultbpid); while($bidum<$numbpid){ $bidumb=0; $bidumbg=mysql_result($resultbpid, $bidum, 'bpid'); echo $bidumbg; $querybid="SELECT COUNT(bid) AS count, workers, efficiency FROM buildings INNER JOIN blueprints ON buildings.bpid=blueprints.bpid WHERE blueprints.btid=$btid AND blueprints.stid=$stid AND buildings.bpid=$bidumbg AND buildings.idcol=$idcol"; $resultbid=mysql_query($querybid); $staff=mysql_result($resultbid, $bidumb, 'workers'); $effic=mysql_result($resultbid, $bidumb, 'efficiency'); $count=mysql_result($resultbid, $bidumb, 'count'); echo $staff; echo $effic; echo $count; $prod=$staff*$effic*$count; echo $prod; $bidumb++; $bidum++; } $st++; $ste++; } $bt++; $bte++; } $ii++; } $i++; $idn++; } ?> Man this is really driving me nuts. I can see my array values with echo inside the loop but outside nothing is shown. What am I missing here? If anything it should show the last value in the loop. while ($x = mysql_fetch_array($query_name,MYSQL_NUM)) { echo $x[0]; } echo $x[0]; Hi @ all, I'm building a simpel agenda function for my boss Now I've ran in some basic query problems. First the code: <? include_once('../../config/config.php'); $query = "SELECT id, bedrijfsnaam, bezoeken FROM clients WHERE actief = 'ja' AND bezoeken > 0 ORDER BY id ASC"; $result = mysql_query($query)or die ("Query kon niet worden uitgevoerd"); echo '<table style="border-collapse:collapse;">'; while($row = mysql_fetch_assoc($result)){ extract($row); $bedrijfsnaam = ucfirst($bedrijfsnaam); $bedrijfsnaam = htmlentities($bedrijfsnaam); if($rowcount % 2 == 0) { echo '<tr onMouseover="this.style.backgroundColor=\'#649fbe\'"; onMouseout="this.style.backgroundColor=\'#fff\';" style="background-color:#fff; border-bottom: 1px solid black;">'; } else { echo '<tr onMouseover="this.style.backgroundColor=\'#649fbe\'"; onMouseout="this.style.backgroundColor=\'#f2f2f1\';" style="background-color: #f2f2f1; border-bottom: 1px solid black;">'; } $rowcount ++; // huidige jaar ophalen $huidig_jaar = date("Y"); echo' <td style="width: 313px; font-family: verdana; font-size: 10px; font-weight: bold; min-height: 20px;">'.$bedrijfsnaam.'</td> <td style="width: 8px; font-family: verdana; font-size: 10px; font-weight: bold;">'.$bezoeken.'</td> <td style="width: 100px; text-align: center; border-left: 1px solid black;">'; //januari ophalen $query1 = "SELECT datum FROM planning WHERE id = '.$id.' AND YEAR(datum) = '$huidig_jaar' AND MONTH(datum) = '01' ORDER BY id ASC"; $result1 = mysql_query($query1)or die ("Query 1 kon niet worden uitgevoerd"); $num1 = mysql_num_rows($result1); echo $num1; echo' </td> <td style="width: 100px; text-align: center; border-left: 1px solid black;">'; //februari ophalen $query2 = "SELECT datum FROM planning WHERE id = '.$id.' AND YEAR(datum) = '$huidig_jaar' AND MONTH(datum) = '02' ORDER BY id ASC"; $result2 = mysql_query($query2)or die ("Query 1 kon niet worden uitgevoerd"); $num2 = mysql_num_rows($result2); echo $num2; echo' </td> <td style="width: 100px; text-align: center; border-left: 1px solid black;">'; //februari ophalen $query3 = "SELECT datum FROM planning WHERE id = '.$id.' AND YEAR(datum) = '$huidig_jaar' AND MONTH(datum) = '03' ORDER BY id ASC"; $result3 = mysql_query($query3)or die ("Query 1 kon niet worden uitgevoerd"); $num3 = mysql_num_rows($result3); echo $num3; echo' </td> <td style="width: 100px; text-align: center; border-left: 1px solid black;"></td> <td style="width: 100px; text-align: center; border-left: 1px solid black;"></td> <td style="width: 100px; text-align: center; border-left: 1px solid black;"></td> <td style="width: 100px; text-align: center; border-left: 1px solid black;"></td> <td style="width: 100px; text-align: center; border-left: 1px solid black;"></td> <td style="width: 100px; text-align: center; border-left: 1px solid black;"></td> <td style="width: 100px; text-align: center; border-left: 1px solid black;"></td> <td style="width: 100px; text-align: center; border-left: 1px solid black;"></td> <td style="width: 100px; text-align: center; border-left: 1px solid black;"></td> </tr> '; } echo '</table>'; ?> In the first query I'll get the id from all the clients in the database, now I want to use that id's in the upcoming query's (WHERE id = '.$id.'), but it allways uses the first id and not all the id's. $num always has the same result. Can anyone put me in the right direction? Thank you Sorry for my bad English, I'm dutch, can't help it I blame my parents... I hope it's enought information.... Greetings XistenceNL My goal here is to have it foreach group from the DB it'll create a new frameset with the groupName as the legend and then under each of those it will create another foreach for each of the fields inside of that group that has a enabled value of 0 from the db. Both queries work correctly. I just get trouble writing foreach loops and I'm not sure how this one is going to work out. Code: [Select] <?php session_start(); // Access the existing session // Include the database page require ('../../inc/dbconfig.php'); $defaultCharID = $_SESSION['defaultCharID']; $styleIDQuery = " SELECT characters.styleID FROM characters WHERE characters.ID = '" . $defaultCharID . "'"; $styleIDResult = mysqli_query ( $dbc, $styleIDQuery ); // Run The Query $row = mysqli_fetch_array( $styleIDResult, MYSQL_ASSOC ); $styleID = $row[ 'styleID' ]; $biofieldsQuery = " SELECT fields.*, groups.* FROM fields INNER JOIN groups ON fields.groupID = groups.ID WHERE groups.styleID = '" . $styleID . "' AND fields.styleID = '" . $styleID . "' AND groups.enabled = 0 AND fields.enabled = 0"; $biofieldsResult = mysqli_query ( $dbc, $biofieldsQuery ); // Run The Query $row = mysqli_fetch_array( $biofieldsResult, MYSQL_ASSOC ); $groupName = $row[ 'groupName' ]; ?> <script type="text/javascript"> $(document).ready(function() { }); </script> <!-- Title --> <div id="title" class="b2"> <h2>Character Management</h2> <!-- TitleActions --> <div id="titleActions"> <!-- ListSearch --> <div class="listSearch actionBlock"> <div class="search"> <label for="search">Recherche</label> <input type="text" name="search" id="search" class="text" /> </div> <div class="submit"> <button type="submit" id="search-button" class="button"><strong><img src="img/icons/search_48.png" alt="comments" class="icon "/></strong></button> </div> </div> <!-- /ListSearch --> </div> <!-- /TitleActions --> </div> <!-- Title --> <!-- Inner Content --> <div id="innerContent"> <form action="#" id="bioForm" > <fieldset> <legend><?php echo $groupName; ?></legend> <div class="field required"> <label for="matchType">Match Type Name</label> <input type="text" class="text" name="matchType" id="matchType" title="Match Type Name"/> <span class="required-icon tooltip" title="Required field - This field is required, it cannot be blank, and must contain something that is different from emptyness in order to be filled in. ">Required</span> </div> <input type="submit" class="submit" name="submitMatchType" id="submitMatchType" title="Submit Match Type" value="Submit Match Type"/> </fieldset> </form> </div> <!-- /Inner Content --> |