SitePoint Sponsor

User Tag List

Results 1 to 18 of 18

Thread: Help!!!

  1. #1
    SitePoint Wizard
    Join Date
    Mar 2004
    Posts
    1,647
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help!!!

    hi1
    how to find a name into mysql database but in the database name not in database table!!!
    example i search into sql54432 for name mark and i get the result and the name of the table where is!!!
    please any help appreciated!!!
    thanx in advance!!!

  2. #2
    SitePoint Evangelist
    Join Date
    May 2004
    Location
    Germany
    Posts
    550
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you coudl do something like
    PHP Code:
    mysql_connect('localhost''user''test');
    mysql_select_db('sql54432');
    $tablesearch 'mark';
    $res mysql_query('SHOW tables');
    while(
    $row mysql_fetch_array($res))
    {
        if(
    preg_match('='.$tablesearch.'='$row[0]) == 1)
        {
            
    $foundtable[] = $row[0];
        }
    }
    if(
    count($foundtable) = 0)
    {
        echo 
    'No table found';    
    }elseif(
    count($foundtable) > 1)
    {
        echo 
    'tables:<br />';
            foreach(
    $foundtables as $k => $table)
            {
                echo 
    $k.' '.$tablesearch.'<br />';
            }
    }else{
        echo 
    $tablesearch[0].' found<br />';

    I tried using 'SHOW TABLES where table like %mark%' but this doesn't seem to work, so we need a little workaround

    hth

  3. #3
    Tranceoholic lilleman's Avatar
    Join Date
    Feb 2004
    Location
    Írebro, Sweden
    Posts
    2,716
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Quote Originally Posted by Daimaju
    I tried using 'SHOW TABLES where table like %mark%' but this doesn't seem to work, so we need a little workaround
    You can use this:

    Code:
    SHOW TABLES LIKE "%mark%"
    Yours, Erik.
    ERIK RIKLUND :: Yes, I've been gone quite a while.

  4. #4
    SitePoint Evangelist
    Join Date
    May 2004
    Location
    Germany
    Posts
    550
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    this looks a little bit easier

    shame on me for not looking at the mysql manual

  5. #5
    SitePoint Wizard
    Join Date
    Mar 2004
    Posts
    1,647
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    lilleman...
    please show me your complete example code for this action.
    thanx in advance!!!

  6. #6
    Tranceoholic lilleman's Avatar
    Join Date
    Feb 2004
    Location
    Írebro, Sweden
    Posts
    2,716
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    I assume that you are already connected to MySQL.

    PHP Code:
    $keyword 'mark';

    $sql 'SHOW TABLES LIKE "%'$keyword .'%"';
    $result mysql_query($sql) or die(mysql_error());

    while(
    $table mysql_fetch_row($result))
      echo 
    $table[0], '<br />'
    Yours, Erik.
    ERIK RIKLUND :: Yes, I've been gone quite a while.

  7. #7
    SitePoint Wizard
    Join Date
    Mar 2004
    Posts
    1,647
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thank you very much erik

  8. #8
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    Learn something new everyday! thanks erik (and reminder for asking!)
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  9. #9
    SitePoint Wizard
    Join Date
    Mar 2004
    Posts
    1,647
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    why this wont work?
    any suggestion wellcome...
    hth
    PHP Code:
    <?php
    if(empty($_POST["searchDB"])) {
    ?><form method="post" action="<?php $_SERVER["PHP_SELF"]; ?>">
    <table cellpadding="0" cellspacing="0" border="1" bordercolor="#999999">
    <tr><td width="100" border="0">Host:</td><td width="100"><input type="text" name="host"></td></tr>
    <tr><td width="100" border="0">Username:</td><td width="100"><input type="text" name="user"></td></tr>
    <tr><td width="100" border="0">Password:</td><td width="100"><input type="password" name="pass"></td></tr>
    <tr><td width="100" border="0">Database:</td><td width="100"><input type="text" name="base"></td></tr>
    <tr><td width="100" border="0">Keyword:</td><td width="100"><input type="text" name="keyword"></td></tr>
    <tr><td width="100" border="0" colspan="2"><input type="submit" name="searchDB" value="Search"></td></tr>
    </table></form><?php
    } else {
    $host $_POST["host"];
    $user $_POST["user"];
    $pass $_POST["pass"];
    $base $_POST["base"];
    $keyword $_POST["keyword"];
    $connect = @mysql_connect($host$user$pass) or die(mysql_error());
    mysql_select_db($base$connect) or die(mysql_error());
    $sql 'SHOW TABLES LIKE "%'$keyword .'%"';
    $result mysql_query($sql) or die(mysql_error());
    while(
    $table mysql_fetch_row($result)) echo $table[0], '<br />';
    }
    ?>

  10. #10
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    Hi,

    PHP Code:
    <?php
    if(empty($_POST["searchDB"])) { 
    ?><form method="post" action="<?php $_SERVER["PHP_SELF"]; ?>"> 
    <table cellpadding="0" cellspacing="0" border="1" bordercolor="#999999"> 
    <tr><td width="100" border="0">Host:</td><td width="100"><input type="text" name="host"></td></tr> 
    <tr><td width="100" border="0">Username:</td><td width="100"><input type="text" name="user"></td></tr> 
    <tr><td width="100" border="0">Password:</td><td width="100"><input type="password" name="pass"></td></tr> 
    <tr><td width="100" border="0">Database:</td><td width="100"><input type="text" name="base"></td></tr> 
    <tr><td width="100" border="0">Keyword:</td><td width="100"><input type="text" name="keyword"></td></tr> 
    <tr><td width="100" border="0" colspan="2"><input type="submit" name="searchDB" value="Search"></td></tr> 
    </table></form><?php 
    } else { 
    $host $_POST["host"]; 
    $user $_POST["user"]; 
    $pass $_POST["pass"]; 
    $base $_POST["base"]; 
    $keyword $_POST["keyword"]; 
    $connect = @mysql_connect($host$user$pass) or die(mysql_error()); 
    mysql_select_db($base$connect) or die(mysql_error());
    $query "show tables like '%$keyword%'";
    $result mysql_query($query);
    $num_results mysql_num_rows($result);
    print 
    "There are $num_results tables.<br>";
    for (
    $i 0$i $num_results$i++)
    {
    $row mysql_fetch_array($result);
    print 
    "table " $row[0] . " exists.<br>";
    }
    }
    ?>
    Should work. It gives the name of a table in the specified database.
    Is that what you wanted?

    SpikeZ
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  11. #11
    SitePoint Wizard
    Join Date
    Mar 2004
    Posts
    1,647
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    practicaly i want to view the table name where the pattern i searched exsist!
    this script doesnt do that...
    any suggestion about how to do that?
    thanx in advance!

  12. #12
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    Ahhh, so you want to know the table the keyword was found in!
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  13. #13
    SitePoint Wizard
    Join Date
    Mar 2004
    Posts
    1,647
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yep

  14. #14
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    Not got time to fully get into this but id you want I can post the page from phpMyAdmin which has the solution in it and you can hack it....
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  15. #15
    SitePoint Wizard
    Join Date
    Mar 2004
    Posts
    1,647
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanx!

  16. #16
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    PM'd!
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  17. #17
    SitePoint Evangelist
    Join Date
    May 2004
    Location
    Germany
    Posts
    550
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by spikeZ
    Hi,

    PHP Code:
    $result mysql_query($query); 
    change the above to

    PHP Code:
    $result mysql_query($query) or die('Error :'.mysql_error()); 
    Perhaps you don't have enough rights to perform the query, though i just created a mysqluser with only SELECT rights, and it worked. But perhaps there is a way to disable certain commands, and your host has done that ?

  18. #18
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    Hi Daimaju,
    The thing with the script I cobbled together based on reminders brought out the tablename if it contained the keyword that had been searched for.

    What reminder wanted was the tablename containing the record the keyword was found in.
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •