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 '
Re: mysql auto_increment
am 07.09.2008 23:46:29 von Evert Lammerts
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 "
Re: mysql auto_increment
am 07.09.2008 23:49:26 von Evert Lammerts
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
Re: mysql auto_increment
am 07.09.2008 23:52:33 von Evert Lammerts
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 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 "{$row['cat_name']}
> 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 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 '',$cat_name,'
>> 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