Jump to content

mds1256

Members
  • Posts

    259
  • Joined

  • Last visited

Everything posted by mds1256

  1. Thank you!!! That worked exactly, looks simple but have been trying to do this for around 4 hours Much appreciated.
  2. Hi I am faced with the following problem. My table is as follows: part_id supplier_id customer_id p1 s1 c1 p2 s1 c1 p3 s2 c1 p4 s2 c2 p5 s1 c2 And I need to return all customer ids where the customer has bought a part from the same supplier more than once. Any help would be appreciated
  3. Hi I have a scenario which I want to be able to post JSON data to a php page which can then parse this. I am learning how to make a mobile app (iOS) and wanting to POST a JSON response to a web service using PHP on the server to then parse this JSON response and allow PHP to do what ever it needs. Any ideas how I can make a PHP page that will receive a POSTed JSON object and work with it? Thanks
  4. I see I didnt realise the time function was unix time stamp. Thanks for the quick answer.
  5. Hi Sorry to drag this topic up again, but a question regarding the below solution (which is quite a neat little trick!), however how does this work on the rare occasion when the clocks go forward / backwards? How does the below solution handle this, surely it will fail..... how can we get around this as I would really like to use this solution. Thanks
  6. Works Perfect!!! Thank you very much
  7. Hi This has been driving me crazy, I have the following tables: Parts: Part_ID p1 p2 p3 p4 p5 Store: Store_ID s1 s2 s3 s4 Stocks: Part_ID | Store_ID p1 s1 p2 s1 p3 s1 p4 s1 p5 s1 p1 s2 p2 s2 Any what I am trying to do is to get a list of ALL store_IDs which do not stock all products. So I need to check inside the Stocks table to see if for each Store_ID that each instance of Product_ID exists for that Store. Any ideas?
  8. Hi Just after some advice on using ImageMagick for reducing images that are uploaded. First of all I will have a form so users can upload Photos ideally these will be in TIFF, JPG / JPEG or BMP. The Form will then process these images to reduce the size / compress and make a thumbnail as well as a normal version. Hosting will be on a Debian VPS. I would like to know if there are any things to look out for, I have thought of a few: Make sure this is an image that is uploaded (what is the best way to check, I have read get the image size?) upload to TMP folder then use imagemagick to process and save to a final destination which is outside of the web root? change permissions on that folder as well as TMP to remove eXecute use a .htaccess file to prevent any scripts from running from there AND the TMP folder Any thing else I should do? Also a question around ImageMagick, i hear this is better than GD at resource management (if server starts running out of RAM it pages to disk so it won't fail), is this true? Thanks
  9. Hi Thanks for the above, yes that seems to work. Also the idea of not wanting to have the whole site as https is also to help Google index this as google doesnt index https.
  10. Unnecessary overhead I guess as no personal / confidential data will be transferred when a user is not logged in. Just don't want the overhead of SSL when users are just browsing around the site.
  11. Hi I am developing a website and when you first browse to the website you can either use http or https but when you login I want it to always use HTTPS (even if someone tries to type in http rather than https to manually browse to a page once logged in). My idea is to post the form using https://mywebsite.com/form.php (as an example). So that means the login details (username and password) will be posted securely. Then from there always force SSL / HTTPS on page requests.
  12. Hi Thanks! So doesnt seem to take too long then. Yeah I see what you mean by normalising the data as I have the data in another table any way, I guess just add the id of the row in the other table. Thanks very much
  13. Hi I am working on a little hobby and it requires a script to go through all results in a table (potentially 10's of thousands) and get the id of all rows that are relevant to that query. So for example get all ID's where the category is set to 'Computers'. Once it has retrieved all the ID's for the suitable category it then needs to insert some data into a different table, e.g. the ID that it has previously retrieved along with some details (the same details for each ID, so many rows with the same details but the ID being different). Now, which is the best way to achieve this. Should I do this in a PHP script, shell script or a database stored procedure? Which way would be faster as I believe this could take a long time or am I wrong. When a user submits a form that will insert these details into one table and then kick off a background task (as waiting for the above to run will take a while or am I wrong).
  14. Hi Having a bit trouble understanding the best way to check if the SQL statement has worked. At the moment check the statement object if error then display bespoke error, if that passes then I check the statement object execute method and then if that fails show the same bespoke error for that form. so I have two if statements, which gets messy if I am calling multiple sql statements within the same php function as I end up with lots of nested if statements. Is there a better way of doing this?
  15. Will that not mean there will be lots of if statements?
  16. Hi I have a Title select box on my website (Mr, Mrs, Miss, etc). Now, if they enter something that does not meet the form validation, it reloads the page and populates the fields that has already been filled out along with the appropriate error message. Now my question is what is the best way to add the selected value that was chosen on the initial filled out form so they dont have to re-select.
  17. Hi What would you say the best practice was to handle a mysql / PHP error. These errors include a SQL query problem, mysql connection problem, any sort of php problem. I have read that all errors should be output to a log so I can keep an eye on any errors etc, but what about displaying errors to users? So say that my website had a problem with a mysql connection, should I just re-direct the user to a static type error page to say there was a problem (as my site relies on a database connection to supply content etc). Also with a SQL query, I am guessing that I should just display a custom error for the action they are trying to perform, e.g. logging in; I should just echo there was a problem logging in. And then pipe the proper php error to a log file? Any tips would be great?
  18. Hi, basically I am not to worried about it being real time as such, more about on the next page click the query will re-run and do a count on new items which haven't been acknowledged by the current user.
  19. Ok thank you I am trying to figure out the best way to return an array from a mysqli prepared statement.
  20. Thanks for the above that helps make it easier I have had a problem returning the result so this is the only way I can think of is to iterate over the result and add it to an array and then return that array unless you can think of a different way. The fetch_results() only works with the mysqld driver which I cannot use unfortunately. Thanks
  21. Hi I have read that you should keep the views away from the business logic so my question is which one of the below is better, the below are just examples but hopefully you can grasp what I am getting at. keeping the php logic out of the html: <?php function displayRows() { $Con = mysqli_connect('localhost', 'usr', 'pass', 'db'); $query = mysqli_query($Con, "select id, name from table"); while($row = mysqli_fetch_object($query)) { echo "<a href=\"#\">".$row->name."</a>"; } } ?> <html> <body> <?php displayRows(); ?> </body> </html> OR keeping the html out of the php function but putting some php into the body of the html <?php function displayRows() { $Con = mysqli_connect('localhost', 'usr', 'pass', 'db'); $query = mysqli_query($Con, "select id, name from table"); return $query; } ?> <html> <body> <?php $myRes = displayRows(); while($row = mysqli_fetch_object($myRes)) { echo "<a href=\"#\">".$row->name."</a>"; } ?> </body> </html>
  22. Ok, I think I may have sorted it. See the below code, is there a more efficient way of doing this? does filling up a new array up and returning it slow things down as well as use memory unnecessarily? <?php function test() { $res = array(); $Con = new mysqli('localhost', 'usr', 'pass', 'db'); $limit = 10000; $sql = "select id, name, email from tbl_test limit ?"; $stmt = $Con->prepare($sql); $stmt->bind_param('i', $limit); $stmt->execute(); $stmt->bind_result($id, $name, $email); $i = 0; while($stmt->fetch()) { $res[$i]["name"] = $name; $res[$i]["email"] = $email; $i++; } $stmt->close(); return $res; } $my = test(); foreach($my as $item) { echo $item['name'].$item['email']."<br />"; } ?>
  23. The function doesnt work, but here is my code: function test() { $res = array(); $Con = new mysqli('localhost', 'usr', 'pass', 'db'); $category = $_POST['category']; $sql = "select id, name from items where category = ?"; $stmt = $Con->prepare($sql); $stmt->bind_param('i', $category); $stmt->execute(); $stmt->bind_result($id, $name); $res = $stmt->fetch() return $res; } $my = test(); foreach($my as $test) { echo $my['id']; }
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.