I am trying to get a date from my database, but only when certain conditions are met. I want a table to populate with data from mySQL, only when the data is submitted under a users name. (i.e. this data is relevant to this user.)
This data has been saved as a TIMESTAMP
.
$sql = "SELECT * FROM bug LIMIT 100";
$result = mysql_query($sql)or die(mysql_error());
while($row = mysql_fetch_array($result)){
$bdate = $row['bugDate'];
$bfor = $row['bugFor'];
$finduserid= mysql_query
("SELECT UserId FROM user WHERE userName='{$_SESSION['myusername']}'");
if($finduserid)
{
$getuserid = mysql_fetch_assoc($finduserid);
}
$findbdate =
mysql_query("SELECT bugDate FROM bug WHERE bugDate = '$bdate'
AND '$bfor' = '" . $getuserid['UserId'] . "'");
if($findbdate)
{
$getbdate = mysql_fetch_array($findbdate);
}
$bdatetime = new DateTime($getbdate['bugDate']);
$formattedbdate = date_format($bdatetime, 'd,M Y');
If anyone can help me I'd greatly appreciate it.
Obviously the security is terrible and I'm pretty sure this method would be the most inefficient way of doing what I'm trying to do, however I'm a noob and kind of learning by doing. If you have some noob friendly documentation on security and seeing this is making you cringe, feel free to post a link. Any help is greatly appreciated.
(Let me know if you need to know more and sorry if I didn't include it in the first place!)
EDIT: I got it working. I was doing it the most roundabout, ridiculous way anyone could come up with. Although I didn't use JOIN
it sent me on the right path. Condensed 250 lines of pointless not working code down to 3-4 that will be obvious to everyone but me.
I selected the row where my session login equalled my loginName on the database.
$finduserid= "SELECT UserId FROM user WHERE userName='{$_SESSION['myusername']}'";
$runuserid = mysql_query($finduserid)or die(mysql_error());
while($getuserid = mysql_fetch_array($runuserid)){
$userid = $getuserid['0'];
}
I then, only Selected records that included my username (instead of everything and then trying to get rid of everything that didn't have my username in it.) -_- (Im an idiot.)
$sql = "SELECT * FROM bug WHERE bugFor = '$userid'";
$result = mysql_query($sql)or die(mysql_error());