Page 1 of 1

list tablenames of mysql database by length of tablename

Posted: Tue Sep 01, 2009 2:50 pm
by jforce93
I am trying to create library catalog software, and I am trying to have it so when someone searches for a book by title, the shortest title comes up first, the second shortest second and so on. How would I do that? Here is my code:

Code: Select all

<html>
<body>
<h1> Here Are Your Results </h1>
<?php
 
$table = 'user';
//get names of tables
$result_handle = mysql_list_tables ($title)
   or die ("mysql_list_tables () failed with this error message: '" . mysql_error () . "'");
 
//number of tables
$number_tables = mysql_num_rows ($result_handle);
 
echo "Your search returned $number_tables table(s):<ol> number of books";
 
for ($index=0; $index < $number_tables; ++$index) {
$User_Input = str_ireplace(" ","",$title);
$Title_Of_Book = str_ireplace(" ","",$result_handle); 
$pos = strpos($Title_Of_Book,$User_Input);
if ($pos === true)
{
 
 
   echo '<li>', mysql_result ($result_handle, $index, 0), '</li>';
}
}
?>

Re: list tablenames of mysql database by length of tablename

Posted: Tue Sep 01, 2009 3:04 pm
by requinix
Stick the table names into an array, then

Code: Select all

usort($array_of_table_names, create_function('$a,$b', 'return strlen($a) - strlen($b);'));
print_r($array_of_table_names);