mysql auto_increment

I am writing a catologe application and i have a problem when it comes
to the edit product part. I have a table with the catogories and a table
with manufacturers.
Each table has a id column and a name column. The id column is set up in
the MySQL to auto_increment, which works fine normally, but i am writing
this script:

function edit_cat_radio($item_cat_id)
{
connect();
$sql = "SELECT * FROM cat DISTINGT ORDER BY cat_id";
$result = mysql_query($sql);
$k = 1;
while ($row = mysql_fetch_assoc($result))
{
extract($row);
echo '<label for="',$cat_name,'">',$cat_name,'<input
type="radio" name="fcat" value="',$cat_id,'" id="',$cat_id,'"';
if($k == $item_cat_id)
{
echo 'checked';
}
echo ' />';
$k++;
}
return;
}

This should (in theory) automatically check the radio button of the
existing catogory. It would work fine; but what seems to mess it up is
the auto_increment.

If i delete a catogory/manufacturer from the id's remain the same. and
end up like this:
cat_id cat_name
1 Bridlework
2 Clippers
3 Clothing
4 Dressage Tests
5 DVD/Video/Books
9 Footwear

but if the cat_id is 9 the /while /statement doesnt repeat 9 times so
the counter never reaches 9.

I don't know if you got all that, its hard to explain.

I would appreciate any help on how to sort this out.

Thanks

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Chris Hale [ So, 07 September 2008 23:16 ] [ ID #1967671 ]

Re: mysql auto_increment

I guess this code was not copy pasted from your actual source? It
would generate mysql errors.

Anyway, I think I've an idea of what you want, so here's my two cents :

function edit_cat_radio($item_cat_id) {
connect();
$query = mysql_query("SELECT * FROM cat");
while ($row = mysql_fetch_assoc($query)) {
echo "<label for=\"{$row['cat_name']}\">{$row['cat_name']}<input
type=\"radio\" name=\"fcat\" value=\"{$row['cat_id']}\"
id=\"{$row['cat_id']}\" " . ($item_cat_id == $row["cat_id"] ?
"checked=\"checked\"" : "") . "/>\n";
}
}



On Sun, Sep 7, 2008 at 11:16 PM, Chris Hale <php [at] chrishale.co.uk> wrote:
> I am writing a catologe application and i have a problem when it comes to
> the edit product part. I have a table with the catogories and a table with
> manufacturers.
> Each table has a id column and a name column. The id column is set up in the
> MySQL to auto_increment, which works fine normally, but i am writing this
> script:
>
> function edit_cat_radio($item_cat_id)
> {
> connect();
> $sql = "SELECT * FROM cat DISTINGT ORDER BY cat_id";
> $result = mysql_query($sql);
> $k = 1;
> while ($row = mysql_fetch_assoc($result))
> {
> extract($row);
> echo '<label for="',$cat_name,'">',$cat_name,'<input type="radio"
> name="fcat" value="',$cat_id,'" id="',$cat_id,'"';
> if($k == $item_cat_id)
> {
> echo 'checked';
> }
> echo ' />';
> $k++;
> }
> return; }
>
> This should (in theory) automatically check the radio button of the existing
> catogory. It would work fine; but what seems to mess it up is the
> auto_increment.
>
> If i delete a catogory/manufacturer from the id's remain the same. and end
> up like this:
> cat_id cat_name
> 1 Bridlework
> 2 Clippers
> 3 Clothing
> 4 Dressage Tests
> 5 DVD/Video/Books
> 9 Footwear
>
> but if the cat_id is 9 the /while /statement doesnt repeat 9 times so the
> counter never reaches 9.
>
> I don't know if you got all that, its hard to explain.
>
> I would appreciate any help on how to sort this out.
>
> Thanks
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Evert Lammerts [ So, 07 September 2008 23:46 ] [ ID #1967672 ]

Re: mysql auto_increment

Pastebin is so much nicer when posting code. Find the code i've sent here:

http://pastebin.com/mc5d611a

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Evert Lammerts [ So, 07 September 2008 23:49 ] [ ID #1967673 ]

Re: mysql auto_increment

Little change - the label was not used in the right way:

http://pastebin.com/m2d98e677

On Sun, Sep 7, 2008 at 11:46 PM, Evert Lammerts
<evert.lammerts [at] gmail.com> wrote:
> I guess this code was not copy pasted from your actual source? It
> would generate mysql errors.
>
> Anyway, I think I've an idea of what you want, so here's my two cents :
>
> function edit_cat_radio($item_cat_id) {
> connect();
> $query = mysql_query("SELECT * FROM cat");
> while ($row = mysql_fetch_assoc($query)) {
> echo "<label for=\"{$row['cat_name']}\">{$row['cat_name']}<input
> type=\"radio\" name=\"fcat\" value=\"{$row['cat_id']}\"
> id=\"{$row['cat_id']}\" " . ($item_cat_id == $row["cat_id"] ?
> "checked=\"checked\"" : "") . "/>\n";
> }
> }
>
>
>
> On Sun, Sep 7, 2008 at 11:16 PM, Chris Hale <php [at] chrishale.co.uk> wrote:
>> I am writing a catologe application and i have a problem when it comes to
>> the edit product part. I have a table with the catogories and a table with
>> manufacturers.
>> Each table has a id column and a name column. The id column is set up in the
>> MySQL to auto_increment, which works fine normally, but i am writing this
>> script:
>>
>> function edit_cat_radio($item_cat_id)
>> {
>> connect();
>> $sql = "SELECT * FROM cat DISTINGT ORDER BY cat_id";
>> $result = mysql_query($sql);
>> $k = 1;
>> while ($row = mysql_fetch_assoc($result))
>> {
>> extract($row);
>> echo '<label for="',$cat_name,'">',$cat_name,'<input type="radio"
>> name="fcat" value="',$cat_id,'" id="',$cat_id,'"';
>> if($k == $item_cat_id)
>> {
>> echo 'checked';
>> }
>> echo ' />';
>> $k++;
>> }
>> return; }
>>
>> This should (in theory) automatically check the radio button of the existing
>> catogory. It would work fine; but what seems to mess it up is the
>> auto_increment.
>>
>> If i delete a catogory/manufacturer from the id's remain the same. and end
>> up like this:
>> cat_id cat_name
>> 1 Bridlework
>> 2 Clippers
>> 3 Clothing
>> 4 Dressage Tests
>> 5 DVD/Video/Books
>> 9 Footwear
>>
>> but if the cat_id is 9 the /while /statement doesnt repeat 9 times so the
>> counter never reaches 9.
>>
>> I don't know if you got all that, its hard to explain.
>>
>> I would appreciate any help on how to sort this out.
>>
>> Thanks
>>
>> --
>> PHP Database Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
>

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Evert Lammerts [ So, 07 September 2008 23:52 ] [ ID #1967674 ]
PHP » gmane.comp.php.database » mysql auto_increment

Vorheriges Thema: If( Query)
Nächstes Thema: Import Excel sheet into SQL