Results 1 to 3 of 3

Thread: Get values from two db tables at same time

  1. #1
    Join Date
    Nov 2011
    Location
    Sweden
    Posts
    36
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Default Get values from two db tables at same time

    Hi i wold like to get some values from two differnt DB tables (at the same server and DB)

    This are the connection codes i need to combine:

    Code:
    <?php
    if ($_SERVER['REQUEST_METHOD'] == 'POST' && $_POST['form_name'] == 'loginform')
    {
       $success_page = './tack.php';
       $error_page = './error.php';
       $mysql_server = '*********';
       $mysql_username = 'jobreg@****';
       $mysql_password = 'jobler****';
       $mysql_database = 'jobler****';
       $mysql_table = 'jobreg';
       
       
       $db = mysql_connect($mysql_server, $mysql_username, $mysql_password);
       if (!$db)
       {
          die('Failed to connect to database server!<br>'.mysql_error());
       }
       mysql_select_db($mysql_database, $db) or die('Failed to select database<br>'.mysql_error());
       $sql = "SELECT Idkod FROM ".$mysql_table." WHERE Idkod = '".mysql_real_escape_string($_POST['Idkod'])."'";
       $result = mysql_query($sql, $db);
       if ($data = mysql_fetch_array($result))
       {
    
    if ($data['Idkod'] != 1)
    {
          $found = true;
             $Idkod = $data['Idkod'];
          }
    
             
       }
       mysql_close($db);
       if($found == false)
       {
          header('Location: '.$error_page);
          exit;
       }
       else
       {
          session_start();
          $_SESSION['Idkod'] = $_POST['Idkod'];
         
          $rememberme = isset($_POST['rememberme']) ? true : false;
          if ($rememberme)
          {
             setcookie('Idkod', $_POST['Idkod'], time() + 3600*24*30);
          }
          header('Location: '.$success_page);
          exit;
       }
    }
    $Idkod = isset($_COOKIE['Idkod']) ? $_COOKIE['Idkod'] : '';
    ?>
    AND

    Code:
    <?php
    if ($_SERVER['REQUEST_METHOD'] == 'POST' && $_POST['form_name'] == 'loginform')
    {
    
    $databasename='*******'; // Name of the database
    $mysqladd='*******'; // Address to the MySQL Server
    $mysqluser='jobadd@*****'; // Your MySQL UserName
    $mysqlpass='jobler****'; // Your MySQL Password
    
    
    //CONNECT TO MYSQL
    $link=mysql_connect($mysqladd, $mysqluser, $mysqlpass) or die('Could not connect to database: ' . mysql_error());
    
    //CONNECT TO DATABASE
    mysql_select_db($databasename, $link) or die('Could not connect to table: ' . mysql_error());
    
    $query="SELECT * FROM jobadd ORDER BY Timestamp DESC"; 
    $result=mysql_query($query); 
     
    $num=mysql_numrows($result); 
    
    mysql_close(); 
     
    $i=0; 
    while ($i < $num) : 
    
    ?>

  2. #2
    Join Date
    Jan 2008
    Posts
    441
    Thanks
    67
    Thanked 4 Times in 4 Posts

    Default

    what happens when you run this?

  3. #3
    Join Date
    Nov 2011
    Location
    Sweden
    Posts
    36
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by ggalan View Post
    what happens when you run this?
    The first code seams to stop the second code from working.

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
  •