-
Posts
5,449 -
Joined
-
Days Won
174
Everything posted by mac_gyver
-
you would ORDER BY steamid in your query (if its not already) so that rows having the same streamid will be adjacent in the result set. then as you loop through the results to display them, you would remember (store in a php variable) the $streamid value and detect when it changes. each time it changes, you would output the new stream id heading, then output the data under that heading. BTW - you need to normalize your database tables to avoid writing a wall of code to display the result. i can replace all that if/else logic with one line of code by storing the attribute/value pairs in their own table, related back to the id in the current table. you would only store the actual data - id, ref_id, attr, value 1 x 23 42 (where x is the id these attributes corresponds to) 2 x 97 9 you can also form the strings you are echoing as one piece (will eliminate a lot of typing and typo errors.) for example, this - echo ' "' . $r['wepid'] . '"' . ' //' . $r['wepname'] . "<br />"; can be just - echo " \"{$r['wepid']}\" //{$r['wepname']}<br />";
-
LOL, the query you posted at the start of this thread is the correct syntax and we only see and can only help you based on the information you provided in your posts. in the future, copy paste the actual query/code you need help with to avoid wasting everyone's time.
-
code works for me (i ended up making the tables to test with after i posted the query in the previous thread.) how about echoing messages at various points to test what execution path, if any, it takes.
-
you already have a thread on this forum for this problem, where someone showed what the code needed to be. you seem to be just randomly throwing code up against the wall to see what sticks.
-
When closing connection when using it a lot in page
mac_gyver replied to pascal_22's topic in PHP Coding Help
what you have posted above is not valid php code and it doesn't show how you are including anything. if you altered the code for the post because it contained links in the include statements that showed your domain, i.e. include 'http://your_domain.com/topmenu.php';, then this means that you are including the pieces of your page using http requests and each of those is making its own separate database connection that counts toward the connection limit. to get actual help with what you are doing you must post actual code. ******* out your domain name if you don't want to post it, but post what you are actually doing in your code. -
When closing connection when using it a lot in page
mac_gyver replied to pascal_22's topic in PHP Coding Help
I'm kind of wondering if you are including these pieces of your page through the file system or via a http request. through the file system would use one database connection. through a http request would use a separate database connection for each include. what does one of these include statements look like? -
How to Upload Multiple Images from HTML from to FIles?
mac_gyver replied to tahakirmani's topic in PHP Coding Help
i recommend starting with the example form and form processing code in Example #3 in the php.net documentation - http://www.php.net/manual/en/features.file-upload.post-method.php this uses an array for the form fields and uses a loop to eliminate all the repetitive code. the if(){} conditional statement in that code will only be true if an image was successfully upload. -
fetching mysql rows with php ---- else part not working
mac_gyver replied to satbir's topic in PHP Coding Help
the following line is causing your script to die() when there isn't a row to fetch. remove the or die (mysql_error()) part from this line - $row = mysql_fetch_array($result) or die (mysql_error()); mysql_fetch_array() returns a false value when there is no row to fetch. this triggers the or die() part AND since this isn't a mysql error, mysql_error() doesn't display anything. -
two questions - 1) is your script using only one database connection in it or do you perhaps have multiple connections (each with different credentials or you are forcing a new connection by specifying the 4th parameter in mysql_connect())? 2) what does your access log show during these times? are there a large number of concurrent requests being made, each one using one concurrent database connection? except for a few buggy versions of php, that didn't perform garbage collection when errors occurred, the database connection should be destroyed when each instance of your script ends. if you happen to have scripts that take a long time to run after they have finished using their database connection, you can close that that connection in your code so that you don't tie up one of the alloted connections to make it available to another instance of your script. also, what is the maximum number of connections your database server has been configured to allow? if this is your server and it is set to a small default, you may simply need to set it to a larger more reasonable value for the amount of traffic your site gets.
- 16 replies
-
- max-connexion
- php
-
(and 1 more)
Tagged with:
-
i'll add an edit to my reply #5 - ... OR it means that the columns already have the values you are trying to update them to.
-
$query="SELECT COUNT(*) FROM `database` WHERE parameter_zero ='approved'"; if(!empty($_GET['first_parameter'])) { $queryPart[] = 'first_parameter=?'; $type[]='s'; $value[]=$_GET['first_parameter']; } if(!empty($_GET['second_parameter'])) { $queryPart[] = 'second_parameter=?'; $type[]='s'; $value[]=$_GET['second_parameter']; } if(!empty($_GET['third_parameter'])) { $queryPart[] = 'third_parameter=?'; $type[]='s'; $value[]=$_GET['third_parameter']; } $query.= ' AND '.implode(' AND ',$queryPart); if ($res = $con->prepare($query)) { $types = array(implode('',$type)); $refs = ref($value); $bind=array_merge($types,$refs); call_user_func_array(array($res,'bind_param'),$bind); $res->execute(); $Res = $res->get_result(); // if using mysqlnd driver, else you must use bind_result() list($cRes) = $Res->fetch_row(); $res->close(); } else error($con->error); echo $cRes; function ref(&$arr){ // added & in call time parameter definition, must be a reference to the actual data $refs=array(); foreach($arr as $key => $value) { $refs[$key] = &$arr[$key]; } return $refs; } it looks like you just copy/pasted together something. at the level of trying to dynamically produce a prepared query, you really need to know what each statement does. you also need to test your code when there are no $_GET parameters to make sure your query statement is correctly being built.
-
that would mean that your WHERE clause if false. have you looked in your database table to see if there's a row with those values in it?
-
you can simplify the logic by just putting the comparison terms into an array and imploding the array with the AND keyword. this will produce the correct result even if there's only 1 term.
-
simplexml_load_file not working with date as file name
mac_gyver replied to syngod's topic in PHP Coding Help
the problem isn't that smiplexml needs a relative path. an absolute file system path would work, but the absolute path you supplied is not correct. the leading / refers to the root of the current disk. that's not where your path/file is at. it just turns out that include() went ahead and found the file relative to the calling script's own directory and the current working directory when it did not find it at that absolute path. -
in your first query, $PCN is apparently a numerical data type (not a string.) in your second query $user_name is obviously a string. string data must be enclosed by single-quotes inside the query statement so that they are treated as a literal string, rather than a mysql identifier or keyword. your query is failing due to an error. whatever is in $user_name is being treated as a column name. if you had some error checking logic for the query, you would getting an error such as "unknown column 'something' in where clause", the something being the actual user_name you submitted. put single-quotes around string data inside the query statement and you always need to test for errors before trying to use the data you expect from a statement to prevent follow-on errors like this one. @tanzeelniazi a query that matches or affects zero rows does not produce php errors.
-
that's pretty messy code. i had to clean it up to even tell what is was doing. the problem is you are concatenating $line to itself and echoing it at the end of each pass through the loop, so it keeps adding each new row of data to what has already been built and echoed. the first assignment to $line needs to remove the concatenation dot so that you are not reusing the previous contents in $line.
-
cannot really help you with what your php code is doing without seeing the relevant code from the point where you are executing the query through to the end of your loop processing the rows and possibly your code displaying the result if you are not doing that inside of the loop.
-
simplexml_load_file not working with date as file name
mac_gyver replied to syngod's topic in PHP Coding Help
the reason for this is the path you are specifying. the leading / is forming an absolute file system path, which is not where your file is actually at. however, if the include() statement doesn't find the file where you specify, it will "finally check in the calling script's own directory and the current working directory before failing.", apparently even for absolute paths, which the documentation hints it won't do. so, the include() statement is finding the file, but your other statements won't. since it appears that your form and your second piece of code are both in the parent folder that contains the inc/ folder, just remove the leading / from the file path, both in the $file variable and in the include statement, to form the correct path to where the file is at. also, your preg_replace() is trying to convert multiple spaces to a single space, but for at least the posted code, there are no spaces at all since the date is being directly built. if the date was from external data and it could contain spaces..., you would want to remove all of them, not convert multiple ones to a single one. -
should (untested) work - SELECT p.reference AS sku, IFNULL(p.price - sp.reduction,p.price) AS price, sa.quantity, mpo.asin1 AS 'product-id', 'ASIN' AS 'product-id-type', p.condition AS 'condition-type' FROM product p LEFT JOIN specific_price sp USING (id_product) JOIN stock_available sa USING (id_product) JOIN marketplace_product_option mpo USING (id_product)
-
what have you tried? you also need to use alias names to shorten the entire query statement. the select term should (untested) be (assuming alias names of p and sp) - IFNULL(p.price - sp.reduction,p.price) AS price
-
simplexml_load_file not working with date as file name
mac_gyver replied to syngod's topic in PHP Coding Help
what exactly does $_GET['Vdate'] contain when the file is created? does it have any leading/trailing spaces or new-line characters? -
you would need to explicitly use a LEFT JOIN between the other tables and the specific_price table, so that there will be a row in the result set even when there isn't one in the specific_price table. then use IFNULL(expr1,expr2) in the select term to get either the product.price - specific_price.reduction or just the product.price (expressions using a NULL value return a NULL.)
-
the things in the code that don't work were actually depreciated/moved-away-from/superseded back in 2002, so the resource you used in 2006 was already four years out of date. the settings/functions that the code relies upon that no longer work, started throwing errors in php5.3 and have been completely removed in php5.4. if you are attempting to update your code, make sure that you have php's error_reporting set to E_ALL and display_errors set to ON so that php will help you as much as it can.
-
the query you are producing is equivalent to - $SQL = "UPDATE {$URL}messages SET `status`='2' WHERE `index`='{$_POST['deleteindex']}'"; assuming the $URL value is the same as in your first working example, so that something about what is in $URL isn't breaking the sql syntax, there's nothing wrong with that query and if it isn't updating anything, it's most likely that the $_POST['deleteindex'] value either doesn't match any index value or that it contains some leading character(s) that don't evaluate to a number that matches any index value. after you add the error checking logic that DavidAM has suggested, if it doesn't expose an sql error, what does using var_dump($_POST['deleteindex']); show?