Vel
Members-
Posts
130 -
Joined
-
Last visited
Everything posted by Vel
-
Just seen it. Missed a " in the href tag. EDIT: Yep, that solved it, working fine now. Damn quotation mark. Thanks for your time.
-
Source code shows it should be showing correctly. I didn't think to check that hehe. I guess it's a browser issue then, it's being run in a in-game browser in a game called Eve Online. <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Shield Fleet :: Home</title> </head> <body>You are currently in a fleet. The details of the fleet are below.<br><table><tr><th>Pilot</th><th>Ship</th><th>Type</th></tr><tr><td><a href="#" onClick="CCPEVE.showInfo{1377, 359320675}>StyphonUK</a></td><td>Nightmare</td><td>DPS Boat</td></tr></table><br><a href="fc.php">Fleet Command Page</a></body> </html>
-
The HTML table is empty where it should be displaying the details of members in the fleet.
-
I am trying to load all rows from a table in a database into a table on a webpage. I cannot understand why the following code does not work: <?php ... echo "You are currently in a fleet. The details of the fleet are below.<br>"; $fleetName = $_SESSION['charFleetName']; $sqlFleetDetails = "SELECT * FROM `$fleetName`"; $queryFleetDetails = mysql_query($sqlFleetDetails); echo "<table>"; echo "<tr>"; echo "<th>Pilot</th>"; echo "<th>Ship</th>"; echo "<th>Type</th>"; echo "</tr>"; while($rowFleetDetails = mysql_fetch_array($queryFleetDetails)) { $charId = $rowFleetDetails['charId']; $charName = $rowFleetDetails['charName']; $shipHull = $rowFleetDetails['shipHull']; $shipType = $rowFleetDetails['shipType']; echo "<tr>"; echo "<td><a href=\"#\" onClick=\"CCPEVE.showInfo{1377, " . $charId . "}>" . $charName . "</a></td>"; echo "<td>" . $shipHull . "</td>"; if($shipType == 1) echo "<td>Logistics</td>"; if($shipType == 2) echo "<td>DPS Boat</td>"; if($shipType == 3) echo "<td>Sniper 120Km+</td>"; if($shipType == 4) echo "<td>Off-grid Booster</td>"; echo "</tr>"; } echo "</table><br>"; I originally had the $rowFleetDetails['charId'] and others in the echo instead of loading them into variables then echoing the variables but changed it to see if that was working, neither is. If I add an extra line outside of the while loop to echo the output of the array then the information is displayed fine, so I know that the information is being transferred from the table into the array correctly, but why is it not outputting properly in the While loop?
-
Sure, although I'm thinking it may just be easier to go back to the loop in the php code to identify the position in the queue. <?php if($_SESSION['charIsInQueue'] == TRUE) { //Check queue flag $charShipType = $_SESSION['charShipType']; $sqlSelectQueue = mysql_query("SELECT rank, entryTime, charId, inviteSent, inviteAccepted FROM (SELECT @rank:=@rank+1 AS rank, entryTime, charId, inviteSent, inviteAccepted FROM queue WHERE shipType = '$charShipType ' ORDER BY entryTime) subselectname WHERE charId = ".$_SESSION['charId']) or die("Error: " . mysql_error()); //Set sql to load queue $numberOfRows = mysql_num_rows($sqlSelectQueue); //Count total number of rows $rowNumber = mysql_fetch_row($sqlSelectQueue); //Increase row number and check to see if this is the character, if not repeat. /* while($getSelectQueue = mysql_fetch_assoc($sqlSelectQueue)) { $rowNumber++; if($getSelectQueue['charId'] == $_SESSION['charId']) //Check if this is the character break; }*/ while($getSelectQueue = mysql_fetch_assoc($sqlSelectQueue)) print_r($getSelectQueue); echo $rowNumber[0] . "<br>"; echo $rowNumber[1] . "<br>"; echo $rowNumber[2] . "<br>"; echo $rowNumber[3] . "<br>"; echo $rowNumber[4] . "<br>"; echo "You are number " . $rank . " of " . $numberOfRows; } Output is: 2011-04-20 00:28:45 359320675 0 0 You are number of 1
-
Nope, that still comes back with nothing in rank.
-
Adding a new column with auto increment to an existing table
Vel replied to wright67uk's topic in MySQL Help
I'm not 100% with this, as I'm fairly new myself, but I think you can only use auto increment on integers. Try setting the column to an integer instead of variable character and try again. ALTER TABLE `business` ADD `ID` INT AUTO_INCREMENT AFTER `Name` You also don't want it to be Not Null, as when the data is submitted it will be null, and then the database will automatically fill in the field. -
Bump, can anyone tell me how to get the rank out?
-
Hi Keith, thanks for the extra info. How do I get the result out? If I try outputting the query directly I get 'Resource id #10', if I use mysql_fetch_row I get the results in an array, and would expect 0 to be the rank, however 0 is empty.
-
Mess was OK, it was enough to allow me to complete it and get it working . Thank you for the help. For anyone interested final code to get this working was: <?php ... if($_SESSION['charIsInQueue'] == TRUE) { //Check queue flag $charShipType = $_SESSION['charShipType']; $sqlSelectQueue = mysql_query("SELECT @rank:=@rank+1 AS rank, entryTime, charId, inviteSent, inviteAccepted FROM queue WHERE shipType = '$charShipType ' ORDER BY entryTime") or die("Error: " . mysql_error()); //Set sql to load queue $numberOfRows = mysql_num_rows($sqlSelectQueue); //Count total number of rows $rowNumber = 0; //Increase row number and check to see if this is the character, if not repeat. while($getSelectQueue = mysql_fetch_assoc($sqlSelectQueue)) { $rowNumber++; if($getSelectQueue['charId'] == $_SESSION['charId']) //Check if this is the character break; } echo "You are number " . $rowNumber . " of " . $numberOfRows; } Also, because I'd like to learn, can someone please explain what @rank=@rank+1 AS rank is for?
-
Server time. But as said, use timestamps for age of entries; you could also set a trigger to update the time of the entry automatically. Creating a field called "date_added", and assigning it as INT(integer) with eight to ten lengths. Only then, would your query be: SELECT `charId` FROM queue WHERE shipType = '$charShipType ' ORDER BY entryTime ...and don't use the MySQL delimiter(;), it will spew errors as PHP doesn't support multiple queries in that fashion. Also, you then need to select it: eg. $rowNumber = mysql_fetch_assoc($rowNumber);/php] That would return an array of charId[i]s[/i], ordered by the time they were inserted. Thanks for the info, however I don't want it to return an array of charId's, only the position in the queue of the current character.
-
Editing it has gotten rid of the error, but is not giving the expected result. The code now reads: <?php ... if($_SESSION['charIsInQueue'] == TRUE) { //Check queue flag $charShipType = $_SESSION['charShipType']; $rowNumber = mysql_query("SELECT @rank:=@rank+1 AS rank, entryTime, charId, inviteSent, inviteAccepted FROM queue WHERE shipType = '$charShipType ' ORDER BY entryTime;") or die("Error: " . mysql_error()); //Get row number $sqlQuery = mysql_query("SELECT * FROM queue"); //Set sql query $numberOfRows = mysql_num_rows($sqlQuery); //Count total number of rows echo "You are number " . $rowNumber . " of " . $numberOfRows; } And the page output is: You are number Resource id #10 of 3
-
One quick question with that, will CURRENT_TIMESTAMP use the servers timestamp or request it from the browser's local machine?
-
Hi guys, I'm new to php and mysql and loving it so far, however have stumbled upon a query that google hasn't been able to solve. First off MYSQL version reads as 5.0.92-log Protocol Revision 10. I have created a queue, where characters (avatars in a game if you will) are stored in a table called queue. Queue has 6 columns, key (unique ID), charName, charID, shipType, inviteSent, inviteAccepted. I'm trying to identify what position in the queue they are in, but only with people of the same ship type (I'd like to keep the queue to 1 database for all ship types if possible, but can split to 1 table per ship type if it won't work). After a little googling I came up with this code: <?php ... if($_SESSION['charIsInQueue'] == TRUE) { //Check queue flag $charShipType = $_SESSION['charShipType']; $rowNumber = mysql_query("SELECT @rank:=@rank+1 AS rank, inviteSent, inviteAccepted COUNT(*) as charId FROM queue WHERE shipType = '$charShipType';") or die("Error: " . mysql_error()); //Get row number $sqlQuery = mysql_query("SELECT * FROM queue"); //Set sql query $numberOfRows = mysql_num_rows($sqlQuery); //Count total number of rows echo "You are number " . $rowNumber . " of " . $numberOfRows; } However this throws up the error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'COUNT(*) as charId FROM queue WHERE shipType = '1'' at line 1 I have no idea what the code is even doing, let alone where to begin to get it working. If someone could explain what is happening as well as the correct code needed I'd be very grateful.
-
I highly recommend you take a look at this tutorial: http://www.phpeasystep.com/phptu/6.html I found it very easy to follow and most useful.
-
ob_start() doesn't start your session. It starts buffering to stop any information other than headers being sent. You need to use ob_end_flush to release the buffered information. But as you want to initiate the session at the top of the script you don't need ob_start() at all AFAIK. Just replace ob_start() with session_start(). EDIT: I see you've put your code at the top that's why you have ob_start(). Why is all your code at the top of the page and not in the body section?
-
Yea, I realised after he meant the big warning at the top. I just edited my code before seeing your response.
-
You can use the following: <?php error_reporting(0); $con=mysql_connect("$host", "$username", "$password") if(!$con) die('Could not connect: ' . mysql_error()); ?>
-
Solved. The problem was after reloading admin.php it no longer new the name of the popup window. I added an unload event that checked to see if the popup was open, and if so, close it. When the form in the popup passes the information back to the parent window and reloads the admin.php page it triggers the unload event, closing the popup.
-
Can anyone suggest how to close this popup please?
-
That's fine. The code is split over 2 pages, both coded in php. The first page first looks to see if an account has been selected. If not it checks to see if there are any new accounts in the database. If there is more than 1 new account (there is a flag in the database for new accounts) it offers the users a hyperlink, which triggers the second page in the form of a popup. In the popup a form is loaded with a selection box, and in the selection box is loaded all usernames of the new accounts. The default selection is "Select User" and links to no account, just so there is some text with instructions for the user and for verification. The user then selects an account from the drop down list and submits the form. A javascript verification process verifies that the "Select User" option isn't still selected, and then the form is passed back using the get method to the parent window. The admin page is loaded again with the form information available. The admin page detects the new information and then proceeds to fill the selected account into a form. Once the parent window has the information, I need the popup to close.
-
The popup should be closed as soon as it passes the form back to the parent admin page. This is the popup page: <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Fearless Bandits :: Select User</title> </head> <body> <?php //Check for config file and initiate session. require("config.php"); session_start(); //Connect to DB if(!$con) die('Could not connect: ' . mysql_error()); mysql_select_db("$dbname") or die("Cannot select DB"); //Load mode if(isset($_GET['mode'])) $mode = $_GET['mode']; else $mode = NULL; //Select users based on mode switch($mode) { case "new": //Load the names of all new accounts into a form, verify that an account is selected then pass the result back $sql="SELECT * FROM users WHERE newreg='1'"; $result = mysql_query($sql); $count = mysql_num_rows($result); echo "<form name=\"selectUser\" method=\"get\" action=\"admin.php\" target=\"adminCP\" onSubmit=\"return Validate();\">"; echo "<select name=\"newuser\">"; echo "<option value=\"Select User\" selected=\"selected\">Select User</option>"; while($row = mysql_fetch_array($result)) { echo "<option value=\"" . $row['username'] . "\">" . $row['username'] . "</option>"; } echo "</select>"; echo "<input name=\"mode\" type=\"hidden\" id=\"mode\" value=\"new\">"; echo "<input name=\"submit\" type=\"submit\" value=\"Submit\">"; echo "</form>"; break; case "modify": //Load the names of all account into a form, verify that an account is selected then pass the result back $sql="SELECT * FROM users"; $result = mysql_query($sql); $count = mysql_num_rows($result); echo "<form name=\"selectUser\" method=\"get\" action=\"admin.php\" target=\"adminCP\" onSubmit=\"return Validate();\">"; echo "<select name=\"newuser\">"; echo "<option value=\"Select User\" selected=\"selected\">Select User</option>"; while($row = mysql_fetch_array($result)) { echo "<option value=\"" . $row['username'] . "\">" . $row['username'] . "</option>"; } echo "</select>"; echo "<input name=\"mode\" type=\"hidden\" id=\"mode\" value=\"modify\">"; echo "<input name=\"submit\" type=\"submit\" value=\"Submit\">"; echo "</form>"; break; default: echo "ERROR: No mode selected. Please go back and try again. If you see keep getting this error message please "; echo "<a href=\"mailto:admin@fearless-bandits.co.cc\">contact the administrator</a><br>"; echo "<a href=\"JavaScript:window.close()\">Close</a>"; break; } mysql_close($con); ?> <script language = "Javascript"> //Validation of form. Makes sure that a user has been selected. function Validate() { if (document.selectUser.account.value == 'Select User') { alert('Please select a user before submitting.'); return false; } return true; } </script> </body> </html> Everything I've read says I can only close that popup with Javascript, and I can have it close as soon as the page loads, but I just don't know how. If there's a way to do it in php I'd be happy to learn.
-
Ah, sorry. I have an admin control panel. This part is for finding newly registered users, selecting a user and then dealing with it. The code I have is: case "new": echo "<a href=\"admin.php?mode=0\">Back</a><br>"; //Initiate variables $newuser = NULL; $newuid = NULL; $newapi = NULL; $newmember = 0; $sql = "SELECT * FROM users WHERE newreg='1'"; $result = mysql_query($sql); $count = mysql_num_rows($result); $row = mysql_fetch_array($result); //Check for new accounts if one hasn't already been selected if(!isset($_GET['newuser'])) { if($count == 1) { $newuser = $row['username']; header("location:admin.php?mode=new&newuser=$newuser"); } elseif($count > 1) { echo "There is more than 1 new user:<br>"; echo "<a href=\"select_user.php?mode=new\" onclick=\"return popup('select_user.php?mode=new')\">Select User</a><br>"; //Open popup } else echo "There are no new users.<br>"; } //Else get details for account and display in a form else { closeWindow(); //Close popup - LINE 93 $newuser = $_GET['newuser']; $sql = "SELECT * FROM users WHERE username='$newuser'"; $newuid = $row['uid']; $newapi = $row['api']; $newmember = $row['member']; echo "<form name=\"newApplication\" method=\"post\" action=\"verify_admin.php?form=new\">"; echo "Username: " . $newuser . "<br>"; echo "UID: " . $newuid . "<br>"; echo "API: " . $newapi . "<br>"; echo "Member: "; if($newmember == 0) echo "<input name=\"newmember\" type=\"checkbox\" id=\"newmember\" value=\"1\"><br>"; else echo "<input name=\"newmember\" type=\"checkbox\" id=\"newmember\" checked=\"checked\" value=\"1\"><br>"; echo "<input name=\"newuser\" type=\"hidden\" id=\"newuser\" value=\"" . $newuser . "\">"; echo "<input name=\"submit\" type=\"submit\" value=\"Submit\"><br>"; echo "Note: Upon submission the \"new account\" flag will be removed."; echo "</form>"; } break;
-
Line 93 is literally: closeWindow();