Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9

Thread: Joining DB's

  1. #1
    Regular Coder
    Join Date
    Aug 2006
    Location
    UK, London, Dartford
    Posts
    221
    Thanks
    3
    Thanked 14 Times in 14 Posts

    Joining DB's

    I have never needed to do this and no i do hehe, but i'm not sure how to do it i'll write here what i need to do....

    I need to check "Invoice DB" for "Iteam ID" then getiing the "Iteam ID" chech table "Iteams" where the "Iteam ID".... Then show the content lol.

    Chears lol, might sound confusing but any help would be great.

  • #2
    Super Moderator guelphdad's Avatar
    Join Date
    Mar 2006
    Location
    St. Catharines, Ontario Canada
    Posts
    2,634
    Thanks
    4
    Thanked 148 Times in 139 Posts
    show the structure of your tables and some sample output. then show us the attempt you have made at doing the query. we can help you from there.

  • #3
    Regular Coder
    Join Date
    Aug 2006
    Location
    UK, London, Dartford
    Posts
    221
    Thanks
    3
    Thanked 14 Times in 14 Posts
    PHP Code:
    <table border=0 width="100%" cellspacing="0" style='border:#3F6A93 1px solid;'>
      <tr bgcolor="#3F6A93" style='color:#FFFFFF; margin: 5px;' height="22">
        <td>&nbsp;<b>Item Name</b></td>
        <td>&nbsp;<b>Item Price</b></td>
        <td align="right"><b>Added</b></td>
      </tr>
    <?php
        $UN 
    explode(" "$_SESSION['uname']);
        
    $rl mysql_query("SELECT s.item_id, i.itemname, i.itemprice, i.addate FROM saleslog s, items i WHERE s.first_name = '".$UN[0]."' AND s.last_name = '".$UN[1]."'")or die(mysql_error());
                    
        while(
    $a1 mysql_fetch_array($r1)){
        
    $date date('M d, Y'$a1['i.addate']);
    ?>
      <tr bgcolor='#F5F7FA'>
        <td><?=$a1['i.itemname']?></td>
        <td><?=$a1['i.itemprice']?></td>
        <td align="right"><?=$date?></td>
      </tr>
    <?php
        
    }
    ?>
    </table>
    Thats what i think the SLQ should be but it shows a error:

    Quote Originally Posted by Error MSG
    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/phpjunk/public_html/scripts.php on line 39

  • #4
    Super Moderator guelphdad's Avatar
    Join Date
    Mar 2006
    Location
    St. Catharines, Ontario Canada
    Posts
    2,634
    Thanks
    4
    Thanked 148 Times in 139 Posts
    the issue is your php and not your mysql query. I'll move the thread to the php forum so you can get an answer faster.

  • #5
    Regular Coder
    Join Date
    Aug 2006
    Location
    UK, London, Dartford
    Posts
    221
    Thanks
    3
    Thanked 14 Times in 14 Posts
    Ok thankyou i thought it was the Query that was giving me the troble

  • #6
    Regular Coder
    Join Date
    Aug 2006
    Location
    UK, London, Dartford
    Posts
    221
    Thanks
    3
    Thanked 14 Times in 14 Posts
    Can anyone help with this or dont you understand what i'm trying to do?

  • #7
    Regular Coder goughy000's Avatar
    Join Date
    Nov 2005
    Location
    England
    Posts
    415
    Thanks
    0
    Thanked 0 Times in 0 Posts
    post your sql tables.. or at least the structure

    for example something like this:

    Code:
    name: table1
    
    ID   |column 1       |column 2    |
    -------------------------------
    1    |example data |data 2       |
    2    |example 2      | more data |
    PHP Freelancing!
    ByteForums!
    Scriptlance.comNeed a job done quick? post it on scriptlance! OR! your a programmer? sign up and get paid for these jobs!

  • #8
    Regular Coder
    Join Date
    Aug 2006
    Location
    UK, London, Dartford
    Posts
    221
    Thanks
    3
    Thanked 14 Times in 14 Posts
    Table 1:
    Quote Originally Posted by Sales Log Table
    CREATE TABLE `saleslog` (
    `id` varchar(32) NOT NULL default '',
    `date` int(10) NOT NULL default '0',
    `first_name` varchar(50) NOT NULL default '',
    `last_name` varchar(50) NOT NULL default '',
    `street` varchar(200) NOT NULL default '',
    `city` varchar(40) NOT NULL default '',
    `state` varchar(32) NOT NULL default '',
    `pcode` int(10) NOT NULL default '0',
    `country` varchar(32) NOT NULL default '',
    `email` varchar(150) NOT NULL default '',
    `item_id` varchar(30) NOT NULL default '',
    `item_name` varchar(150) NOT NULL default '',
    `item_price` float(5,2) NOT NULL default '0.00',
    `currency` char(3) NOT NULL default '',
    `exp_date` int(10) NOT NULL default '0',
    `downloaded` char(3) NOT NULL default 'no',
    KEY `id` (`id`)
    ) TYPE=MyISAM;
    2nd table

    Quote Originally Posted by Items
    CREATE TABLE `items` (
    `itemname` varchar(50) NOT NULL default '',
    `itemnum` varchar(30) NOT NULL default '',
    `itemprice` decimal(5,2) NOT NULL default '0.00',
    `filename` varchar(100) NOT NULL default '',
    `addate` int(10) unsigned NOT NULL default '0',
    `lastdate` int(10) unsigned NOT NULL default '0',
    `stat` smallint(5) unsigned NOT NULL default '0',
    PRIMARY KEY (`itemname`)
    ) TYPE=MyISAM;

  • #9
    Regular Coder goughy000's Avatar
    Join Date
    Nov 2005
    Location
    England
    Posts
    415
    Thanks
    0
    Thanked 0 Times in 0 Posts
    PHP Code:
    <?php
    session_start
    ();
    mysql_connect("127.0.0.1""root");
    mysql_select_db("leestevens");

    $_SESSION['uname'] = "jack gough";
    ?>

    <table border=0 width="100%" cellspacing="0" style='border:#3F6A93 1px solid;'>
      <tr bgcolor="#3F6A93" style='color:#FFFFFF; margin: 5px;' height="22">
        <td>&nbsp;<b>Item Name</b></td>
        <td>&nbsp;<b>Item Price</b></td>
        <td align="right"><b>Added</b></td>
      </tr>
    <?php
        $UN 
    explode(" "$_SESSION['uname']);
        
    $result mysql_query("SELECT s.item_id, i.itemname, i.itemprice, i.addate FROM saleslog s, items i WHERE s.first_name = '".$UN[0]."' AND s.last_name = '".$UN[1]."'")or die(mysql_error());
                    
        while(
    $array mysql_fetch_array($result)){
        
    $date date('M d, Y'$array['i.addate']);
    ?>
      <tr bgcolor='#F5F7FA'>
        <td><?php echo $array[itemname]?></td>
        <td><?php echo $array[itemprice]?></td>
        <td align="right"><?php echo $date?></td>
      </tr>
    <?php
        
    }
    ?>
    </table>
    this seems to be working for me now..

    if you have more problems make sure that your $_SESSION vars ar set properly by echoing them
    PHP Freelancing!
    ByteForums!
    Scriptlance.comNeed a job done quick? post it on scriptlance! OR! your a programmer? sign up and get paid for these jobs!


  •  

    Posting Permissions

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