...

View Full Version : Joining DB's



Lee Stevens
10-27-2006, 10:33 PM
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.

guelphdad
10-28-2006, 01:07 AM
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.

Lee Stevens
11-07-2006, 11:39 AM
<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:



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

guelphdad
11-07-2006, 12:37 PM
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.

Lee Stevens
11-07-2006, 06:01 PM
Ok thankyou i thought it was the Query that was giving me the troble

Lee Stevens
11-09-2006, 03:35 PM
Can anyone help with this or dont you understand what i'm trying to do?

goughy000
11-11-2006, 08:57 PM
post your sql tables.. or at least the structure

for example something like this:



name: table1

ID |column 1 |column 2 |
-------------------------------
1 |example data |data 2 |
2 |example 2 | more data |

Lee Stevens
11-11-2006, 09:04 PM
Table 1:


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



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;

goughy000
11-11-2006, 09:28 PM
<?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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum