Jump to content

[SOLVED] Incrementing values? $var++


Solarpitch

Recommended Posts

Hi,

 

I want to be able to get the highest value from my user_id field in the database and increment it by 1. So highest user id is 104... next user will be 105 etc.

 

I have the below code but it doesn't seem to be doing. It just puts the value in as 1 all the time. the job. Anyone help a little?

 

I got the following code from a helpful guy which works fine for him. So I am a little stumped!  :-\

 

$query = mysqli_query("SELECT MAX(user_id) `user_id` FROM `phpbb_users`");
$fetch= mysqli_fetch_assoc($mysqli_connect, $query);

$get_val= $fetch['user_id'];
$get_val++;

Link to comment
Share on other sites

I am trying to change the structure of the query.. I think thats the problem

 

something like..?

 

$query = ("SELECT MAX(user_id) `user_id` FROM `phpbb_users`");
$result = mysqli_query($mysqli_connect, $query);

$fetch = mysqli_fetch_assoc($result);

$get_val = $fetch['user_id'];
$get_val++;

Link to comment
Share on other sites

Hmmm, I tested the last code I gave you on my own website, and it worked fine. Try this:

 

<?php

$query = ("SELECT MAX(user_id) AS max FROM `phpbb_users`");
$result = mysqli_query($mysqli_connect, $query);

$fetch = mysqli_fetch_assoc($result);

$get_val = $fetch['max'];
$get_val++;
echo $get_val;

?>

 

Tell me what that echoes out, or if it works right.

Link to comment
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.