Jump to content
MakeWebGames

Question about Lottery mod


Miks

Recommended Posts

I have created a table in the database to store the winner of the lottery. The table has 3 columns: id, lotuid(userid), lotuname(username), the table successfully collects the users id but doesnt collect the username

This is what I have done

		//Add to winner log
$test=$db->query("SELECT `username` FROM `users` WHERE `userid`='$userid'");
$ug=$db->fetch_row($test);
$db->query("INSERT INTO `lotterylog` (`id`, `lotuid`, `lotuname`) VALUES ('', '{$userid}', '{$test}')");

 

Any advice?

Link to comment
Share on other sites

I have created a table in the database to store the winner of the lottery. The table has 3 columns: id, lotuid(userid), lotuname(username), the table successfully collects the users id but doesnt collect the username

This is what I have done

		//Add to winner log
$test=$db->query("SELECT `username` FROM `users` WHERE `userid`='$userid'");
$ug=$db->fetch_row($test);
$db->query("INSERT INTO `lotterylog` (`id`, `lotuid`, `lotuname`) VALUES ('', '{$userid}', '{$test}')");

 

Any advice?

could easy be changed to

if its a auto increment then you don't need to include it in the bit for sql

$username = $db->fetch_single($db->query("SELECT `username` FROM `users` WHERE `userid` = {$ir['userid']}");
$db->query("INSERT INTO `lotterylog` (`lotuid`, `lotuname`) VALUES ('{$ir['userid']}', '{$username}')");

or if you wanted to fetch more than 1 column from the table same method can be applied but altered a little

$un = $db->fetch_row($db->query("SELECT `username` FROM `users` WHERE `userid` = {$ir['userid']}");
$db->query("INSERT INTO `lotterylog` (`lotuid`, `lotuname`) VALUES ('{$ir['userid']}', '{$un['username']}')");
Edited by NonStopCoding
Link to comment
Share on other sites

could easy be changed to

if its a auto increment then you don't need to include it in the bit for sql

$username = $db->fetch_single($db->query("SELECT `username` FROM `users` WHERE `userid` = {$ir['userid']}");
$db->query("INSERT INTO `lotterylog` (`lotuid`, `lotuname`) VALUES ('{$ir['userid']}', '{$username}')");

or if you wanted to fetch more than 1 column from the table same method can be applied but altered a little

$un = $db->fetch_row($db->query("SELECT `username` FROM `users` WHERE `userid` = {$ir['userid']}");
$db->query("INSERT INTO `lotterylog` (`lotuid`, `lotuname`) VALUES ('{$ir['userid']}', '{$un['username']}')");

This is assuming that the $ir variable has been previously defined as the current player's information (extracted from the database in globals.php)

With that being said, the `username` is already part of the $ir associative array. Re-selecting the name shouldn't be necessary.

$db->query("INSERT INTO `lotterylog` (`lotuid`, `lotuname`) VALUES (".$ir['userid'].", '".$ir['username']."')");
Link to comment
Share on other sites

This is assuming that the $ir variable has been previously defined as the current player's information (extracted from the database in globals.php)

With that being said, the `username` is already part of the $ir associative array. Re-selecting the name shouldn't be necessary.

$db->query("INSERT INTO `lotterylog` (`lotuid`, `lotuname`) VALUES (".$ir['userid'].", '".$ir['username']."')");

hello stranger :) ye never thought of that much easier lol

Link to comment
Share on other sites

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.   Paste as plain text instead

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