Define The Maximum Result Record
I would like to define the maxmum record that are shown after a search.
Say the total result has 20000 records
I want the result page show only the first 50 out of the 20000, and ignore the rest.
I heard someone say i could "Change the SQL to "SELECT TOP 50...."
I'm not sure how to do that, can anyone help? ....
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Setting A Maximum Limit On A Php/mysql Result?
I am using PHP and MySQL to do this script. I want to have a table that contains only numbers for data and then add them all up as a result to display and that I have accomplished with no problem and then I want to display a percentage of that number to the public however that also I have accomplished with no problem using round()... The problem is I am trying to set a maximum number that it displays. I want it to display 1-500 no matter what the number is or the decimal it may have is provided it doesnt exceed 500 but once it does I want it to display 500 as the limit so even if it is say 674 I want it to only display 500. How would I go about doing this? The sql I am using for the adding is SELECT SUM which works just fine and I am using round( $total_number *.15, 2) to display the percentage number of 15%.
Function To Test If Mysql_fetch_array($result) Pointing Last Record?
I try to perform multiple insert statment, but the problem is in the below codes, the last sql concatenation ends with ",". I wonder if there is any php function to test if the $result set contains the last record. ------------------ //Get topic id of vote_topic from last insert record $sql_topic_id = "SELECT topic_id FROM vote_topic ORDER BY topic_id DESC LIMIT 1"; $result = mysql_query($sql_topic_id,$conn); $row = mysql_fetch_array($result); //Get all student info from stuinfo $sql_strn = "SELECT strn from stuinfo"; $result1 = mysql_query($sql_strn,$conn); //Dump all student strn into vote_status. //Multiple insert statement? How? $sql2 = "INSERT INTO vote_status (strn,topic_id) VALUES "; while ($row1 = mysql_fetch_array($result1)){ $sql2 .= "VALUES ('".$row1[strn]."','".$row[topic_id]."'),";} mysql_query($sql2,$conn); ---------------------
Can You Define An Array Constant With Define()?
I have a list of related defines like: define( "FRUIT1", "apple" ); define( "FRUIT2", "banana" ); define( "FRUIT3", "orange" ); I'd rather keep these defined in one file only so that later when I decide to modify or add to the list I don't have to mess with all my other files. Elsewhere, I'd like to loop through the constants and be able to obtain their values. This code is fine except that printf() and echo() return the constant name not the value: $i = 1; while( defined( "FRUIT$i" ) ) { echo 'FRUIT$i' $i++; } Ideally, I could define an array constant like this: define( "FRUIT", { "apple", "banana", "orange" } ); but I don't think PHP allows this. I'd rather not define these as variables and have to mess with calling them in as global variables later, etc. Any ideas? At the very least, perhaps someone knows how to trick a function like echo() to 'echo( FRUIT1 )' rather than 'echo( "FRUIT1" )'.
Compare Record With Session Variable And Update Record If Different
I'm trying to figure out how to create a session variable from a recordset field value in a mySQL database and compare this with subsequent values from the same field each time the page reloads. When the value of the field changes (as a result of a user update) I want to trigger an event (redirecting to another page). It's probably a very basic PHP function but I am a newbie with this language.
Define()
When I create different directories, my header and footer no longer show up because they're not in the same directory. I want to create a directory structure to make it a little easier for me to navigate and organize my site. I've seen define() used to set a directory path for includes, but i'm unsure of how it works. I'm thinking I would have to make a config.php and set all my path to my included files. I'm lost after that.
Define Vars
I have a form with this vars: var1 .... var50 is there any workaround that instead i do this: PHP Code:
PHP3 And Define()
I know this might be an odd question, but does PHP version 3 support the define() function? What little PHP 3 documentation I have doesn't seem to contain the function, but I would think PHP 3 would support constants. I realize that upgrading and using PHP 4 and PHP 5 would give me the define() function, but that's not what I'm looking for, just the answer to this specific question. When the manual says, "PHP 4, PHP 5" and excludes "PHP 3" it's not always accurate, as there are many functions supported by PHP 3 not listed in the current manual.
Strpos() To Define PHP SELF
I'm trying to make a script that can be placed at the top of an included file. For example if I place this script in config.php then only index.php or admin.php could include it without dying with the error. For some reason the if statement doesn't work as I had expected. Any file (eg: test.php) I include config.php into, still loads without dying. $self = $_SERVER["PHP_SELF"]; $index = strpos($self, "index.php"); $admin = strpos($self, "admin.php"); if (($index === false) ¦¦ ($admin === false)) { die ("You can't access this file directly..."); } However this works... if ($index === false) // or admin.php, either works, but only one. { die ("You can't access this file directly..."); } I've also tried doing this with index.php and admin.php in an array, and it still doesn't work as expected. I'd prefer to have the script be something like the following. Naturaly it does notwork either when having two strpos() functions. $self = $_SERVER["PHP_SELF"]; if ((!strpos($self, "index.php")) ¦¦ (!strpos($self, "admin.php"))) { die ("You can't access this file directly..."); }
How To Define A New Global Function?
Very frequently, I need to use codes like this to see output clearly: $a=print_r($var,true); echo "<pre>$a</pre>"; How can convert this piece of code to a global function (for example: echopre) in Php so that I can use echopre($data) anywhere in php program (in my server)?
Universally Define __call( ) ?
I want to universally define the __call() method, so that every class in my application does the same thing if a non-existant function is called. In actionscript I could do this by adding the definition to the prototype for Object. Is there any way to do that in php 5? I could make every one of my classes inherit from like an Object class that I define,
How Do You Define A Unique Visitor?
On trackers you see 2 different number for visitors on your webpage, uniques and raws. But how is the unique visotor defined? And how do they accomplish this? My thoughts have gone in the direction of a visitor that haven't visited the website for a periode of 24 hours, and is beeing accomplished but setting a cookie on the surfers computer.
Difference Between 'const' And 'define()'
What is the difference between 'const' and 'define()' ? When would I prefer using 'const' over 'define', or vice versa? It seems if i do: const secondsInMinute = 60; define("secondsInMinute", 60); Aren't these two the same thing?
How To Define A Member Variable?
PHP barfs (on line 3) when I define a member variable like this: class Foo() { $num; function DoSomething() { $num = 2 + 3; } } I want to do this so I can access if from another function. How can this be done?
Define A Function's Name With A Variable?
Does anyone know if you can define a function name using a variable? For example: $var = 'my_function_name'; function $var() { } I know you can't do that verbatim, as I've tried, but I was wondering if there is some workaround that would be valid?
I Want To Define Something Inside A File Into A Variable
I want to open and read a file into a variable. Then i want to define things in that variable to a diffrent variable.Example: The variable page = <html><head><title>{title}</title></head> If there any way i could define {titile} to write out the contents in trhe variable $title ? Here is what my current code looks like: define("{title}", $title); $placeforstyle = "styles/style.php"; $placeforstyle = $mainactual.$placeforstyle; $fd = fopen($placeforstyle, "r"); $outputstring = fread($fd, filesize("$placeforstyle")); fclose($fd); $fp = fopen($pagesactual.$filename, "w"); fwrite($fp, $outputstring); fclose($fp);
Performance-define Vs. Global Vars
I'm interested to know which one is better--define or global variables especially for config stuffs. For example, osCommerce use something like: define('db_user', 'xx'); whereas phpMyAdmin uses like $config['server']['host'] = 'localhost' and other few software use $db_pass = 'foo' I'm much interested to know which one is good. Isn't hash array like $config['server']['host']
Define()ing Constants Vs Global Variables
I'd like to open a discussion regarding define()ing constants for use throughout a script, or simply declaring global variables. I'd like to know who uses what and why, and what you think the advantages / disadvantages of either are. Example PHP Code:
Debugging User Define Functions
when i was coding my own functions, it comes a time that i don't know if what part of my code was the bug, pls tell me how to best debug my own functions, if it is returning the right value or not.
Define Root Directory For Images
I want to have a root directory from which the images on different pages shall be displayed. I define it here: define('image_root', '/web/d2/w/mydomain/mydomain.com/images/'); Then I try to pass this path to the image: $imageurl = image_root . $myrow['image']; echo "<div id=left><img src='$imageurl' border=1></div>";But it doesn't work... Any ideas?
How To Replace Define In A Require File With Mysql?
I have a file linked with require into my program with statements like: define("_ADDRESS","Address"); define("_CITY","City"); I would like to replace this with a mysql table with these two fields (out of many other fields). How can I do that?
Define/cannot Get Celcius To Display In Weather Script
I have two php pages, the first of which contains a "config section." In the config section of the first page, I have defined Celsius by inserting the following: define('DEFAULT_UNITS', "c"); It seems as of the problem is the weather class assumes the default is Fahrenheit and will not switch to Celsius because it has no idea what is stored in DEFAULT_UNITS. Can someone troubleshoot? I've been staring at this so long that I'm probably looking right through the answer. Code:
Maximum Sizes
I have few more questions what is maximum string size, maximum header size for sending e-mails & maximum html e-mail size if we want to send html content in body and set content type tex/html. How to configure linux server to increase mailbox size so that I can send huge mails. I'm really in a great trouble, It will be of great help to me if any one tells me this maximum sizes and how to handle if maximum size exceeds.
Maximum And Minimum Value
I want to find the maximum and minimum, average value from the text file <? $lines = file('./data.txt'); foreach ($lines as $line) { $text_line = explode(":" , $line); $text_line1 = explode(" " , $text_line[2]); array_sum($text_line1); } ?> This method I am not able to get the array sum..... How to get the numerical value of numbers from strings When I explode the line it is in string format. I should find the array_sum and max() which I values are in numeric not string.
Getting Maximum Value Inside A Loop
I'm using something like this, to output a table of rows: // Set max_val $max_val = 0; // Do the loop while ($row = mysql_fetch_assoc($result)) { $max_val = max($max_val, $row['integer']); // etc etc echo $max_val; // etc etc } I want the maximum value of $row['integer'] to be available in every row. The above example does this, with the exception of the first (top) row of the table, where $max_val is then the value of $row['integer'] for that row - not the actual maximum for all rows.
What Is The Maximum Length Of A String?
the php manual gave an example where you can pull an entire file into one string: $fcontents = join( '', file( 'http://www.php.net' ) ); is there a maximum size that this string can hold, therefore a maximum size file I could import...what happens when this max is reached...error, or just cuts off..?
Maximum Dropdown Size
I have a strange issue with dropdowns. Using php4, mySQL5, Apache 2 on a fast XP pro PC, I have a form which requires 5 dropdowns populated with indentical values. I extract the values using SQL and populate 2 variables and use a for-next loop to create the dropdown. The dropdown contains some 310 items! It works beautifully if I have 1 or 2 dropdowns but as soon as I add more it partially creates the 3rd and just stops until it times out! All 5 work because I have altered their positions but it always stops part way through creating the 3rd dropdown. I tried an alternative method by doing away with the variables and constructing the dropdowns with a 'while' statement reading through the results of my SQL and got exactly the same problem only 2 and a bit dropdowns. Stopping it running after a few seconds or several minutes makes no difference, it seems to reach a certain point and just stop - no error messages or anything! I have tried increasing the resourses in my php.ini file but this also made no difference. Can anyone suggest an alternative or a fix?
Maximum Integer Size?
I'm trying to figure out how big integers in PHP can be and am having some difficulty. My first idea was to try something like this: <? for ($bits=0; (1<<($bits+1)) > (1<<$bits); $bits++); echo $bits; ?> The result was 30. This, however, is incorrect as the following demonstrates: <? $num = 1<<30; echo "num = $num "; echo 'num<<1 = '.($num<<1)." "; echo 'num*2 = '.($num*2)." "; ?> That my first idea would return the wrong result doesn't surprise me, though, since bitwise operators in PHP are treated as arithematic ones and not logical ones. So I came up with another test. <? for ($bits=0; pow(2,$bits+1) > pow(2,$bits); $bits++); echo $bits; ?> In Windows XP, I got 1024 back. On Linux 2.6.13.2 and 2.4.28 (as reported by phpinfo), all I get are timeout errors. So I decided to make my script more efficient and hopefully faster: <? $x = 2; $y = 1; for ($bits=1; ($x*=2) > ($y*=2); $bits++); echo $bits; ?> On Windows XP, I again got 1024 back, whereas on Linux, I again got timeout errors.
Using SELECT To Just Find Row With Maximum Value
how do i do a SELECT statment that will just query a table to find the row with the maximum of a declared field. for example, if i have a table of customers and i would like to get the value of the last customer to register so the SELECT statement would return only one row, how would i do this? also, the plan i have is to use a while loop (coz i dont know any other) to get the colum value of each row: $select = "SELECT ... $result = mysql_query($select, $conn); //$conn will be predefined in the code while ($row = mysql_fetch_array($result)) { $date_added = $row['date_added']; } the while loop makes sense when outputting many rows but to get the value of one column in one row, i dont know. it just seems a little inefficient to use a while loop when i know there is only one row returned (or will know), is this how all rows from a select statement are queried or is there a more efficient way of doing this for this situation?
Maximum Characters In Variables?
My concern now is that I am putting a lot of info into arrays. Is this a bad way to proceed? Or should I use a way to simply include() the file instead of loading it into a variable and printing it to screen? The reason why I have it in an array is for reading different parts of the file... But I can fix it to use the include() function for the heavy parts... Right now I am storing the same data into a database I downloaded MySQL, made the database and tables and all I need to do is insert the info... But that's another thing. I wanted to not use a database because it will save money for hosting. The site isn't going to be very big (guessing only 50 pages) so I can use only PHP.
Finding Sums Of Two Numbers Under Maximum Value
I have two, or more, numbers and a maximum value. I need to find a way to calculate all unique combinations of those numbers whose sum is less than or equal to the maximum value. For example: First Number: 6 Second Number: 8 Maximum value: 30 Possible sums: 6, 12, 14, 16, 18, 20, 22, 24, 28, 30 (how I calculated those sums is listed at the end of the message) If anyone could give me some suggestions that would be fantastic. peer // Calculated Sums 6 * 1 = 6 6 * 2 = 12 6 * 3 = 18 6 * 4 = 24 6 * 5 = 30 8 * 1 = 8 8 * 2 = 16 8 * 3 = 24; 6+8=14 6+16=22 12+8=20 12+16=28 18+8=26
Maximum Lenght Of Select Statement
Can anyone tell me what the maximium length of a SELECT statement can be. I am coming from Foxpro where 8100 char was the limit. Part of my program is a query builder and I need to build a query from a series of drop down lists users select values from.
Maximum Size Of Cookie Content
I was wondering if anyone knows whether there is a maximum size limit on a cookie content If so, 1) Is this a limit per cookie in a single domain? i.e. no single cookie value can exceed XX bytes 2) Is this a limit on all the cookies that get saved under a single domain? i.e. the total size of all the cookies cannot exceed XX bytes 3) Is the limit different from browser to browser? 4) How can I detect what the limit is?
Maximum Execution Time - 30 Seconds?
I'm writing a script that will pour over 30,000 records into my MySQL database, but PHP is bugging out and stopping after just 30 seconds....Only about a quarter of my records are getting put into the DB - is there a way I can temporarily modify the limit to this execution time, and then switch it back later if I need to?
Fetch Maximum Amount Of Chars
I want to fetch a maximum amount of chars, 10 in this case, from my mysql dbase with php. For example: If there is 'Post new topic for forum' in the table, I want to output it to the screen like this: 'Post new..'
Maximum Upload Limit Reached
Hi there I have a form on my website that can allow people to upload files via a web page. I have the MAX_FILE_SIZE value currently set at the default of 2mb. What I would like to know is, when I am uploading the files what is the easiest way to spit out an error message if the maximimum upload limit gas been reached? Currently it just goes to a refreshed upload page, but does not inform the user that the limit has gone over. Does anyone know the easiest way to do a check for this and then if it is more than they are allowed inform them??
What Is Maximum File Size For .php Files?
I'm currently working on a 56kb .php file, but my (Windows) PHP interpreter crashes very often when displaying the php script in my browser. What is the maximum size for .php files, and is 56kb actually too big? Should I split it up?
Maximum Load Time Exeeded..
I know exactly the problem... Basically I changed my method from displaying tutorials per 1000 characters, to adding a function in my bbcode to manually make a "new page". Code:
Maximum Image Height And Width
I have a form where a user can upload a file. s there a way to check the height and width and if the the dimensions fall within a certain criteria the image is uploaded? If not uploaded I want to display and error. I would like images to be no greater than 80 pixels wide by 120 pixels tall.
Catch The Maximum Execution Time Error
I have tried to code a script that allows user to upload a C source file, then compiles and runs. When i execute the compiled file, i want to impose it a time limit and if the limit exceeded, print " Time limit exceeded". <form method="POST" enctype="multipart/form-data" action="<?= $PHP_SELF ?>"> <input type="file" name="fn" size="49"> <input type="submit" value="Upload" name="B1" style="button"> </form> <?php function excess($errno, $errstr, $errfile, $errline) { print "Time limit exceeded"; } $fn=$_FILES['fn']; $max=204800; if (is_uploaded_file($fn['tmp_name'])) { move_uploaded_file($fn['tmp_name'],"test.cpp"); print "<p>Compiler feedback </p>"; if (is_file("new")) unlink("new"); if (is_file("a.out")) unlink("a.out"); passthru("g++ test.cpp 2>new"); if (!$f=fopen("new","r")) {print "error";} else { while (!feof($f)) { $s=fgets($f); echo($s); } fclose($f); } unlink("new"); if (is_executable("a.out")) { print "<p>Time limit is 60 seconds </p>"; set_time_limit(60); error_reporting(E_ALL); set_error_handler('excess'); passthru("./a.out >new"); if (!$f=fopen("new","r")) {print "error";} print "<p>Your program output </p>"; while (!feof($f)) { $s=fgets($f); echo($s); } fclose($f); } else {print "<p>Cannot compile your program </p>";} } else {echo "Submission failed";} ?> it seems like the passthru is not imposed any time limit and the script always ends regardless the source file.
Maximum Execution Time Of 30 Seconds Exceeded
I need to process every character in a file, so i open the file read in buffers of about 8192 bytes and process each buffer, then i write the output to another file. the problem is that with large files(>8Mb) i get a script error(Fatal error: Maximum execution time of 30 seconds exceeded ). I acess every character in the buffer with $chr=ord($bufferIn{$i}); (where $i=0...8192) seems like all he time the script consumes is in the for loop and the chr/ord functions. can i do something to speed things up? is there any other way of acessing a single characher except $bufferIn{$i}?
How Can I Increase The Import Maximum Size For MySql
I have a requirement for importing a sql file in my local databse.I have exported the file from the client database.That file is more than 50mb.I want to import this sql file into my local database.My Maximum import file size showin as 8mb.I tried to change by editing the ini file.But still it showing the same.I am using phpMyAdmin.Please tell me the procedure to change the Maximum File Size for Importing sql file.
Maximum File Size That Can Be Handles With A PHP Script
I am currently trying to debug a script written by my predecessor. Basically I have an HTML form that is used to upload a file that is then processed using a PHP script. It has been in frequent use but I have just been contacted because there is a PDF document that is not uploading. I reckon it may have something to do with the file size. All the previously uploaded files are relatively small (<2MB) but this one is about 5MB. When I try to upload the file using the script, which I know uploads the file as it has been in use frequently in the past and I have tested it with other files, it appears to reject it. When I do the following (before any processing when the form has been submitted): echo $_FILES['file']['size']; ....it returns zero (0) indicating that something has gone wrong although when I do the following: echo $_FILES['file']['name']; ....it returns the name. I have tried including a hidden HTML form element MAX_FILE_SIZE and setting it to exceed the file size (in bytes) but still no luck. Could it maybe be something in the files content?
How To Remove Oldest Field After Maximum Fields ?
Members of my site have a personal guestbook. I want to give them space for 100 comments. How can I achieve that if item 101 is posted, the oldest is being removed so that 100 items stay in the db ? the mySQL table PersonalGuestbook: pgID pgName pgComment pgOwner
Displaying Result 1-8, Then Result 9-17 Etc.
I dispaly the results from the database like this. <? while ($row = mysql_fetch_array($prod_result)) { $small = $row[0]; echo"<td align=center><img src="produkter/hardware/decks/$small"></strong></td>";}?> But if there are more than 8 results, I wnat to dispaly the first 8 on one page, then the next 8 on the next page...How can this be done?
FATAL ERROR:Maximum Execution Time Exceeded
I really would like to focus on the business solution this app is supposed to achieve, but there always seems to be a problem with either PHP or MySQL. I finally got everything installed and talking to one another, but now I get this error - Fatal error: Maximum execution time of 30 seconds exceeded in Unknown on line 0. All I am doing is testing the database connection. The table I am querying has one row of data and I am asking for only one value from that row. The query always takes 30 seconds. I am running this query on my local machine. I am not traversing the net or anything. Here is the code I am using . I pass in one value called login, to this page : $cnx=mysql_connect("server:/tmp/mysql.sock","user","") or die(mysql_error); mysql_select_db("database")or die(mysql_error); $qry="select SSL from SysUser where username="."'".$login."'"; echo $qry."<br>"; $recset=mysql_query($qry); while($row=mysql_fetch_object($recset)) { $ans=$row->SSL; echo 'SSL= '.$ans; } Please help me debug this speed issue.
|