PHP - How To Create Ranking And Order Mysql Table
Hello
I have a mysql table like this:
id | user | car
1 | 1 | fiat 500 2 | 2 | vw polo 3 | 2 | vw golf 4 | 3 | renault clio 5 | 2 | fiat panda 6 | 3 | seat ibiza From this table how can i get a query that the result be like: user 2 - 3 cars user 3 - 2 cars user 1 - 1 cars Thanks Similar TutorialsI would like to create something like foursquare badges. When ppl upload files, the most downloaded files will have a new badge, how do i create that?
Hi everyone. I'm very new into self learning programming. Presently I'm trying to develop a simple basic Robot that would only Place a Market Order every seconds and it will cancel the Order every followed seconds. Using the following library: It would place Trade Order at a ( Price = ex.com api * Binance api Aggregate Trades Price) I have already wrote the api to call for xe.com exchange rate with php <?php $auth = base64_encode("username:password"); $context = stream_context_create([ "http" => [ "header" => "Authorization: Basic $auth" ] ]); $homepage = file_get_contents("https://xecdapi.xe.com/v1/convert_from?to=NGN&amount=1.195", false, $context ); $json = json_decode($homepage, TRUE); foreach ($json as $k=>$to){ echo $k; // etc }; ?> And also for the Binance Aggregate Price in JavaScript
<script> var burl = "https://api3.binance.com"; var query = '/api/v3/aggTrades'; query += '?symbol=BTCUSDT'; var url = burl + query; var ourRequest = new XMLHttpRequest(); ourRequest.open('GET',url,true); ourRequest.onload = function(){ console.log(ourRequest.responseText); } ourRequest.send(); </script>
My problem is how to handle these two api responds and also the functions to use them to place a trade and cancel it. This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=321906.0 Hi, I'm a researcher (and complete coding noob), and am planning a longitudinal study that requires e-mail follow-up with subjects taking an initial survey. For purposes of ethics/anonymity due to sensitive survey data, I'd like the acquired e-mails to be saved uncoupled from the survey responses; this is simple to deal with, and I use a basic PHP e-mail form, which injects the email address in a table in MySQL in a different server than the one used for the survey. The issue is that the e-mails are saved in the MySQL database in order of injection, thus it is still theoretically possible for me to link the e-mails back to the survey responses (which have a time stamp that I cannot remove). Ideally I would like not to be able (at all) to link the e-mails to the survey responses, and one way to do that (since I don't save the e-mail injection timestamps in MySQL) might be to have the e-mails saved in MySQL in a random order. Not sure if this is possible, and not even sure if this would be via PHP or MySQL side of things. The server is on godaddy and uses Starfield interface for MySQL but I cannot find an option for random insert/saving of table items (emails). They are saved in order of injection. Any solution for this? Thanks, Hey guys and girls, Okay so am trying to provide a rank for each user within my database but I cant seem to get it working here is my code Code: [Select] SELECT `Table`.`Id`, `Table`.`Photo`, `Table`.`Fname`, `Table`.`Lname`, `Table`.`Gender`, `Table`.`Gd`, `Table`.`Bd`, `Table`.`Point`, (SELECT COUNT(*) + 1 FROM (SELECT U.Id, T.`User Id` FROM `u_account` U LEFT JOIN `score_system` T ON `T`.`User Id` = `U`.`Id`) x WHERE Table.Point > (SELECT SUM(Good)-SUM(Bad) FROM `score_system` GROUP BY `User Id`) ) AS RANK FROM (SELECT `C`.`Id`, `C`.`Photo`, `C`.`Fname`, `C`.`Lname`, `C`.`Gender`, CASE WHEN COALESCE( SUM(`S`.`Good`), '') = '' THEN '0' ELSE SUM(`S`.`Good`) END AS Gd, CASE WHEN COALESCE( SUM(`S`.`Bad`), '') = '' THEN '0' ELSE SUM(`S`.`Bad`) END AS Bd, CASE WHEN COALESCE( SUM(`S`.`Good` - `S`.`Bad`), '') = '' THEN '0' ELSE SUM(`S`.`Good` - `S`.`Bad`) END AS Point FROM `u_account` AS `C` LEFT JOIN `score_system` AS `S` ON `C`.`Id` = `S`.`Child Id` AND (SELECT Start FROM event_schedule WHERE CURDATE() >= Start AND End >= CURDATE()) < `S`.`Date` AND (SELECT End FROM event_schedule WHERE CURDATE() >= Start AND End >= CURDATE()) > `S`.`Date` GROUP BY `C`.`Id` ) AS `Table` ORDER BY Point DESC, Fname ASC I cant seem to pull the users rank from this and its donig my head in I've tried different things and they all dont work this is perhaps as close as I've got to figuring it out. This is the part that creates the users rank now its saying the Subquery returns more than 1 row but I just cant seem to think of away to implement this into my query above so that it displays the rank for each user. Code: [Select] (SELECT COUNT(*) + 1 FROM (SELECT U.Id, T.`User Id` FROM `u_account` U LEFT JOIN `score_system` T ON `T`.`User Id` = `U`.`Id`) x WHERE Table.Point >= (SELECT SUM(Good - Bad) FROM `score_system` GROUP BY `User Id`) ) AS RANK I'm also looking for this to display the same rank for both users with the same points so If bill and ben have 200points then they would both have the same rank but if bill was to have 201points then he would be higher up than ben. So can anyone lend me a hand. Thanks in advance What I mean by dynamic is say I created a function to generate a random code. I put it in a variable named $key. I make a form with a hidden input type with the name and value of $key. When the form posts, it generates the table name to whatever $key is. Because I tried something like this & its not querying. Heres my code: <?php $dbc = mysqli_connect('localhost', 'cpacrop_todo', 'pass', 'cpacrop_todo') or die('Failed to connect to database!'); function make_key($num_chars) { if ((is_numeric($num_chars)) && ($num_chars > 0) && (! is_null($num_chars))) { $key = ''; $accepted_chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'; //seed srand(((int)((double)microtime()*1000003)) ); for ($i=0; $i<=$num_chars; $i++) { $random_number = rand(0, (strlen($accepted_chars) -1)); $key .= $accepted_chars[$random_number] ; } return $key; } } $key = make_key(6); ?> <form action="" method="post"> <input type="hidden" name="<?php echo "$key"; ?>" /> <input type="submit" name="submit" value="Submit" /> </form> <?php if ($_POST['submit'] == "Submit") { $query = "CREATE TABLE `$key` ( `id` INT AUTO_INCREMENT, `title` VARCHAR(35), `description` VARCHAR(365) );"; mysqli_query($dbc,$query) or die('Unable to query database.'); echo "Success"; } ?> If this is possible, what am I doing wrong? Thanks! Hey yall! I'm working on a new site idea and I've run across a problem that I know is simple enough but I'm stumped. It's in the signup form What I want to do is insert the new user into the 'Login' table and get the user id that was just created and use that to create a table with the user id in the name. Here is what I have: // now we insert user into 'Login' table mysql_real_escape_string($insert = "INSERT INTO `Login` (`UID`, `pass`, `HR`, `mail`, `FullName`) VALUES ('{$_POST['username']}', '{$_POST['pass']}', '{$_POST['pass2']}', '{$_POST['e-mail']}', '{$_POST['FullName']}')"); mysql_query($insert) or die( 'Query string: ' . $insert . '<br />Produced an error: ' . mysql_error() . '<br />' ); $error="Thank you, you have been registered."; setcookie('Errors', $error, time()+20); // Get user ID mysql_real_escape_string($checkID = "SELECT * FROM Login WHERE `mail` = '{$_POST['e-mail']}'"); while ($checkIDdata = mysql_fetch_assoc($checkID)) { $userID = $checkIDdata; // now we create table 'Transactions" for the user mysql_real_escape_string($create = "CREATE TABLE `financewatsonn`.`Transactions_{$userID}` ( `ID` INT( 20 ) NOT NULL AUTO_INCREMENT COMMENT 'Transaction ID', `name` VARCHAR( 50 ) NOT NULL COMMENT 'Name/Location', `amount` VARCHAR( 50 ) NOT NULL COMMENT 'Amount', `date` VARCHAR( 50 ) NOT NULL COMMENT 'Date', `category` VARCHAR( 50 ) DEFAULT NULL COMMENT 'Category', `delete` INT( 1 ) NOT NULL DEFAULT '0', UNIQUE KEY `ID` ( `ID` ) ) ENGINE = MYISAM DEFAULT CHARSET = utf8 COMMENT = 'User ID {$userID}'"); mysql_query($create) or die( 'Query string: ' . $create . '<br />Produced an error: ' . mysql_error() . '<br />' ); } I know in 'Get user ID' that I need to get the ID but I'm not sure how to get that information. i get the error Quote Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource at 166 which is the while line under Get user ID How would I create a prepared mysql temp table using PHP? I currently write my prepared statements like the example below. How would I create a "TEMP" table? Thanks!
$connection8y = new mysqli("host", "xxx", "xxx", "db"); Hi ppl, I am not an php expert, but I want to allow my website users to edit a record in mySQL table. I need to allow them changing Name and description of a product, thats all. easy edit. Is there a ready component that will do the hard work for me? Thank you! I've got. Lets say I have this query: $sql = mysql_query("SELECT * FROM Member ORDER BY posts DESC LIMIT 10"); while ($get = mysql_fetch_array($sql)){ $row .= $get['id']; $posts .= $get['posts']; echo "$row - $posts<br />"; } Lets say I have two of rows, with posts fields of 84 and 803. When it displays it, it grabs the 84 row first, when I want the bigger number 803 first. Is there a way to fix this? I'm currently trying to grab data from my database for my chatbox, which when displayed, displays in an ascending order, when I call it to descend, it shows the messages ONCE in descending order, then just repeats but in random order.. Code: [Select] $sql = "SELECT * FROM `message` WHERE `chat_id` = 1 AND `message_id` > $last ORDER BY `message_id` DESC"; Database: message_id | name 1 RSX 2 RSX 3 RSX 4 RSX Code: [Select] RSX: 4 RSX: 3 RSX: 2 RSX: 1 RSX: 4 RSX: 3 RSX: 2 RSX: 4 RSX: 3 RSX: 4 It is ordering it correctly, just repeats, I'm using Ajax, could that be the problem, or is it within the PHP code? Edit: I read it wrong, it displays as shown under "output". When you make a mysql query the results are always returned with the first being the first entry in the database. I was wondering if there is a way to make it so that the last entry is returned first and so on? Thanks for any help. ok so i want to order by high to low on the field price but i don't know how to do this. i can order low to high by using ORDER BY `Price` ASC but how can i order high to low? hello all. I have a list of records, which each have a comment button, just like any forum does. when I click on the comment button it brings up the current record at the top, and a blank form, to which you enter in information. When I submit this information, I want it to show up on the main page as a child of the parent record. I want it similar to the example I've shown below: Code: [Select] id name dob address email username 1 john smith 10/11/1986 124 Peermont Drive john.smith@yahoo.com john smith1 >> 2 Harry 15/12/1985 98 The Roundhay harry@gmail.com harry23 >>> 3 jhk 08/11/1976 65 dfgdfg gfdfg@ yahoo.com jhk345 4 john smith 10/11/1986 124 Peermont Drive john.smith@yahoo.com john smith1 >> 5 Harry 15/12/1985 98 The Roundhay harry@gmail.com harry23 >>>> 6 jhk 08/11/1976 65 dfgdfg gfdfg@ yahoo.com jhk345 I've been stuck on this for hours, and I haven't got anywhere. Any ideas? Hello, I would like to order by date that contains day and month, like this: 14-3 Is this possible? Quote $sql = mysql_query("SELECT * FROM date WHERE online='1'"); This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=347726.0 by the order in which they were entered?
like i dont want to order by a specific row in my table, i want to list the data by which it was entered.
maybe i can add a row that enters column #s somehow??
This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=349226.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=320026.0 |