Page 1 of 1
checkbox using a query and php
Posted: Wed Mar 19, 2003 5:08 pm
by meandrew
Hi all
I was using a select option for an insert and have discovered I need to have mnore than one of the records displyed available to be selected:
This is what I have which works and I don't want!
And this is what I now have that I want bvut doesn't show the check boxes
It displays the records, this could be a html error as I have had before but I have tried that with no joy
$result=mysql_query("SELECT CountyID, City, CityID FROM city WHERE CountyID=".$CountyID." ORDER BY City");
while ($row = mysql_fetch_array($result))
{
$county_id=$row['CountyID'];
$city_id=$row['CityID'];
$city=$row['City'];
if ($CityID == $city_id)
echo "<input type=\"checkbox\" name=\"$city_id\">";
echo "> $city $city</td>";
$count++;
if($count ==3){
echo "</tr><tr>";
$count=0;
}
}
Thank you
Andrew
Posted: Wed Mar 19, 2003 9:43 pm
by daven
Not sure about all your conditions, but the following should output checkboxes. You forgot the value attribute.
Code: Select all
<?php
while ($row = mysql_fetch_array($result))
{
echo "<input type="checkbox" name="$city_id" value="$Value">";
}
?>
You also have the following line:
echo "> $city $city</td>";
The angle bracket (>) does not have a corresponding tag, so it will screw up your HTML formatting.
Posted: Thu Mar 20, 2003 3:50 am
by meandrew
I have now manged to sort this out thank you for your help
Code: Select all
echo "<tr><td>";
echo "Select Cities and Towns<br>";
echo "</td></tr>";
$queryC="SELECT CountyID, City, CityID FROM city WHERE CountyID=".$CountyID." ORDER BY City";
$result=mysql_query($queryC,$con_id);
$count=0;
echo "<tr>";
while($row=mysql_fetch_array($result)){
$county_id=$rowї'CountyID'];
$city_id=$rowї'CityID'];
$city=$rowї'City'];
if ($CityID == $city_id)
$city="city_".$city_id;
echo"<td width="25%"><input type="checkbox" name="$CityID">$city</td>";
$count++;
if($count ==3){
echo "</tr><tr>";
$count=0;
}
}
Andrew
Part two the Inserts for Two Tables
Posted: Sat Mar 22, 2003 4:22 am
by meandrew
I am now working on the insert into two tables
items and items_city
In each table there is the ID which is unique. This is what I have so far and I am not getting very far with it.
select from city and display ready for check box selection.
Code: Select all
echo "Select Cities and Towns<br>";
echo "</td></tr>";
$queryC="SELECT CountyID, City, CityID FROM city WHERE CountyID=".$CountyID." ORDER BY City";
$result=mysql_query($queryC,$con_id);
$count=0;
echo "<tr>";
while($row=mysql_fetch_array($result)){
$county_id=$rowї'CountyID'];
$city_id=$rowї'CityID'];
$city=$rowї'City'];
if ($CityID == $city_id)
$city="city_".$cityId;
echo"<td width="25%"><input type="checkbox" name="$city_id">$city</td>";
$count++;
if($count ==3){
echo "</tr><tr>";
$count=0;
}
}
once selected this is the form that should do the inserts ->
Code: Select all
<?
require("connection.php");
DBInfo();
Root();
$con_id=mysql_connect("$DBHost","$DBUser","$DBPass");
mysql_select_db($DBName);
mysql("$DBName","INSERT INTO Items VALUES(
'$ItemSKU',
'$ItemName',
'$ItemDescription',
'$PostCode',
'$Category',
'$CityID',
'$CTelephone',
'$ItemID',
'$Cfax',
'$Cemail',
'$Caddress',
'$CTown',
'$Cwww')");
$nItemId=mysql_insert_id();
$queryC="select * from city";
$result=mysql_query($queryC,$con_id);
while($row=mysql_fetch_array($result)){
$cityId=$rowї'CityID'];
$city="city_".$cityId;
$c=$$city;
if($c == "on"){
$query1="insert into item_city (item_id,city_id)values('$nItemId','$cityId')";
$result1=mysql_query($query1);
}
}
/////////////////////////
?>
I have looked at this for too long and seem to be seeing the same thing

so if someone can see something aloof that would be great
Andrew
Posted: Sat Mar 22, 2003 7:35 am
by twigletmac