assesment for php application code [closed] - php

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Thanks for reading.... still on my way to really getting the hang of php an MySQL queries.
I have a system that queries table entries... I have managed the joining of the 2 tables in my sql query.
Sample:
$sql = mysql_query("select * from table1,table2 where `field_table1` = `field_table2` and `x`= 'x' and y = 'y'")
My question on the validation for this query... The joined field in table1 has to be the same as field in table2. Is an if statement the solution and how would I approach this?
Basically I do not want the query to show the result of the search if field_table1 is not = to field_table2.
Thank you for your assistance.

SELECT *
FROM table1
INNER JOIN table2 ON...
WHERE table1.field != table2.field
That should pretty much take care of it.

Related

php code to delete value table 2 from value of table 1 [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I am php beginner.
I would like to read email contain in table 1 and with the value selected deleted the corresponding email of the table 2 ?
May you provide me some info to manage it ?
select email_table1 from table1.
delete from table2 where email = email_table1.
Thanks
Greg
There's little information to form an answer but you could use a sub select.
Something like this presuming you're using MySQL or similar.
DELETE FROM `table1` WHERE id = (
SELECT `referenceID` FROM `table2` WHERE `email` = 'the#email.com' LIMIT 1
) LIMIT 1;

Display/create a blank row in between data set and breack the table data using php/mysql [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I am using one table and two queries to display the below output.
Here I have used 1st query to display the morning/middle/evening and other to get the user details.
I want to user a empty/blanks row after the last morning/middle which need to have this output
Expected output:
Can anyone help me on this.
Not knowing your SQL statemanets, i would only advise to use
UNION ALL
(See Docu here)
So your Statement would look somehow like that:
Select Col1, Col2
from tbl1
UNION ALL
Select NULL as Col1, NULL as Col2
UNION ALL
Select Col1, Col2
from tbl2

Select and sort data from one table on certain columns [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I'm looking to see if it is possible to select data from table A with a sort so the order of the data changes.
I then want to make a loop so it will go through each row and add it into table B.
Is this possible.
Use a variable #row_number to store the incremented num for your expected sorting.
SET #row_number = 0;
SELECT (#row_number:=#row_number + 1) AS num, Column1
FROM TableA
ORDER BY Column1
This result can be store in temporary table and based on that you can do loop/insert into the TableB

Query Execution [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
How to execute this query in laravel. ?
select d1.update_id from ( select update_id, count(update_id)
as ct from updates_tags where tag_id in (67,33,86,55) group by
update_id) as d1 where d1.ct=4
you can use Raw Queries in Laravel
$results = DB::select(SELECT * FROM table WHERE id IN (1,2,3,4) AND );
http://fideloper.com/laravel-raw-queries
You can chain where conditions with eloquent, each chained one is evaluated like an and.
$update = Tag::whereIn('t_id',$tags)->whereIn('u_id',$tags)->where(/*more and conditions you could need*/)->lists('u_id')
Edit: If you need the ones coincident with u_id consider this:
$update = DB::table('tags')
->select('t_id', 'u_id', DB::raw('count(*) as total'))
->whereIn('t_id',$tags)
->where('total','=',count($tags))
->groupBy('u_id')
->lists('u_id');

Show a random mysql row, but not the same twice [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I'm trying to create a database that holds all my information with questions, users, answers etc.
I've been thinking all day how to solve this problem of mine. Okey, so the problem is like this:
Let's say I have a table in my DB, with questions (300++) and the user that logs on will get a random question shown. But never the same question again, so I'll need to store this information in a separate table with the user-ID and the question-ID. And I'll need to create another table that stores the answers to the questions.
So how would this PHP/MYSQL-code look like? Because I'll need to find a random question that hasnt been shown to the same user again.
If something is unclear, please let me know. And thanks in advance
You can use RAND() function and NOT IN
Example:
SELECT * FROM `questions` WHERE id NOT IN (5, 3) ORDER BY RAND() LIMIT 1;
You have to fetch question id using sub query
Example
SELECT * FROM `questions` WHERE id NOT IN (SELECT question_id FROM shown_questions WHERE user_id=1) ORDER BY RAND() LIMIT 1;
You can use an outer join to select items that have not been used already. It might be a bit faster than NOT IN if you set up the indexes:
SELECT questions.* FROM questions
LEFT JOIN shown_questions
ON (questions.id=show_questions.question AND user_id=42)
WHERE shown_questions.question IS NULL
ORDER BY RAND() LIMIT 1;

Categories