How to dynamically generate table names in SQL queries?
P粉588152636
2023-09-03 19:57:51
<p>I have a SQL query that uses a MySQL database to get information from it. The table name is the first constant with a different IMEI number at the end. </p>
<p>gs_object_data_12345678</p>
<p>12345678 is identified in my script as <code>$_GET</code> but when I try to change the table name it does not display the data from that table</p>
<pre class="brush:php;toolbar:false;">$imei = $_GET['imei'];
$result = $db->query("SELECT * FROM gs_object_data_'$imei' LIMIT 200 ");</pre>
<p>If I use the following string it works</p>
<pre class="brush:php;toolbar:false;">$result = $db->query("SELECT * FROM gs_object_data_12345678 LIMIT 200 ");</pre>
<p>I need to change the table name with <code>$_GET</code>information</p>
The <p>URL <code>alarm_action.php?id=58543®=****&imei=862202228007105</code> contains the IMEI, so the information should pass through </p>
Use like this
or
In a protected manner