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
https://forums.phpfreaks.com/topic/57085-solved-incrementing-values-var/
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++;

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.