-
Posts
16,734 -
Joined
-
Last visited
-
Days Won
9
Everything posted by PFMaBiSmAd
-
You can paginate an array of data by simply replacing the sql logic with equivalent array functions - <?php // pagination from db -> array $arr = range(1,32); // simulate data $rows_per_page = 15; // get total number of rows /* $query = "SELECT count(*) FROM table WHERE ..."; $result = mysql_query($query, $db) or trigger_error("SQL", E_USER_ERROR); list($numrows) = mysql_fetch_row($result); */ $numrows = count($arr); // Calculate number of $lastpage $lastpage = ceil($numrows/$rows_per_page); // condition inputs/set default if (isset($_GET['pageno'])) { $pageno = $_GET['pageno']; } else { $pageno = 1; } // validate/limit requested $pageno $pageno = (int)$pageno; if ($pageno > $lastpage) { $pageno = $lastpage; } if ($pageno < 1) { $pageno = 1; } // Find starting array index that corresponds to the requested page no $start = ($pageno - 1) * $rows_per_page; // database query /* $query = "SELECT * FROM table $limit"; $result = mysql_query($query, $db) or trigger_error("SQL", E_USER_ERROR); //... process contents of $result ... */ $page = array_slice($arr, $start, $rows_per_page, true); foreach ($page as $key=>$value){ echo "Key: $key, Value: $value<br />"; } echo "<br />"; // first/prev pagination hyperlinks if ($pageno == 1) { echo " FIRST PREV "; } else { echo " <a href='?pageno=1'>FIRST</a> "; $prevpage = $pageno-1; echo " <a href='?pageno=$prevpage'>PREV</a> "; } // Display current page or pages echo " ( Page $pageno of $lastpage ) "; // next/last pagination hyperlinks if ($pageno == $lastpage) { echo " NEXT LAST "; } else { $nextpage = $pageno+1; echo " <a href='?pageno=$nextpage'>NEXT</a> "; echo " <a href='?pageno=$lastpage'>LAST</a> "; } ?>
-
The correct syntax is - if (!$config['text']['emptyMessage']) $config['text']['emptyMessage'] = CNT_TXT_EMPTYMESSAGE; Edit: seems to be an echo in here..............
-
How Creat A Square Picture With Two Colors
PFMaBiSmAd replied to jason213123's topic in PHP Coding Help
If you want to dynamically create an image like that using php, perhaps with different colors..., you would use the GD image library functions - http://us3.php.net/manual/en/book.image.php -
Issue With Submitting Form And Storing In A Mysql Db
PFMaBiSmAd replied to daveylong's topic in PHP Coding Help
Ummm. What have you done to determine what execution path your code is taking? Do you have php's error_reporting set to E_ALL and display_errors set to ON in your master php.ini so that php would report and display all the errors it detects? What exactly do you get when you submit the form? If you get a blank page, what does the 'view source' in your browser show? -
The short-answer to preventing sql injection is to escape string data, i.e.data that is put inside of single-quotes in the query statement, and cast numerical data as the appropriate numerical data type, i.e. use intval for integers, before putting it into your query statement. You can also use prepared query statements (available using the mysqli extension or the PDO extension), where the actual query statement has place holders for the data values and any data you supply is treated ONLY as data and cannot alter the actual sql statement.
-
I'm going to guess your `catSel` column and your `category` column don't hold the same value. That's what your query and your php logic are testing for.
-
The overall problem preventing your code from working is your submit button doesn't have a name='submit' attribute, so your if(isset($_POST['submit'])){ logic is never true.
-
Thanks for the excellent contribution to the forum.
-
The undefined index error message is because form checkboxes (and radio buttons) are only submitted when they are checked. The solution is to have some validation logic in your code to test if a checkbox is set or not and take an appropriate action. if(isset($_POST['accessory'])){ // code for when this checkbox is checked } else { // code for when this checkbox is not checked } Since I don't have the slightest idea what value you want to use when a checkbox is not set, the actual coding in this example is left up to you. P.S. you need to have validation logic for ALL your form inputs and you need to escape string data and cast numerical data to the appropriate numerical data type before putting it into your query statement to prevent sql errors if the data contains sql special characters or to prevent sql injection.
-
You would do the following - 1) Use one query for all the rows you are interested in. 2) Get a count of the number of rows that query returned. 3) Generate a random number from 1 to the number of rows the query returned. 4) Use a for(){} loop, instead of the traditional while(){} loop to iterate over the rows in your result set. This will give you a loop counter variable that you can compare with the random number you generated in item #3. 5) As you are looping through the result of the query, if the for(){} loop counter variable is equal to the random number you generated, select the current option.
-
Here's the likely php change that caused the preexisting error in your code to stop returning any data (in my test above, mysql_result returned a null value when using code with the incorrect '$roomnumber' 2nd parameter) -
-
I just tried your code for one of my tables/columns, and along with that Warning about the parameter type, it doesn't fetch any data. If you change that errant parameter from '$roomnumber' to a 0 (zero), your code will fetch the value from the result of the query.
-
Aside from a Warning message, the lines of code you have posted should be producing the same result as before, Either php5 introduced that Warning message for the parameter type or the code was always producing the error, but it was hidden due to the error_reporting or display_errors/log_errors settings. Ignoring the Warning message, what else isn't working? What output are you getting v.s. what you expect?
-
Also, mysql_result is the slowest way of retrieving data because it performs a data seek, then a fetch. You should just use a mysql_fetch_assoc or mysql_fetch_row statement.
-
Automatically Setup Domain With Server
PFMaBiSmAd replied to dannyb785's topic in Other Web Server Software
Try searching for: cpanel api (application programming interface) -
I'm going to guess it 'worked' because a non-numerical string, treated as a number, is zero. What exactly is your query and code leading up to that point? Are you actually trying to fetch something other than a row 0 value?
-
As long as the class definition exists before the session_start() statement, you can create objects ($_SESSION['some_object'] = new some_class() in session variables or you can assign an object to a session variable ($some_object = new some_class(); $_SESSION['some_object'] = $some_object.) If your class makes or holds a resource (database connection, file handle,...) that resource will not persist between page requests since all resources used on any page are destroyed when the execution of that page ends. All session data is automatically serialized and unserialized by php when the data is stored to the session data file and retrieved from the session data file. There's no need to specifically serialize any data put into a $_SESSION variable.
-
To build your pagination links, while keeping any existing get parameters or letting a different section of your code set their own get parameters, see the use of http_build_query in the following pagination example - http://forums.phpfreaks.com/topic/268497-pagination/page__hl__+http_build_query#entry1378864
-
Because you are unconditionally exploding on the $fieldseparator, without regard to it being inside of a double-quoted string, you are getting an extra array element. Your parser needs to take into account the double-quoted values that contain the separator character or since fgetcsv already does this, why not just use fgetcsv?
-
Mysql Php If Column Is Not Null Update Next Column
PFMaBiSmAd replied to Simber33's topic in MySQL Help
This is only 1/5th as bad as the last person who wanted to have a table spread out like this. -
You apparently copy/pasted the code from some rich-text/formatted source. Please go back and copy/paste just the plain text from your programming editor.
-
Do you have php's error_reporting set to E_ALL and display_errors set to ON so that php would help you by reporting and displaying all the errors it detects? You likely have a path or permission problem on the newer install of php.
-
Your need to check your capitalization of the function name.
-
0.2 is grater than zero. Perhaps you meant less than 1
-
Php Not Working.
PFMaBiSmAd replied to prathameshkakade's topic in PHP Installation and Configuration
The latest VC6 version of php is 5.2.17. Why would you want to go back in time and use that version? The latest xampp version already uses the proper VC9 builds of apache and php. Why not just stick to xampp?