Page 1 of 1
how do i store as variable when i click on echo'd results
Posted: Tue Jun 06, 2006 4:20 pm
by jpaloyo
here is my little code. When i echo this it returns a list of database. how can i click on the list of result and save it to a variable?
once the list of databases are outputed, i would like to be able to click on a database name and show the tables in that database.
help somone please. examples would be nice. Thank you.
Code: Select all
$database_query = mysql_query("show databases");
while ($row = mysql_fetch_row($database_query))
{
echo $row[0] . "<br>";
echo $row[1] . "<br>";
}
Re: how do i store as variable when i click on echo'd result
Posted: Tue Jun 06, 2006 7:52 pm
by a94060
jpaloyo wrote:here is my little code. When i echo this it returns a list of database. how can i click on the list of result and save it to a variable?
once the list of databases are outputed, i would like to be able to click on a database name and show the tables in that database.
help somone please. examples would be nice. Thank you.
Code: Select all
$database_query = mysql_query("show databases");
while ($row = mysql_fetch_row($database_query))
{
echo $row[0] . "<br>";
echo $row[1] . "<br>";
}
assuming what i am seeing,you only want/have 2 databases right? so to do that,you would do soemthing like:
Code: Select all
$database_query = mysql_query("show databases");
while ($row = mysql_fetch_row($database_query))
{
echo $row[0] . "<br>";
echo $row[1] . "<br>";
echo 'View <a href=?db=' .$row[0]. '>This Database</a>';//something like this i would guess
}
after this,you would need to set up and action in your main to get the result name and then do a SELECT * FROM dbname. Since i dont usually do this using the naumbers,im not really sure how to go past that.
Posted: Tue Jun 06, 2006 9:53 pm
by ambivalent
Disclaimer::Don't use this this on a live site as it is not particularly secure.
Code: Select all
if(!isset($_GET['t']))
{
$database_query = mysql_query("show databases");
while ($row = mysql_fetch_row($database_query))
{
echo "<a href=\"".$_SERVER['PHP_SELF']."?t=".urlencode($row[0])."\">".$row[0]."</a><br />";
}
}
else
{
$tableVal = mysql_real_escape_string(urldecode($_GET['t']));
$showTables = mysql_query("SHOW TABLES FROM $tableVal ");
while ($row = mysql_fetch_array($showTables))
{
echo $row[0]."<br />";
}
}
Essentially, you just want to feed a given value from the initial output to a new query and spit out the results. That first echo is somewhat messy though...

Posted: Wed Jun 07, 2006 6:38 pm
by jpaloyo
thank you so much everyone.