$result=mysql_query("SELECT
            items.*, city.City
        FROM
            items, city
        WHERE
            items.Category='$Category'
            AND items.CityID='$CityName'
            AND items.CityID=21
        ORDER BY
            City
");

while ($row=mysql_query($result)) {   <==this is a/the problem, I think,
wrong function :)

$CityName=$row['0'];
$CityID=$row['1'];
        }


should be

$result=mysql_query("SELECT
            items.*, city.City
        FROM
            items, city
        WHERE
            items.Category='$Category'
            AND items.CityID='$CityName'
            AND items.CityID=21
        ORDER BY
            City
");

while ($row=mysql_fetch_row($result)) {   <== should be

$CityName=$row['0'];
$CityID=$row['1'];
        }



-----Original Message-----
From: Andrew [mailto:[EMAIL PROTECTED]
Sent: 01 March 2003 11:55
To: MySQL-Lista
Subject: Query <selected> with php


Dear Mysql guru's

I have a sneaky suspision that the my current problem is related!

I want to display

There are '$number of records' in '$the city you have selected'

However this is proving to be beyond my brains capacity to deal with :p

So,if any of you can spot what the obvious mistakes I am making I would
appreciate it very much.  This is the situation and schema.

form selects city and category:

<!-- Include Left Menu Options Here -->
<table width="146" border="0" cellpadding ="0" cellspacing="0">
 <tr class="navTable"><td class="bgColorDark" height="18">
  <span class="Header">Select City and Business</span>

 </td>
</tr>

<tr>
 <td>

<form action='./companies.php' method='POST' name='CompanySearch'>
  <input type='hidden' name='CompanySearch' value='YES' />
  <input type='hidden' name='CompanySearch' value='Simple' />

<?
require("connection.php");

mysql_connect("$DBHost", "$DBUser", "$DBPass") or
        die("could not connect");
    mysql_select_db("$DBName");

echo "<select name=\"CityID\" size=\"1\" class='menuForm'>";

$result=mysql_query("SELECT City, CityID FROM city ORDER BY City");
while ($row = mysql_fetch_array($result))
    {
        $city_id=$row['CityID'];
                $city=$row['City'];
echo "<option value=\"$city_id\"> $city </option>";
}
echo "</select>";
?>
<br>
<?

mysql_connect("$DBHost", "$DBUser", "$DBPass") or
        die("could not connect");
    mysql_select_db("$DBName");

echo "<select name=\"Category\" size=\"1\" class='menuForm'>";

$result=mysql_query("SELECT Category, CategoryID FROM category ORDER BY
Category");
while ($row = mysql_fetch_array($result)) {
echo "<option value=\"$row[CategoryID]\"> $row[Category] </option>";
}
echo "</select>";
?>

 </td>
</tr>

<tr class="navTable">
 <td class="bgColorMid">
  <table cellpadding="0" cellspacing="0" border="0" width="100%">
   <tr>
    <td align="right">

<input class="inputsubmit" type="submit" value="Find Company">

<INPUT TYPE="image" SRC="search.gif" VALUE="find a company in your city"
Name="companysearch">



</a>

     </tr>
    </table>
   </td>
  </tr>
 </form>
</table>


resluts appear here:

<!--BEGINNING OF MIDDLE COLUMN -->
<TD align="left" valign="top" class="grayfill">

<div class="subheader">&nbsp;
</div> <!-- BEGINNING MIDDLE TABLE -->

<?
$result=mysql_query("SELECT
            items.*, city.City
        FROM
            items, city
        WHERE
            items.Category='$Category'
            AND items.CityID='$CityName'
            AND items.CityID=21
        ORDER BY
            City
");

while ($row=mysql_query($result)) {

$CityName=$row['0'];
$CityID=$row['1'];
        }


?><TABLE cellpadding=5 cellspacing=3 width=\"100%\" border=0>
   <TD valign=\"top\" align=\"left\" class=\"city\">

<? echo "There were ??? companies found in $CityID are:";
?></TD>
<TD valign=\"top\" align=\"left\" class=\"companydesc\">

<?
$result=mysql_query("SELECT items.ItemSKU, items.ItemName,
items.ItemDescription, items.PostCode, items.Category, items.CityID,
items.CTelephone, items.ItemID, items.Cfax, items.Cemail, items.Caddress,
items.CTown, items.Cwww FROM items WHERE CityID='$CityID' ORDER BY CityID");

while ($row  =  mysql_fetch_row($result)) {

$City=$row['5'];
        }
/* Image here */
echo "<img src=\"$Relative/images/city/city".$City."\">";

/* Image will END here */
?>
</TD>
</TR>
</TABLE>



<?
$result=mysql_query("SELECT items.ItemSKU, items.ItemName,
items.ItemDescription, items.PostCode, items.Category, items.CityID,
items.CTelephone, items.ItemID, items.Cfax, items.Cemail, items.Caddress,
items.CTown, items.Cwww FROM items WHERE Category='$Category' and
CityID='$CityID' ORDER BY CityID");
if (!$result) echo mysql_error();
else {
    }
while ($row=mysql_fetch_row($result)) {
$IS=$row['0'];
$IN=$row['1'];
$ID=$row['2'];
$CpostC=$row['3'];
$Ca=$row['4'];
$City=$row['5'];
$Ctele=$row['6'];
$II=$row['7'];
$Cf=$row['8'];
$Ce=$row['9'];
$Caddress=$row['10'];
$Ctown=$row['11'];
$Cw=$row['12'];

echo "<div class='subheader'>&nbsp;$IN ";
echo "</div>";

echo "<div class='frontPageContentBox'>";

echo "<TABLE cellpadding=5 cellspacing=3 width=\"100%\" border=2>";
echo "<TR>";
echo "<TD valign=\"top\" align=\"left\" class=\"company\" width=\"70%\">";
echo "<B>$IN</B><BR>";

echo "a: $Caddress<BR>";
echo "a: $Ctown<BR>";

echo "p: $CpostC<BR>";
echo "t:<b> $Ctele </b><BR>";

echo "</TD>";

echo "<TD valign=\"top\" align=\"left\" class=\"companydesc\"
width=\"30%\">";
echo "</TD>";
echo "</TR>";
echo "</TABLE>";
echo "<BR>\n\n";



echo "</div>";

    }

?>

<!-- Middle TD ends here -->


It ius this thats casuiing the headache:  and I think it is related to not
having a selected clause in the resulte

<?
$result=mysql_query("SELECT
            items.*, city.City
        FROM
            items, city
        WHERE
            items.Category='$Category'
            AND items.CityID='$CityName'
            AND items.CityID=21
        ORDER BY
            City
");

while ($row=mysql_query($result)) {

$CityName=$row['0'];
$CityID=$row['1'];
        }


?><TABLE cellpadding=5 cellspacing=3 width=\"100%\" border=0>
   <TD valign=\"top\" align=\"left\" class=\"city\">

<? echo "There were ??? companies found in $CityID are:";
?></TD>

???
Andrew



---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php




---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to