Jump to content

Recommended Posts

Hi,

 

I have a table in which one of the columns is called ID. This is an auto-increment column which assigns a new ID everytime a users joins (i.e.a new row is created in the table).

 

Now, I need to send emails to the users and have some code written to do this.

 

The problem is that if the ID is not recognised the code stops.

 

What I would like the code to do it:

1. Set the ID number (starting from 1)

2. Find the maximum ID number (i.e. the highest number assigned)

3. Keep on incrementing through the ID numbers until the number is greater than the maximum ID number and then stop.

 

Here's part of what I have so far but it does not seem to work and the code stops as soon as an ID is not found.

 

At the ops of the code I have ...

 

$maxusers=mysql_query("SELECT MAX(ID) FROM `awisemails`");

$usercount=0;

{

do{$usercount++;.... (I then count through the users)

.

.

.

}

while ($usercount <= $maxusers);

 

 

However, I must be dong something wrong? Wondered if anyone can spot it?

 

Thanks,

Simon

Link to comment
https://forums.phpfreaks.com/topic/268469-max-id-problem/
Share on other sites

Thanks Spiderwell...I have to select some data off another table too and use the ID to do this, hence using the ID.

 

Jesirose, I am not selecting all the users to email as there is then a condition from another table (it's actually the area they want to receive a weather forecast for).

 

Thanks for your replies though.

 

Simon

Link to comment
https://forums.phpfreaks.com/topic/268469-max-id-problem/#findComment-1378607
Share on other sites

Thanks, will try to compress the table.

 

Before that though, have you any idea why this won't work? How can I just get it to ignore missing ID's so long as they are less than the highest ID in the table column?

 

$maxusers=mysql_query("SELECT MAX(ID) FROM `awisemails`");

$usercount=0;

{

do{$usercount++;.... (I then count through the users)

.

.

.

}

while ($usercount <= $maxusers);

 

 

Thanks,

Simon

Link to comment
https://forums.phpfreaks.com/topic/268469-max-id-problem/#findComment-1378617
Share on other sites

if its missing it should ignore it as it wont be there?? or am I missing something here?

 

I think you are making this harder for yourself than you need to!!!

 

a recordset will contain the IDs that you have asked for, and using a while loop it will loop from start to end, whether its 5 records with ID 1 to 5 or 1000 records with ID from 1 to 1000.

If could even be  a number inbetween , without being incremental all the time due to missing/deleted rows. like ID 50 to 250 but not having 175 to 200

 

You dont need a usercount, you dont need a max users, unless I have misunderstood greatly what is going on

 

 

Link to comment
https://forums.phpfreaks.com/topic/268469-max-id-problem/#findComment-1378621
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.