Dispalying the result of different tables using tabs - php

I want some suggestions regarding this topic. I have different types of tables. What I want is whenever mysql returns results from multiple tables it gets displayed according to table's name. Also I am using pagination so that if one table returns more than 10 results the results get displayed on multiple pages. How can I achieve this?

Related

Is there a way to add multiple values with same ID in two different tables?

Using PHP and mySQL, I need to add multiple values in 2 mysql tables : the first table would have the more important informations and the second one would have the less important informations about each items.
To be more clear, ONE element would have his informations split in two tables.
(I need this for some reasons but two of them are : having the first table the less weight possible, and the second table would store datas that will be erase after a short time (meanwhile the first table keeps all the datas it stored).)
In the best scenario, I'd like to add a row in each table about one item/element with the same id in each table. Something like this :
Table 1 id|data_1_a|data_1_b|...
Table 2 id|data_2_a|data_2_b|...
So if I add an element which get the ID "12345" in the table 1, it adds the datas in the table 2 with the same ID "12345".
To achieve this, I think of two solutions :
Create the ID myself for each element (instead of having an auto_increment on table 1). The con is that it would probably be better to check if the ID doesn't already exist in the tables everytime I generate an ID...
Add the element on table 1, get its ID with $db->lastInsertId(); and use it to add the element's datas on table 2. The con is that I have to add one element by one element to get all the IDs, while most of the time I want to add a lot of elements (like one, two or three hundreds !) at once
Maybe there's a better way to achieve this ?
lastInsertId() reports the first value generated by the last INSERT statement executed. It's reliable to assume that when you insert many rows, they are given consecutive id values following that first value. For example, the MySQL JDBC driver relies on this assumption, so it can report the set of id values generated.
This assumption breaks only if you deliberately set innodb_autoinc_lock_mode=2 (interleaved). See https://dev.mysql.com/doc/refman/8.0/en/innodb-auto-increment-handling.html for details about that.
But if it were my task, I would still choose to use a single table. When you find you don't need some of the columns anymore, use UPDATE to set them to NULL. This will eliminate the problems you're facing with assuring the same id is used across two tables.

Searching Multiple Tables in database

How to search multiple tables for a keyword regardless of which table or column it would be in?
I am looking for information relating to for example a name or phrase which maybe in one or multiple tables in any column.

How to fetch and display "unpivot" SQL in php?

I built a table which had to contain 42 columns which would be a large one, I decided to use rows as columns and used a column to add values of the respective fields. I've used dtsid as common entity.
Assuming that there are different values for every dtsid.
If in a page, I set $dtsid = $_GET['dtsid'] and run this url "exam.ple/result.php?dtsid=%Any_dtsid%"
How do I fetch the data and display values in different parts of html using php?

mySQL use row in table to find multiple rows in second table quickly [duplicate]

This question already has answers here:
SQL query of multiple values in one cell
(2 answers)
Closed 7 years ago.
What would be the best way of obtaining data from a second table using a row from the first.
Imagine a website where a table in a database defines the individual pages. The pages are subsequently made out of multiple components. Components exist in another Table. For the page to select which components it needs, it has a column containing the ID numbers of the components its after eg.( 14,15,17,19
This would then be used in a mySQL query using IN(14,15,17,19) etc..
Is there a better approach than this?
If the relationship is 1:N (each component can belong to only one page, but a page has multiple components), I would suggest to store the page_id in the components table. Then you can do a simple join between these two tables and you'll get the expected result.
If the relationship is N:N, I suggest creating an intermediate table "PagesComponents" that has the component_id and page_id. Then if yopu join the table Pages with PagesComponents with Components, you get the expected result.
If is not possible to modify the database, then I guess the IN(...) is probably the best option.

Laravel: Split model across two tables

I have a model titles
My titles DB table is getting rather large 100,000+ rows of data.
What is the best way to create a new titles2 table and join it with the titles table so that they can both be the same titles model?
Also if I finish adding rows to titles at id 100,000 should i start incrementing titles2 at id 100,001 to that the ids will always be unique?
You can add another column ex. source to differentiate these two table records. This way you can make sure that there's no way we will run into the problem of mixing these two datasets.
However for conveniency, we still want to make sure the id itself is unique across different dataset, which requires you not to use auto-increment for id field, because you'll gonna be the one to handle the id generation.
Some of the issues that I run into includes using the following line to update or insert the record,
$db->table('users')->insert($record);
instead of
User::create($record); // assume you are using auto-increment ids

Categories