Dustin013 Posted June 18, 2008 Share Posted June 18, 2008 What I am doing is loading up a list of my SQL tables then creating a link for the user to browse all listings in that category. What I would like to do is use mysql_list_tables to pull all the tables names from the selected database and display them like below. However, I would like to change the echo statement to display a little differently... echo "<a href='$sitepath/listall.php?cat={$row[0]}'>{$row[0]}</a><br />"; results in me getting a list of the tables but I would like to change the second {$row[0]} to display another name for the table.... for instance the table structure could look like the following... Database1 Table1 Table2 Table3 With the code below the HTML output would look something like... Listing all... <a href="http://localhost/test/listall.php?cat=Table1>Table1</a><br /> <a href="http://localhost/test/listall.php?cat=Table1>Table2</a><br /> <a href="http://localhost/test/listall.php?cat=Table1>Table3</a><br /> What I would like to do is change the name of the table so its displayed like such... Listing all... <a href="http://localhost/test/listall.php?cat=Table1>CustomTableName1</a><br /> <a href="http://localhost/test/listall.php?cat=Table1>CustomTableName2</a><br /> <a href="http://localhost/test/listall.php?cat=Table1>CustomTableName3</a><br /> Basically, I would like to define a name for each of the table names so it looks better. Is this possible using mysql_list_tables? Maybe I could use an if statement? if ($row[0] == "Table1"){ $tablename = Custom Table Name } else if ($row[0] == "Table2") { $tablename = Another Custom Table Name } I know my syntax is messed up but any help would be appreciated... Here is the code I am working with now... <?php include("header.php"); ?> <div class="box2"> <!-- START Listings --> <h1><span class="green"><span class="white">Listing all...</span></h1> <strong> <?php include 'include/config.php'; include 'include/connect.php'; mysql_select_db($dbname); $result = mysql_list_tables($dbname); while ($row = mysql_fetch_row($result)) { echo "<a href='$sitepath/listall.php?cat={$row[0]}'>{$row[0]}</a><br />"; } ?> <?php include("footer.php"); ?> Link to comment https://forums.phpfreaks.com/topic/110663-mysql_list_tables-question/ Share on other sites More sharing options...
DarkWater Posted June 18, 2008 Share Posted June 18, 2008 No, not with mysql_list_tables. You could make sort of a "translation" array before the while loop: $newnames = array( "Table1" => "ThisIsANewTable", "Table2" => "Again..." ); Then inside the while loop, you could do: $tablename = $newnames[$row[0]]; Then use $tablename. Link to comment https://forums.phpfreaks.com/topic/110663-mysql_list_tables-question/#findComment-567709 Share on other sites More sharing options...
Dustin013 Posted June 18, 2008 Author Share Posted June 18, 2008 awesome thanks! Link to comment https://forums.phpfreaks.com/topic/110663-mysql_list_tables-question/#findComment-567725 Share on other sites More sharing options...
DarkWater Posted June 18, 2008 Share Posted June 18, 2008 No problem. Link to comment https://forums.phpfreaks.com/topic/110663-mysql_list_tables-question/#findComment-567727 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.