Combining database query request in a single statement [closed] - php

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 7 years ago.
Improve this question
I have been told that my web server only allows 75,000 database queries request per hour. I'm wondering if combining query request would lessen the amount of queries or if it doesn't matter. It kind of feel like common sense, but I just want to make sure. Thanks.
$text1 = "text1";
$text2 = "text2";
$text3 = "text3";
SELECT text FROM table WHERE text = '$text1';
SELECT text FROM table WHERE text = '$text2';
SELECT text FROM table WHERE text = '$text3';
3 queries ^---
SELECT text FROM table WHERE
text = '$text1' OR
text = '$text2' OR
text = '$text3';
1 query ^---
Is the above correct or wrong? Thanks.

It look OK. You also can use "IN", the you can write i little bit smaler.
SELECT text FROM table WHERE
text IN ('$text1', '$text2', '$text3');

Related

Using PHP?= to navigate between pages [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 2 years ago.
Improve this question
I am able to navigation between a php page using ID but not using project name. Can you only use an number and not characters?
Works
$sql = "SELECT id, assigned, project, start, end, status
FROM projects
WHERE id=$id";
'.$row['project'].'
page url: https://example.com/project.php?id=1
Doesn't work
$sql = "SELECT id, assigned, project, start, end, status
FROM projects
WHERE project=$project";
'.$row['project'].'
page url: https://example.com/project.php?project=Test
Thanks for the help!
MySQL uses single or double quotes for strings. Your second query puts string to a query, resulting in invalid query.
This is not a valid SQL query:
SELECT `name` FROM `cats` WHERE `breed` = ordinary cat
But this is:
SELECT `name` FROM `cats` WHERE `breed` = 'ordinary cat'
Of note, be careful with using any input (including query string) in your query like you did. You should use prepared statement instead to safely escape that string for your query.

How to make this MySQL query execute faster? [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
SELECT * FROM (`collection_series`)
JOIN `datadatexnumericy` ON
`collection_series`.`series_id` = `datadatexnumericy`.`series_id`
JOIN `saved_users_chart` ON `collection_series`.`collection_id` =
`saved_users_chart`.`chart_id`
WHERE `saved_users_chart`.`chart_id` = '265'
AND `saved_users_chart`.`id` = '6' AND `datadatexnumericy`.`x` >=
'1973-09-30' AND `datadatexnumericy`.`x` <= '2014-06-30' AND
`datadatexnumericy`.`series_id` != '43538'
AND `datadatexnumericy`.`series_id` != '43541'
GROUP BY YEAR(datadatexnumericy.x)
This is my SQL query and result of this query I am getting from AJAX response this query is working fine but I am getting response slow a bit I think the problem is in my SQL query.
I want all matching records from collection_series and datadatexnumericy table and only matching row from saved_users_chart is there any possible way to optimize this query in more efficient way so that I can get ajax response faster.
In my opinion your query is already optimized. You should test the result of the query in an SQL server to see response time of SQL server and then compare with the time you actualy receive the response back from server.
If is not necesary to extract all the columns from each table, then manualy enter the column names instead of *. By doing this the response received from server will be certainly smaller, therefore it will be faster.

How to print data from SQL database to HTML table based on query [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
so I have records in my database that I would like to print to a HTML table IF they belong to the user.
$sql="SELECT * FROM ".$tbl_name." WHERE Username='".$username."'";
The table would read :
Date, Room, Period , Cancel
With cancel being a red cross designed to delete that specific entry from the database :
Booking ID, Date, Period,Type,RoomID, Username are the fields in the database.
How would I go about doing this? I was thinking echoing a table using a for loop but I wouldn't know where to begin?
Try:
$query_rsSearch = "SELECT * FROM ".$tbl_name." WHERE Username='".$username."'";
$rsSearch = mysql_query($query_rsSearch) or die(mysql_error());
$row_rsSearch = mysql_fetch_assoc($rsSearch);
$totalRows_rsSearch = mysql_num_rows($rsSearch);
do {
echo $row_rsSearch['Date']." | ".$row_rsSearch['Room']." | ".$row_rsSearch['Period'];
} while($row_rsSearch = mysql_fetch_assoc($rsSearch));

Insert each result of an array into separate SQL rows? [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 8 years ago.
Improve this question
I have a query that is returning a different amount of user_id's each time it's run (based on the number of subscribers).
What I need to do is insert each of these user_id results into separate rows within a table along with a simple message of "new alert" in a separate column.
How could I possibly go about doing this? Would a for each loop work in this situation?
Try this:
INSERT INTO alert_table SELECT user_id, 'new alert' FROM ... WHERE ...
Use your own query, just prepend it with the INSERT INTO alert_table clause.

How to select all fields where a string is common in all the tables in a mysql database? [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 8 years ago.
Improve this question
I have a mysql database where there is 3 tables 'groupstage', 'quarterfinal,' semifinal. All of these table have a column named 'Date'. Now I want to write a query from where I can get all the fields from those tables with a specific date? what should i write it in php?
To get what you want, you can write a query which join the 3 tables like :
SELECT *
FROM groupstage, quarterfinal, semifinal
WHERE groupstage.date = quarterfinal.date AND quarterfinal.date = semifinal.date
AND date = "YOUR DATE"
In php you should just create a var $query = "My query above"

Categories