4 Replies - 434 Views - Last Post: 24 July 2017 - 05:51 PM

#1 hokletrian  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 24-July 17

Displaying table from dropdown

Posted 24 July 2017 - 05:17 PM

Hey guys, so i currently have this code working which gets all of the desired table names from the database and puts them into the dropdown:

 <?php
$result = $con->query("SHOW TABLES WHERE `Tables_in_irrigation` NOT LIKE 'user%' and `Tables_in_irrigation` NOT LIKE 'company%' and `Tables_in_irrigation` NOT LIKE 'roles%' and `Tables_in_irrigation` NOT LIKE 'ftp%' and `Tables_in_irrigation` NOT LIKE 'RTU_LINK%'");

if($result->num_rows > 0) {
    echo '<select name="rtu" id="rtu">';
    while($row = $result->fetch_array(MYSQLI_NUM)) {
        echo '<option>' . $row[0] . '</option>';
    }
    echo '</select>'; 
}
 
?>


<input type="submit" value=" Submit " name="submit"/><br />
</form>
</div>



What i would like to know is how i can display the table selected after submit is clicked?

Is This A Good Question/Topic? 0
  • +

Replies To: Displaying table from dropdown

#2 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 13400
  • View blog
  • Posts: 53,478
  • Joined: 12-June 08

Re: Displaying table from dropdown

Posted 24 July 2017 - 05:24 PM

I would imagine you can splice together a sql string (typically called 'dynamic query') and combine that with your string of a table name from the drop down.
Was This Post Helpful? 0
  • +
  • -

#3 hokletrian  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 24-July 17

Re: Displaying table from dropdown

Posted 24 July 2017 - 05:33 PM

Can you give me an example please, i have literally looked everywhere for a solution ahah.. :bigsmile:

Thanks!
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 13400
  • View blog
  • Posts: 53,478
  • Joined: 12-June 08

Re: Displaying table from dropdown

Posted 24 July 2017 - 05:38 PM

In this line..
2	$result = $con->query("SHOW TABLES WHERE `Tables_in_irrigation` NOT LIKE 'user%' and `Tables_in_irrigation` NOT LIKE 'company%' and `Tables_in_irrigation` NOT LIKE 'roles%' and `Tables_in_irrigation` NOT LIKE 'ftp%' and `Tables_in_irrigation` NOT LIKE 'RTU_LINK%'");


... this all is a string, right?
"SHOW TABLES WHERE `Tables_in_irrigation` NOT LIKE 'user%' and `Tables_in_irrigation` NOT LIKE 'company%' and `Tables_in_irrigation` NOT LIKE 'roles%' and `Tables_in_irrigation` NOT LIKE 'ftp%' and `Tables_in_irrigation` NOT LIKE 'RTU_LINK%'"

You can combine strings in php with the '.' operator.

"foo"."bar" yields "foobar".

The same principle applies with your issue .

"SELECT * FROM ".$Table_Name_Variable
Was This Post Helpful? 0
  • +
  • -

#5 hokletrian  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 24-July 17

Re: Displaying table from dropdown

Posted 24 July 2017 - 05:51 PM

$result is a query used to get all the table names. Sorry I'm either plain dumb or don't understand what you are saying... ahah.. So After the form is submitted i want the table selected in the drop down to be displayed.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1