Click to See Complete Forum and Search --> : Mysql help


Yokiest
11-12-2009, 03:33 PM
I'm a bit new to php and mysql just know the basics
and what i'm trying to do is i have 2 tables that work together

table 1
id
state
service

table 2
id
name
city
state ...etc

now the tables are linked together by the id that is set in table2
what these 2 tables are for is to narrow down vendors
table 2 stores there infromation who there
table 1 stores where they are and what they do
since most of the vendors i work with are across the country and do many things and not one

the problem i'm having is displaying the information i get it to narrow down what i'm looking for via service but i want to display all the vendors with the same service.
here is the code that i'm using and it just shows one vendor and i have 2 inputted into the database

$sql = "SELECT * FROM vendorservice WHERE vendor_area = '" . $areaid .
"' AND vendor_servicecode = '" . $servicecode . "';";
echo $sql;
$result = mysql_query($sql, $conn) or die(mysql_error());
while ($newArray = mysql_fetch_array($result)) {
$vendor_id = $newArray['vendor_id'];
}
$sqlvendor = "SELECT * FROM vendor where vendor_id = '" . $vendor_id .
"' ORDER BY adtype LIMIT 10;";
echo $sqlvendor;
$vendorresult = mysql_query($sqlvendor, $conn) or die(mysql_error());
while ($newArray = mysql_fetch_array($vendorresult)) {
$vendor_status = $newArray['vendor_status'];
$vendorid =$newArray['vendor_id'];
$vendor_name = $newArray['vendor_name'];
$adimage = $newArray['adimage'];
$adtype = $newArray['adtype'];
}
if ($vendor_status == "A") {
if ($adtype == "T") {
echo "<div class='vendortext'><a href='vendor.php?id='". $vendor_id .">". $vendor_name ."</a></div>";
} else {
echo "<div class='vendorbanner'><a href='vendor.php?id='". $vendor_id ."><img src='". $adimage . "' /></a></div>";
}
}

Yokiest
11-12-2009, 04:56 PM
I fixed it and i'm hgappy about it i used something called a JOIN so now it shows me what i wanted but i now have another problem her is the new script i'm using

<?php
$sql = "SELECT * FROM vendorservice JOIN vendor ON vendorservice.vendor_id = vendor.vendor_id HAVING vendorservice.vendor_servicecode='". $servicecode ."' AND vendorservice.vendor_area='". $areaid ."' ORDER BY adtype ASC";
echo $sql;
$result = mysql_query($sql, $conn) or die(mysql_error());
while ($newArray = mysql_fetch_array($result)) {
$vendor_id = $newArray['vendor.vendor_id'];
$vendor_status = $newArray['vendor_status'];
$vendor_name = $newArray['vendor_name'];
$adimage = $newArray['adimage'];
$adtype = $newArray['adtype'];

if ($vendor_status == "A") {
if ($adtype == "T") {
echo "<div class='vendortext'><a href='vendor.php?id='". $vendor_id .">". $vendor_name ."</a></div>";
} else {
echo "<div class='vendorbanner'><a href='vendor.php?id='". $vendor_id ."><img src='". $adimage . "' /></a></div>";
}
}
}?>

the problem i'm having is it doesnt post the vendor id on the links