PHP read specific row [closed] - php

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
I have a PHP script that displays data read from a MySQL database. I want to filter the output to only show rows where two columns contain specific values. How do I do this?

Add a WHERE clause, e.g., WHERE column1 = 'specific-value1' AND column2 = 'specific-value2'
Here's a link to MySQL's SELECT syntax:
http://dev.mysql.com/doc/refman/5.1/en/select.html
(and in German):
http://dev.mysql.com/doc/refman/5.1/de/select.html

no idea why you are posting in german on an english site and then translating it to english. But what you need to do is something like "select * from table where column1='val' and column2='val'". Though it sounds like you have a large set of data pulled off already and you want to filter that. I don't see why you shouldn't just query what you need from the database instead of pulling everything off and then filtering.

Related

MySQL unrepeatable rows search query [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I save some images in my database. Each images have a "tags" property.
I'm gonna show "search by tags" result to users, but there is a problem.For example, "IMAGE1" has "c#, programming, scripting" tags and I'm gonna show every images which have "programming" and "scripting" tags. So If I do that, "IMAGE1" will be duplicated.
So how can I prevent this duplicating ?!
Thanks !!
You can use DISTINCT operator of MySQL to retrieve non-duplicates
SELECT DISTINCT `imagename`
FROM `images`
WHERE (`tags` = 'programming') OR (`tags` = 'scripting')
The conditions for WHERE may be different depending on your PHP code.

using explode with php and mysql [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I am doing my project and I am using php and MySQL
My program is reading a data from textarea as a list of people, I use the explode function to separate the list and then I generate a for loop to insert them to MySQL database
till this part I don't have any problems
The problem is when I query the database with a where condition specifying a name from the list it does not recognize it
My question does the explode function change any thing to the names in the list or add any special characters
because I use the same functionality with specific name and it goes smoothly
Thanks in advance
It should not. PHP explode will not change your text and the WHERE query should operate correctly.
Are the characters all utf8 encoded? Check the database and see what you are querying for actually exists the same way you are sending it.
Like the others said, if you can provide us an example of the following it would be great:
Actual textarea input (not exploded).
DB Dump of what is inserted.
Your QUERY to select
Additionally, it could be a space issues, use trim before you insert the data or in your query instead of field = '$a' do a field LIKE '%$a%'
I don't think explode() will modify anything. try to use trim() in your foreach loop before inserting. Might be some characters that can not be seen.

PHP Algorithm and MySQL [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I have an equation that I need to process from a couple MySQL columns. I am just trying to figure out the best way of doing this once I run my SELECT statement to retrieve all the data.
Table - tbl_Spirits
Columns - ID, Volume, Proof
I know how to retrieve all the Data from MySQL, the problem is, is that there may be one record returned or 5. Probably never more then 5. Is there a clean fast method of the equation below in PHP.
This example is if there was 2 records returned.
((Volume1 * Proof1) + (Volume2 * Proof2)) / (Volume1 + Volume2)
Even if you did not show any attempt to solve your problem, I will give it a try. Basically you want to divide the sum of products between the two columns by the sum from one of them. So it should be something like
SELECT
SUM(`Volume`*`Proof`)/SUM(`Volume`)
FROM
`tbl_Spirits`
WHERE
1
and you will need to fill in your WHERE statement to fit your needs
Update: added this sample in sqlfiddle: http://sqlfiddle.com/#!2/0dc417/1/0
you will see that for the two records the value you will get is 4, exactly (2*4+3*4)/(2+3)

Get recently viewed posts by using PHP [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
I want to store and display recently viewed posts. I don't want to use cookies because not only want to show what the visitor him/her self viewed posts but viewed by others as well.
I know I can simply store post id in the table and display the data. But is this is best way to do this. As I understand this will store huge amount of junk data in the database as I only want to display 10 latest viewed posts on my website.
Can anyone tell me a better way to do this or is this the only way to do this?
Add a "dt_lastViewed" field to your "Posts" table. Update it when it's been viewed, and pull the top 10 for your module.
Optionally, create another field called "timesViewed" so that you can increment and track the most popular posts! May be considered YAGNI

php - data entry and order issue [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
Im having a little trouble with a php script ive made.
you can see all the relevant info at http://click-media.co.uk/Client/Lisa/Admin/admin.php (password: "hey")
I basically need the classes to be ordered by day/time when a new class is created, either by changing the column names in the database to a timestamp or something or by making a new column to and ordering it by this.. then using the php to switch the order values when the admin clicks "moveup"/"move down" next to the row.
any help would be much appreciated.
Thanks
You can implement this by doing the following:
Add a column in the database and call it class_order
Your SQL query should have ORDER BY class_order
Moving up UPDATE table set class_order = THE_ORDER_OF_THE_CLASS_ABOVE WHERE id = TARGET_CLASS and UPDATE table set class_order = TARGET_CLASS_ORDER WHERE id = THE_CLASS_ABOVE
Moving down is the opposite of moving up

Categories