
mediabob
Members-
Posts
40 -
Joined
-
Last visited
Profile Information
-
Gender
Not Telling
mediabob's Achievements

Member (2/5)
0
Reputation
-
Getting a users rank from a mysql table with PDO
mediabob replied to mediabob's topic in PHP Coding Help
That's a good point I didn't consider, thanks for getting me going in the right direction! -
Getting a users rank from a mysql table with PDO
mediabob replied to mediabob's topic in PHP Coding Help
So using your idea, I have done this, and it works exactly for what I want, is this the best recommended way? $stmt = $dbh->query("SELECT COUNT(uid) AS `rank` FROM $table WHERE score > ( SELECT score from $table WHERE uid = $uid )"); $result = $stmt->fetchColumn(); echo $result+1; -
Hi, I am trying to get the rank of a user in a database, based on his score, so when the user logs in he can see his rank. I am using this to build a list of all users ordered by their score for a different section. $stmt = $dbh->query("SELECT * FROM $table ORDER BY score DESC"); $rank = 0; while($uid = $stmt->fetchObject()) { $rank++; echo $uid->uname ."is ranked". $rank; }; How can I get ONLY a users rank in the db based on his ID number, if I have a table like, . | user | ID | score | Jim | 2568 | 80 Pete | 5693 | 115 Sam | 3258 | 569 George | 7412 | 30 the ID numbers are a unique key If Jim logs in today he will see: Your Current Rank is 3 I am using PHP with PDO on a MySQL table. Thanks!
-
The query is returning all 80 rows, if I remove the DIV and just display the table it shows up correctly. But with the DIV in place to hide it, once you show it you only get the first row of the table. As I a said above, if I include the show/hide link IN the loop, then I will get 80 empty rows with the show/hide link 80 times, and I can click each individual link and get the correct row of information.
-
Hi, thank you for your quick response. You are correct the DIV does show and hide correctly. The problem lies within the dynamic table inside the DIV. When you "show" the DIV, the table might have 80 records, but you only get the first one. The table is created with a while loop, here is a trimmed down sample of it... <table width="100%" border="1" cellpadding="2"> <tr> <td>User Name</td> <td>Real Name</td> <td>Location</td> <td>Registered Date</td> </tr> <?php do { echo' <tr> <td>' .$row_info['uname']. '</td> <td>' .$row_info['realname']. '</td> <td>' .$row_info['memloc']. '</td> <td>' .$row_info['regdate']. '</td> </tr>'; } while ($row_info = mysql_fetch_assoc($info)); ?> </table>
-
Hi, I am trying to build a page that has a table inside a collapsible div. The table is dynamic, in that it is populated from a MySQL database. Now, the problem I have is that when I expand the table, I only get the very first row from the database. I know that they all need a unique ID so I am using the record ID from the db to dynamically assign each row a unique number, but it still does not work, I just get the first row. (They are all pulled, the div just does not show them all. ) So I played around a bit and moved the code inside the repeat region for the table, this was halfway there, except now I get a "show" link for EVERY row of the table and I have to click each one individually to show it's corresponding data. So I am at a loss. I am trying to make it so clicking one link at the top reveals the entire table, but it's just not working, so any help would be greatly appreciated. Here is what I am using so far... Javascript that handles show/hide part <script language="javascript"> function toggleDiv(divid){ if(document.getElementById(divid).style.display == 'none'){ document.getElementById(divid).style.display = ''; }else{ document.getElementById(divid).style.display = 'none'; } } </script> The link Im using to show/hide the table <a href="javascript:;" onmousedown="toggleDiv('t<?php echo $row_info['memID'] ?>);">Show/Hide</a> DIV <div id="t<?php echo $row_info['memID'] ?>" style="display:none"> [table here] </div> Any help would be greatly appreciated... thanks in advance!
-
Thanks Ken, that was the solution I needed. Sometimes the most obvious solutions evade us
-
Hi, I am writing an application that tracks productivity in units per hour, so much of it involves working with time. So basically the person enters a start time, an end time, and there is a field to account for time not on the project (breaks, lunch, etc). Basically they way I have done it, to make it simple, is that in the form real times are entered and stored in the database (in 24 hour format). So, to calculate the units per hour, it pulls the time from the database, converts it to minutes, and works this calculation: $result = (($end_time - $start_time) - $breaks);// to get the total minutes on the project, (by this time is has been converted to minutes) $fuph = (($uph / $result) * 60); //and divide the units worked by the minutes worked on them and multiply by 60 OK, this works great except for one thing... when the shift crosses midnight.... One shift is 8pm - 8am, so say a project starts at 11:33PM (23:33) and runs until 1:15AM (01:15), it fouls up the calculation. I know I need to take one more step here to account for that... but at this point i'm lacking on sleep and can't wrap my head around it... so some help would be appreciated. Thanks!
-
that was dumb... thanks
-
Hi, I am working on a date system like facebook where instead of a date and time something was posted it shows like, 45 minutes ago, or 3 hours ago... that sort of thing and I have it working except for one small issue. To start off I have function post_time ($session_time) { $db_date = $row_post_list['pdate']; $calc_time = time() - $db_date; the $db_date should be date/time as pulled from the database, but it does not seem to work. if I replace the $row_post_list['pdate'] with an actual date/time like this: function post_time ($session_time) { $db_date = 1266048067; $calc_time = time() - $db_date; The whole thing works flawlessly, so I am not sure what I am doing wrong here. All the rest of the data on the page that comes from the db works great, it's just pulling that one thing that is throwing a wrench in.
-
I had to modify slightly but that worked, thanks Edit: What happed to the Solved button ???
-
forgot to add, I tried it with a single row and it worked, I just can't the loop to work to do all the records :-\
-
OK I tried that and get error Here is my code I tried $result = mysql_query("SELECT * FROM mydb",$db); $csvcontent = 'field1'."\t".'field2'."\t".'field3'."\n\r". while ($row = mysql_fetch_array($result)) { $csvcontent .= $row['field1']."\t".$row['field2']."\t".$row['field3']."\n\r". }
-
Hi, I am trying to query a db table and save the results to a tab delimited text file, but I can't seem to figure out how to do it ??? can anyone help me with this it should be saved to a folder on the server and be formatted like head head head row row row sort of like a spreadsheet Thanks
-
OK when I tried to print the query it told me there was no database selected, so I played with it and finally got this to work $query_countShows = "SELECT * FROM rating WHERE itemid = '$file_id' AND ruserid = '$name' AND rcat = '$catname'"; $countShows = mysql_query($query_countShows, $dload) or die(mysql_error()); $num_rows = mysql_num_rows($countShows); Thanks for your help guys!