Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6251235
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T13:34:39+00:00 2026-05-24T13:34:39+00:00

I have a table of items that are each individually associated with a category

  • 0

I have a table of items that are each individually associated with a category by means of an integer in a row called category. I also have a display order for each item, relevant to its associated category. This is saved in a row called pictureorder. Straightforward?

My problem arrises when the user deletes a category that contains items/pictures that are associated with it. I tell mySQL to search for any items associated with the category and to associate them with a ‘default’ category which is denoted by 0.

// IF THERE'S ANY PICTURES THAT WERE IN THAT CATEGORY,
// MOVE THEM INTO THE DEFAULT CATEGORY.
$uncategorise = "UPDATE pictures 
    SET category = '0'
    WHERE category = '$categoryID'
    AND username = '$userID'";
$queryUncat = mysql_query($uncategorise) or die(mysql_error());

This works. However, the items’ pictureorder is broken as items transferred from the deleted category may create duplicate pictureorders in the default category. I’m aware of how to solve this problem in a manner which would make multiple calls to the database. This feels too expensive. My query is whether I can use some technique I’m unaware of to update an incrementing pictureorder integer to the database as it’s called without making that row a key? Something along the lines of:

$uncategorise = "UPDATE pictures 
    SET category = '0',
        pictureorder = 'TotalofDefaultCategory++'
    WHERE category = '$categoryID'
    AND username = '$useID'";
$queryUncat = mysql_query($uncategorise) or die(mysql_error());

Thanks in advance!

Update1

Based on Kyle’s suggestion below, I am trying the following without success:

UPDATE pictures 
    SET category = '0',
        pictureorder = (SELECT COUNT(category) + 1 WHERE category='0' AND username='$useID')
    WHERE category = '$categoryID'
    AND username = '$useID';

If I omit pictureorder = (SELECT COUNT(category) + 1 WHERE category='0' AND username='$useID'), the category does indeed get changed to ‘0’ whenever the category matches $categoryID and $useID. However, if I include the addtional line, nothing changes. I don’t get any errors but pictureorder doesn’t change. Nor does category. Is the syntax correct?

Also, if I replace pictureorder = (SELECT... with pictureorder = 2 it works as expected. So I can’t see a possible problem other than the syntax being incorrect (I hope it’s not, as I feared, that it was too good to be true that you could include a COUNT in this manner).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T13:34:40+00:00Added an answer on May 24, 2026 at 1:34 pm

    I’ve been scratching my head for two days solid on this one as it turns out none of the solutions were quite right. Marc B led me on the right path although I couldn’t add to a user-defined variable in a second query in PHP, though I was able to call on it (hence some misguided trials and errors). There is a way of querying MySQL in PHP that can make multiple queries and connect them but the mysql_query method I was already using was too deeply interwoven in my site to make it an easy change.

    Instead, based on the fact that the category to be deleted ($categoryID) had existing pictureorders starting from 1 and incrementing. I was able to use this existing information to add onto the COUNT suggestion made on this page. So, although I had to use two queries, for the second one I simply added the existing pictureorder of the deleted category onto the total count of the default category for the current user.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table full of items that each have a unique ItemID .
let's say that I have a table called Items (ID int, Done int, Total
I have a table of Items, and in each row there is a link
I have a table of items, each of which has a date associated with
I have a following table using MVC that shows number of items the user
I have a recordset loop that creates a table, and every 9 items it
I have a table called 'MyTable' that looks like: ID | Item | Type
I have a table that contains items, buyprice, and sellprice. I need to figure
I have a product feed that lists clothing items multiple times, once each for
I have a table with items that are part of a thread, so they

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.