how to show table names as combobox use php syntax?
silent lover 0 Light Poster
Recommended Answers
Jump to PostThis seems to be the way to me:
include "connect.php"; $query = "SHOW TABLES FROM `my_database`"; $res = mysql_query($query); $output = "<select name = 'venue'>"; while ($row = mysql_fetch_row($res)) { $sel = ($selected_venue_id == $row[0]) ? ' selected="selected"': ''; $output .= "\n\t<option value = '{$row[0]}'$sel>{$row[0]}</option>"; } $output …
Jump to Posthow about i change it to ... is this will work?
yes. But why haven't you tried it to see for yourself?
Jump to PostThis may be a better approach as you can apply an id to each table and use them in further code.
Jump to PostThis code is correct:
…<?php include "connect.php"; $query = "SHOW TABLES FROM `my_database`"; if($res = mysql_query($query)){}else{die(mysql_error());} $selectedTable = 'table'; echo "<select name='venue'>"; while ($row = mysql_fetch_row($res)){ echo "<option value='{$row[0]}' "; if ($selectedTable == $row[0]){ echo " selected='selected'";//<-- added space } echo ">{$row[0]}</option>"; } echo "</select>"; ?>
All 16 Replies

LastMitch
veedeoo 474 Junior Poster Featured Poster
silent lover 0 Light Poster
code739 17 Posting Whiz in Training
AARTI SHRIVAS 2 Posting Pro in Training

diafol
silent lover 0 Light Poster
AARTI SHRIVAS 2 Posting Pro in Training

diafol
silent lover 0 Light Poster

diafol
Biiim 182 Junior Poster
Biiim 182 Junior Poster
silent lover 0 Light Poster
Biiim 182 Junior Poster
silent lover 0 Light Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.