
dean7
Members-
Posts
309 -
Joined
-
Last visited
Everything posted by dean7
-
Hey guys, I'm attempting to code a simple find user script for my website in which I cannot get my head around why my data in my while loop isn't displaying. I keep having breaks from coding as I only do it for something todo when I have time so this website wont be going live its just for me to make so if its unsecure its no big deal. if (isset($_POST['user_button']) && ($_POST['theusername'])){ $theusername = $_POST['theusername']; $query11 = "SELECT * FROM UsersRegTable WHERE username LIKE ':theusername'";$select = $db->prepare($query11);$select->bindValue(":theusername", "%".$theusername."%"); $select->execute();$total = count($select); echo $total; // always finds 1 echo "</table><br /><table width='25%' border='1' align='center' cellpadding='0' cellspacing='0' class='tableborder'><tr><td colspan='2' class='header' align='center'>Users:</td></tr><tr><td class='forum' align='center'>Username:</td><td class='forum' align='center'>Rank:</td></tr>"; if ($total == "0"){echo "<tr> <td colspan='2' align='center'>Username was not found!</td></tr>";} while($Ob = $select->fetch(PDO::FETCH_ASSOC)){ echo "<tr> <td align='center'><a href='profile.php?view=".$Ob['username']."'>".$Ob['username']."</a></td><td align='center'>".$Ob['rank']."</td></tr> </tr>"; } } Back on subject, when I echo the rows its found it always says 1 although it never displays the usernames it has found in the loop? Any help will be great! Thanks in advance
-
Would it be ideal to hold the timestamp in session then? Thank you for the advice about the query in the loop and selecting all so have change them. These JOINS, I've looked up on them on Google as I've not actually used them and they say about Inner Join, Outter Join, Left join, Right join etc, what join would I need to use for my code? Getting my head around them is seeming rather hard right now
-
Hey guys, I'm currently trying to code an online script which simply displays whos online and a link to their profile. I have coded something similar in MySQL but changing to PDO has made it harder, but anyway, I have a weird problem in which it don't always show when the user is online then when it does after some little time it disappears showing, but when it don't show the user whos online it counts that there is one user online but when it shows the user online it counts two users even though there is only one This is how I update my timestamp in my functions file: $TimeNow = time() + (60 * 10); $LoggedIn1 = $db->prepare("UPDATE UsersRegTable SET timestamp = :timestamp WHERE username = :username"); $LoggedIn1->bindValue(':timestamp', $TimeNow); $LoggedIn1->bindValue(':username', $Username); $LoggedIn1->execute(); This is my online code: <?php $timenow = time(); $UsersTable = $db->prepare("SELECT * FROM UsersRegTable WHERE timestamp > $timenow ORDER by id DESC"); $UsersTable->execute(); $UsersTable1 = $UsersTable->fetchObject(); $NoUsers = "SELECT COUNT(*) as totalusers FROM `UsersRegTable` WHERE timestamp > $timenow"; $NumQuery = $db->prepare($NoUsers); $NumQuery->execute(); $UsersObj = $NumQuery->fetchObject(); $UsersObj->totalusers; $HowManyOnline = ($UsersObj->totalusers) ? "{$UsersObj->totalusers} " : "0"; // Shows correct amount when it shows nobody online but shows wrong amount when displays someones online // $num = mysql_num_rows($select); while ($UsersTable11 = $UsersTable->fetchObject()){ $UsersInfo = $db->prepare("SELECT * FROM UserInfoTable WHERE username = :username"); $UsersInfo->bindParam(":username", $Username); $UsersInfo->execute(); $UsersInfo1 = $UsersInfo->fetchObject(); if($UsersInfo1->userlevel == "2"){ // Admin $Name = "<font color='#000000'>$UsersInfo1->username</font>"; }elseif ($UsersInfo1->userlevel == "3"){ // Owner $Name = "<font color='A7A7A7'>$UsersInfo1->username</font>"; }else{ $Name = "$UsersTable11->username"; } echo "<a href='profile.php?view=$UsersInfo1->username'> $Name </a>,"; } ?> Any help to get me around this would be great appreciated! Thanks
-
Thanks for your help! I have tried and tested this bit of code but it is still saying that I have no messages yet I know I do. This bit: $inboxCountHtml = ($inbox->unreadCount) ? "{$userInbox->unreadCount} New" : "0"; Has slightly confused me though? Should {$userInbox->unreadCount} be {$inbox->unreadCount} as where did the $userInbox variable come from Thanks for your help
-
Hey guys, I've not done any coding in a long time although I'm starting to get back into it, using PDO rather than MySQL aswell. On the code below I'm simply trying to pull information from the database to tell the user if he/she has a message, but the problem I've got is its saying I haven't got a message even when I have? Am I missing something completely simple here or have I got to approach this a complete different way than I have done? <?php$Unread = 0;$UsersInbox = $db->prepare("SELECT * FROM `inbox` WHERE `to` = ':username' AND `read` = ':unread'");$UsersInbox->bindParam(":username", $Username);$UsersInbox->bindParam(":unread", $Unread);$UsersInbox->execute();$UsersInbox1 = $UsersInbox->fetchObject();$NumberOfMessage = $UsersInbox->rowCount(); ?><div class="FooterText"><a href="Inbox.php">Inbox</a>(<?php if ($NumberOfMessage != "0"){ echo "New"; }else{ echo "0"; } ?>) Thanks for any help! Dean
-
I currently have: Scrap that I have it working now thank you! Just had to put the : in the array if (isset($_GET['del'])){ $DoQuery1 = ("SELECT * FROM BoxingResults"); $query1 = $conn->query($DoQuery1); $Obj = $query1->fetch(PDO::FETCH_OBJ); $PostIdThing = $_GET['del']; $idnum = $Obj->id; $delete = "DELETE FROM BoxingResults WHERE id = :boxingid LIMIT 1"; $Startoff = $conn->prepare($delete); if (!$Startoff->execute(array('boxingid'=>$PostIdThing))){ print_r ($Startoff->errorInfo()); }else{ echo ("Result ".$PostIdThing." deleted!"); } }
-
Hey thanks for your reply, I've tried removing that line but it still does the exact same thing
-
Hey guys, I've recently started coding again after a long break away from it but I'm trying to learn PDO, so as a Boxing fan I thought I'll try to code my own Boxing Score card. I've not tested it all as of yet but I'm getting a problem when I go to delete a record from the database. Here is the delete part of my code: </tr> <?php $DoQuery = ("SELECT * FROM BoxingResults"); $query = $conn->query($DoQuery); while ($r = $query->fetch(PDO::FETCH_OBJ)){ echo ' <tr> <td align="center" width="">'.$r->FavBoxer.'</td><td align="center" width="">'.$r->R1.'</td><td align="center" width="">'.$r->R2.'</td><td align="center" width="">'.$r->R3.'</td><td align="center" width="">'.$r->R4.'</td><td align="center" width="">'.$r->R5.'</td><td align="center" width="">'.$r->R6.'</td><td align="center" width="">'.$r->R7.'</td><td align="center" width="">'.$r->R8.'</td><td align="center" width="">'.$r->R9.'</td><td align="center" width="">'.$r->R10.'</td><td align="center" width="">'.$r->R11.'</td><td align="center" width="">'.$r->R12.'</td><td align="center" width="" class="header">'.$r->FavPoints.'</td><td align="center" width="" rowspan="2" class="Delete"><a href="index.php?del='.$r->id.'">Delete (X)</a></td> </tr> <tr> <td align="center" width="">'.$r->UnFavBoxer.'</td><td align="center" width="">'.$r->UR1.'</td><td align="center" width="">'.$r->UR2.'</td><td align="center" width="">'.$r->UR3.'</td><td align="center" width="">'.$r->UR4.'</td><td align="center" width="">'.$r->UR5.'</td><td align="center" width="">'.$r->UR6.'</td><td align="center" width="">'.$r->UR7.'</td><td align="center" width="">'.$r->UR8.'</td><td align="center" width="">'.$r->UR9.'</td><td align="center" width="">'.$r->UR10.'</td><td align="center" width="">'.$r->UR11.'</td><td align="center" width="">'.$r->UR12.'</td><td align="center" width="" class="header">'.$r->UnFavPoints.'</td> </tr> <tr> <td colspan="15" class="Uuheader" align="center">Winner: '.$r->Winner.'</td> </tr> <tr> <td colspan="15" class="Uuheader"> </td> </tr>'; } if (isset($_GET['del'])){ $DoQuery1 = ("SELECT * FROM BoxingResults"); $query1 = $conn->query($DoQuery1); $Obj = $query1->fetch(PDO::FETCH_OBJ); $PostIdThing = $_GET['del']; $idnum = $Obj->id; $delete = "DELETE FROM BoxingResults WHERE id = ':boxingid' LIMIT 1"; $Startoff = $conn->prepare($delete); $Startoff->bindValue(':boxingid', $PostIdThing); $Startoff->execute(array(':boxingid' => 1)); if (!$Startoff->execute()){ print_r ($Startoff->errorInfo()); } echo ("Result ".$PostIdThing." deleted!"); } ?> When I click the delete button I'm wanting it to delete the record from the database although currently when I press the delete button its saying its deleted with the correct ID but not actually deleting. I've search over google and just cannot find something to help me. Thanks for any help given.