Skip to content

Tag: php

SQL get results 21-30?

This seems like a really simple question but I can’t seem to find information on it. If I have 100 results, and I only want to get the results results between 21 and 30 (from the order my SQL query is grabbing them), how would I accomplish this? Answer You can use this: E.g.,

How to attach PDF to email using PHP mail function

I am sending an email using PHP mail function, but I would like to add a specified PDF file as a file attachment to the email. How would I do that? Here is my current code: Answer You should consider using a PHP mail library such as PHPMailer which would make the procedure to send mail much simpler and better…

Selecting one row from MySQL using mysql_* API

I have the following query: and the output I am getting is: Resource id #2 Ultimately, I want to be able to echo out a single field like so: Without having to use a while loop, as since I am only trying to get one field I do not see the point. I have tried using mysql_result with no luck

MySQL commit and transaction

I have a question regarding MySQL commits and transactions. I have a couple of PHP statements that execute MySQL queries. Do I just say the following? What exactly would this do? How does it help? For updates, deletes and insertions I also found this to block other queries from reading: Would this block other…

MySQL INSERT IGNORE INTO keeps adding duplicate entries

Here’s the particular area im having an issue with when testing this it keeps adding the same entry to the table even though I have set IGNORE INTO. Answer It looks like you don’t have a UNIQUE INDEX on the IP column. In order for INSERT IGNORE to work as required, that’s neccessary. Try thi…

Check if all values in array are the same

I need to check if all values in an array equal the same thing. For example: If every value in the array equals ‘true’ then I want to echo ‘all true’. If any value in the array equals ‘false’ then I want to echo ‘some false’ Any idea on how I can do this? Answer…