PHP - Get Users From Db In Alphabetical Order
I have a string which is a list of user id's like "44/5/6/67/7/88/56/76/9/90/65/74/8/68". I explode this string and put them into an array, but now I have a problem of getting the users first names from the database by using the id's and putting them in alphabetical order. How can I do this?
Thanks Similar TutorialsI'm pulling a list from a DB and inserting it in a drop down menu. Each item on the list has a numerical id associated called marketid in the DB. It works, but it orders the list alphabetically. I need it to order by marketid which is the column name. What code do I need to add? Here is what I have now.... <option value="<?=$market['marketid']?>"><?=$market['name']?></option> Thanks in advance all!! Tony How do I present these documentaries like this:
0-9
10 Things You Need to Know About Sleep
20 Animals That Will Kill You
A
Ant Kingdom
Atkins Diet
B
Battle of the Brains
Body Talk
I don't even know where to start!
I'm not asking anyone to do this for me; I just need a push in the right direction.
Any help will be appreciated.
This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=309973.0 The following code is what I have already done, but I have just realised that the way I have done this will not enable me to display the online users in alphabetical order, I do not know a way how to do this. Any help or suggestions? Thanks $friend_query = mysql_query("SELECT * FROM friend_request WHERE user='{$user_id}'"); $friend_id_array = ""; while($row = mysql_fetch_assoc($friend_query)) { $friend_id = $row['friend_id']; $more_query = mysql_query("SELECT * FROM friend_request WHERE friend_id='{$user_id}'"); while($row_more = mysql_fetch_assoc($more_query)) { $more_friend_id = $row_more['user']; //all friends in an array $friend_id_array = $friend_id_array.$friend_id."/".$more_friend_id; $friend_id_array = explode('/', $friend_id_array); $friend_count = count($friend_id_array); //how many of the friends are online $online_count = 0; for($i=0;$i<$friend_count;$i++) { $query_online = mysql_query("SELECT loggedin, fname, mname, lname FROM users WHERE id='{$friend_id_array[$i]}'"); //get loggedin and names $row = mysql_fetch_assoc($query_online); $loggedin = $row['loggedin']; if($loggedin == "1") //if logged in { $online_count++; // final number off people online } } } } This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=356016.0 Hi all! I'm stuck in the midst of some code. In it I have an if function which operates based on whether a variable (a word) is the same as another variable. Here is my code: Code: [Select] <? $var1 = "chicago"; if($table_name === $var1){ $result = mysql_query("SELECT * FROM another_table WHERE username='$usernamee'"); while($row = mysql_fetch_array($result) ) { $var2 = $row['var2']; $var2_new = $var2 * 2; mysql_query("UPDATE another_table SET var2 = '$var2_new' WHERE username = '$usernamee'"); } } ?>I tried using =, == and ===, but did not get any of the results I expected. Could anyone advice me on the situation? Thanks in advance. Regards, Thauwa Hello
I am trying to work out how many regular users I have to my site and how long those users tend to be users..
So, I have a table that logs every time a user visits my site and logs in, it stores the date / time as a unix timestamp and it logs their user id.
I started by getting the id's of any user who logs in more than 5 times in a specified period, but now I want to extend that...
SELECT userID as user, count(userID) as logins FROM login_history where timestamp > UNIX_TIMESTAMP('2014-06-01 00:00:00') and timestamp < UNIX_TIMESTAMP('2014-07-01 00:00:00') group by user having logins > 5;
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. I just discovered that I have a major security flaw with my website. Anyone who logs in to the website can easily access other users information as well as delete and edit other users information just by changing the ID variable in the address bar. I have user ID Session started on these pages but still people can do anything they like with other users information just by editing the address bar. For example if your logged in in the address bar of www.mywebsite.com/delete_mystuff.php?id=5 and change the "5" say to a "9" then you will have access to user#9 information. Every important page that I have has this code: Code: [Select] session_start(); if (!isset($_SESSION['user_id'])) { // Start defining the URL. $url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']); // Check for a trailing slash. if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\') ) { $url = substr ($url, 0, -1); // Chop off the slash. } // Add the page. $url .= '/index.php'; ob_end_clean(); // Delete the buffer. header("Location: $url"); exit(); // Quit the script. } else { //Else If Logged In Run The Script if((isset($_GET['id'])) && (is_numeric($_GET['id']))) { $id = (int) $_GET['id']; } elseif ((isset($_POST['id'])) && (is_numeric($_POST['id']))) { $id = (int) $_POST['id']; } else { echo ' No valid ID found, passed in url or form element'; exit(); } What am I doing wrong? Please help if you know how to correct this. Many thanks in advance. I've got. im new , and ... i hate tutorials .. books .. anything that does not make u part of the deal - .. thats why i started by creating something and learning from my mistakes at the same time .. i like this way of learning .. soo , while im building and trying things out .. i started thinking how the server know the person with this link is really U ? .. when u start just linking pages to each other its just a matter of finding out what is the link to do what ever u want with the users personal pages ! .. i know my questions r stupid but i just hate to go and write lessons without any effort im confused with the concept of SESSIONS and COOKIES , r they the unswer to this security problem ? how u can work with them .. ? im not asking for codes .. just general ideas about users and how they control their profiles and stuff with full security ? ill be very thankful if i get any answer ^^ I have used
$sql = "SELECT id, username FROM $tbl_name ORDER BY username"; $result = $con->query($sql); while ($row = $result->fetch_assoc()) { echo "<a href='editUser.php?id={$row['id']}'>{$row['username']}</a><br><br>\n"; echo "<style>a {color: blue; text-decoration: none;} a:hover {color: #ff0000} body {background-color: #000;} </style>"; }in euser.php which echo's out all the users in the database via an anchor tag and includes their id in the url. but when i click on their name i want to have options like: - change password - ban user e.t.c and i have tried $sql = "SELECT id FROM $tbl_name"; $result = $con->query($sql); while ($row = $result->fetch_assoc()) { echo "<a href='editUser.php?id={$row['id']}'> Change Password </a>in my other page editUser.php it posts Change Password Change Password Change Password and each change password has the 3 ids of the users this is confusing me. I would get the ip address of the user that is on the site. I used $ip = $_SERVER['REMOTE_ADDR']; and it doesn't show my actual ip. Is it because im using an apache server on my computer. Hi. my browser ist telling me there are errors on line 3 and 4 for my code. It says summin like Notice: HTTP_CLIENT_IP and HTTP_X_FORWARDED_FOR are unidentified: below is the code see if you can spot anything btw i copied down the code from beginner php tutorial 66 if you type that into youtube . Code: [Select] <?php $http_client_ip = $_SERVER['HTTP_CLIENT_IP']; $http_x_forwarded_for = $_SERVER['HTTP_X_FORWARDED_FOR']; $remote_addr = $_SERVER['REMOTE_ADDR']; if (!empty($http_client_ip)){ $ip_addr = $http_client_ip; }else if(!empty($http_x_forwarded_for)){ $ip_addr = $http_x_forwarded_for; }else{ $ip_addr = $remote_addr; } echo $ip_addr; ?> Thanks MOD EDIT: code tags added. how can I list a user from a table and show the results in a grid with different color eg frist in blue color second on white , 3rd on blue 4th in with etc
I do need to set select command and I have db name and ip on a file called dbconfig.php from wd calendar so I just need to read the info
ps: I cant post links so search for wd calendar and see the dbconfig.php in php folder
Hi guys, I am trying to get a admin panel, which when the user is logged in, it will check if there user access is(say for this post) 9... If there access is 9 in the database then direct to admin panel if not return them home. Thanks guys Hi, I am having serious issues with compatibility with IE7 and below (and even 8 but they should be rectified). There is no way I can have these problems finished before the site is online, so I want to redirect users to a page apologizing and recommending alternative browsers. Is this possible? *Please don't reply just to tell me that banning an entire browser is bad, I know it is - I plan to sort it out. But this is an extra curricular project and I'm halfway through my penultimate year of uni, so IE and it's utterly shambolic rendering of CSS is not my priority. Thankyou* Hi guys, im just trying to work out an app in my head and on paper. im just wondering.. when a user registers they can choose an Avatar 100px by 100px jpg, when they upload one would i then grab the file and store all Avatars in a avatar image folder and rename it to something like.. avatar[user_id].jpg and keep them all in the same folder. or would i crate a folder called users, each user gets their own folder with files like avatar.jpg and it finds the [user_id] folder and pulls the avatar out from that, or is there a more prefered method? cheers Hi I am creating an e-commerce website, where users who pay with their credit card are able to download pdf books. how can I make a PDF file only accessible for those users (who pay and validate their credit card) and not for everyone ? I want to know the main idea about securing these files. Hey sup guys i need help Implementing top 10 users script into index.php. I got a screen shot of where it needs to go. I need to Implement it so its inside the grey container as in the picture. Here is the php for the top 10 users : Code: [Select] <span style="float:right;"> <table width="200"> <tr><td colspan="2" align="center">TOP 10 USERS</td></tr> <tr><td align="left"><b>Username<b></td><td align="left"><b>Points</b></td></tr> <?php $i=0; if($num>0){ while ($i < $num) { $username6=mysql_result($result4,$i,"username"); $points6=mysql_result($result4,$i,"points"); $i++; echo "<tr><td>".$username6."</td><td>".$points6."</td></tr>"; Here is the image file for the graphic : Code: [Select] <table width="165" height="236" bgcolor="#FFFFFF" td background="images/tablebg.png" > And here is the index.php : Code: [Select] <? session_start(); include_once"config.php"; if(isset($_POST['login'])){ $username= trim($_POST['username']); $password = trim($_POST['password']); if($username == NULL OR $password == NULL){ $final_report.="Please complete both fields"; }else{ $check_user_data = mysql_query("SELECT * FROM `members` WHERE `username` = '$username'") or die(mysql_error()); if(mysql_num_rows($check_user_data) == 0){ $final_report.="This username does not exist"; }else{ $get_user_data = mysql_fetch_array($check_user_data); if($get_user_data['password'] == $password){ $start_idsess = $_SESSION['username'] = "".$get_user_data['username'].""; $start_passsess = $_SESSION['password'] = "".$get_user_data['password'].""; $final_report.="<meta http-equiv='Refresh' content='0; URL=members.php'/>"; }}}} if(isset($_SESSION['username']) && isset($_SESSION['password'])){ header("Location: members.php"); } ?> <?php include("includes.php");?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title><?php echo $title ?> | #1 Spot for Free Paid Surveys</title> <link rel="shortcut icon" href="favicon.ico" > <link rel="icon" type="image/gif" href="animated_favicon1.gif" > <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <meta name="description" content="Get free vouchers for online stores such as Amazon, ASOS, iTunes and more. It takes a few seconds to get started. Register now to start shopping for free." /> <link rel="stylesheet" href="style.css" type="text/css" /> <script type="text/javascript" src="js/jquery-1.4.2.min.js"></script> <script type="text/javascript" src="js/script.js"></script> <script type="text/javascript" src="js/dimensions.min.js"></script> <script type="text/javascript" src="js/func.js"></script> <script type="text/javascript" src="js/SHA1.js"></script> <script>var _wau = _wau || []; _wau.push(["tab", "72vlo7dmnb8j", "w12", "bottom-center"]);(function() { var s=document.createElement("script"); s.async=true; document.getElementsByTagName("head")[0].appendChild(s);})();</script> <style> #logoPart { background:#000; height:90px;} #bannerTD { width:900px; height:85px; background-color:#333; background-repeat: no-repeat;} #bannerTD #bannerContainer { width:900px; height:325px; text-align:center;} #bannerTD #bannerContainerCover { width:900px; height:325px; text-align:center;} #bannerTD #bannerBody { height:245px; text-align:center;} #bannerTD #bannerFooter { position: relative; background:#000; height:80px; display:none; width:900px; top: -39px; /* 1x the distance of the footer used to be 78 */ } #bannerTD #bannerFooterNav { position: relative; border: 1px solid grey; top: -117px; /* 2x the distance of the footer used to be 156*/ } .footerCell{ padding:5px; text-align:left; border:0px #F90 solid;} .footerCell .footerTitle {font-family:tahoma, arial; font-size:11px; color:#fff; font-weight: bold;} .footerCell .footerDesc {font-family:tahoma, arial; font-size:11px; color:#efefef;} .footerCell ul {list-style: none; margin: 2px; margin-left: 75px; padding-left: 10px;} .footerCell ul li {margin: 2px; line-height: 13px; padding: 0;} .footerLink {text-align: right;} .footerCell .imgDiv{ position:relative; float:left; width:80px; height:65px; margin: 2px 1px 0px 1px;} .bttnMore {width:57px; height:19px; float: right;} .bttnMore a{display: block; background:url(images/welcome-banner/gen/bttn_more_small.png) 0 0 no-repeat; line-height: 19px; text-decoration: none;} .imgBgDiv_i { width:82px; height:67px; //background: url(images/welcome-banner/gen/thumbBgBordered.png) 0 0 no-repeat; padding: 0; float:left; } </style> </head> <body> <body id="exterior"> <div id="body-bg"> </div> <div id="container"> <div id="header"> <a href="index.php<?php echo $referral_string?>"> <div id="logo"> </div></a><!--end of logo--> <div id="updates"> <span> </span> </div><!--end of updates--> <div id="login"> <div id="loginwelcome"> <?php if(!isset($_SESSION['username']) || !isset($_SESSION['password'])){ ?> <?php if($final_report !=""){?> <font color="red"><? echo $final_report;?></font> <?php }else { ?>Welcome Guest, not a member? <a href="register.php<?php echo $referral_string?>"><b>Register Now!</b></a> <?php } ?> </div><!--end of loginwelcome--> <form action="" method="post"> <p> <input type="text" title="username" name="username" class="username" value="Username" onclick="if ( value == 'Username' ) { value = ''; }"/> <input name="password" type="password" class="password" title="password" value="Password" onclick="if ( value == 'Password' ) { value = ''; }"/> <input type="Submit" name="login" class="submit" value="login" tabindex="3" /> </p> </form> </div><!--end of login--> <?php } ?> <?php if(isset($_SESSION['username']) && isset($_SESSION['password'])){ ?> <table> <tr> <td> Welcome <b><?php echo $membername ?></b> </td> </tr> <tr> <td align="right" width="310"> Total Points: <b><?php echo $memberpoints ?></b><br> <?php if ($pointsneeded<=0){ ?> You can now request a reward!<?php }else { ?> Points Needed: <b><?php echo $pointsneeded ?> <?php } ?> </b><br> </td> </tr> </table> </div> <!--end of header--> <?php } ?> <div id="navigation"> <?php if(isset($_SESSION['username']) && isset($_SESSION['password'])){ ?> <table id="navi-items"> <tr><td> <div class="navi-item navi-item-selected"> <div class="navi-heading navi-heading-selected"> <a href="index.php"><img src="images/home.png" alt="Home" /></a> </div> </div> <div class="navi-spacer"></div> <div class="navi-item"> <div class="navi-heading"> <a href="vouchers.php"><img src="images/rewards.png" alt="Rewards" /></a> </div> </div> <div class="navi-spacer"></div> <div class="navi-item"> <div class="navi-heading"> <a href="testimonials.php"><img src="images/testimonials.png" alt="Testimonials" /></a> </div> </div> <div class="navi-spacer"></div> <div class="navi-item"> <div class="navi-heading"> <a href="terms.php"><img src="images/terms.png" alt="Terms" /></a> </div> </div> <div class="navi-spacer"></div> <div class="navi-item"> <div class="navi-heading"> <a href="help.php"><img src="images/help.png" alt="Help" /></a> </div> </div> <div class="navi-spacer"></div> <div class="navi-item"> <div class="navi-heading"> <a href="contact.php"><img src="images/contact-us.png" alt="Contact Us" /></a> </div> </div> </td></tr> </table> <?php }else { ?> <table id="navi-items"> <tr><td> <div class="navi-item navi-item-selected"> <div class="navi-heading navi-heading-selected"> <a href="index.php"><img src="images/home.png" alt="Home" /></a> </div> </div> <div class="navi-spacer"></div> <div class="navi-item"> <div class="navi-heading"> <a href="vouchers.php"><img src="images/rewards.png" alt="Rewards" /></a> </div> </div> <div class="navi-spacer"></div> <div class="navi-item"> <div class="navi-heading"> <a href="testimonials.php"><img src="images/testimonials.png" alt="Testimonials" /></a> </div> </div> <div class="navi-spacer"></div> <div class="navi-item"> <div class="navi-heading"> <a href="terms.php"><img src="images/terms.png" alt="Terms" /></a> </div> </div> <div class="navi-spacer"></div> <div class="navi-item"> <div class="navi-heading"> <a href="help.php"><img src="images/help.png" alt="Help" /></a> </div> </div> <div class="navi-spacer"></div> <div class="navi-item"> <div class="navi-heading"> <a href="contact.php"><img src="images/contact-us.png" alt="Contact Us" /></a> </div> </div> </td></tr> </table> <?php } ?> </div><!--end of navigation--> <!-- ______________________ BANNER ___________________--> <tr><td id="bannerTD"> <div id="bannerContainer"> <div id="bannerBody"> <br /><img src="images/banner.png" border="0" alt="Banner" /> </div> </div> <a href="register.php"><img src="images/signup.png" /></a> <a href="points.php"><img src="images/earn.png" /></a> <a href="vouchers.php"><img src="images/get.png" /></a> </td></tr> <!-- ______________________ /BANNER ___________________--> <div id="contents-top"></div> <div id="contents"> <div class="content-block"> <h1>How does <?php echo $title?> work?</h1><br><br> <a href="register.php<?php echo $referral_string?>"><center><img src="images/step1.png" border="0"><img src="images/step1a.png" border="0"></a><a href="points.php<?php echo $referral_string?>"><img src="images/step2.png" border="0"><img src="images/step2a.png" border="0"><a href="vouchers.php<?php echo $referral_string?>"><img src="images/step3.png" border="0"></center></a> <br> <br> <p> It's easy to use your free time to earn <a href="vouchers.php<?php echo $referral_string?>"><b>rewards</b></a>. While you certainly won't get rich quick or instantly win prizes, if you put in a bit of effort you can earn whatever you want! You can redeem points for online goods or for vouchers such as Amazon, iTunes, ASOS and Xbox Live, the choice is yours. <br><br> While you learn about new products, share information about yourself, or sign up for online services, you earn points. While MOST OFFERS ARE FREE, you will also find cashback shopping and paid/trial offers - a great way to get a deal on your online purchases! <br><br> </p> <h1>Just 3 steps to success!</h1> <p><br> 1. <b>Register:</b> The sign up process takes about 10 seconds, and we'll even give you <font color=#fcbc0c><b><?php echo $bonuspoints ?> FREE BONUS POINTS</b></font> when you <a href="register.php<?php echo $referral_string?>"><b>register</b></a>.<br><br> 2. <b>Earn points:</b> To be able to offer our users FREE gift vouchers to use at online stores such as Amazon and ASOS, you need to earn points. Earning these points are FREE, and you just need to complete a few surveys to get enough points to claim a free voucher. You can also earn points by signing up to some trial offers, but we recommend you stick to the free surveys for now.<br><br> 3. <b>Get Rewards:</b> Once you have earned <?php echo $mainpointsneeded ?> points on <?php echo $title?> you can swap them for REAL products or vouchers, which can be used at online stores/communities. Basically, you can request ANY product or voucher, as long as we can buy it online and send to you via email or shipping. On top of this, if you wish to have something custom ordered, feel free to tell us something what it is and we can always help you out! The rewards you can receive are endless........ </p> <h1>What are points worth?</h1> <p> <br> 10 points = $1.00/£0.50<br> 50 points = $5.00/£2.50<br> 100 points = $10.00/£5.00<br> 200 points = $20.00/£10.00 <br><br> You need <?php echo $mainpointsneeded ?> points before you can redeem them for <a href="vouchers.php<?php echo $referral_string?>">rewards</a>. <br> </p> <h1>How do I know Simple Rewards is legit?</h1> <p>There's no doubt that in today's world fake companies are everywhere. So how do you know Simple Rewards is, in fact, legit? To start, Simple Rewards has already paid out over $10,000 in the last month. This shows not only that we are a legitimate business but also that we are a very active one. If you would like to see more proof of our legitimacy, feel free to check out our <a href="testimonials.php">Testimonials </a> section and read some of the latest testimonials written by Simple Rewards users! </p> <br /> <h1>Reward Ideas</h1> <p> <br /> <img src="images/ps3.png"> <img src="images/giftcards.png"> <img src="images/ipodtouch.png"> </p> <p><center> <p><a href="index.php"><img src="images/largebanner.gif" /><hr width="75%"> <script type=text/javascript language=JavaScript src=http://www.linkreferral.com/networkads2.pl?refid=341046&height=1&width=3&category=money making opportunities&subcategory=services ></script></a></p> </center></p> </div><!--end of contentblock--> </div><!--end of contents--> <div id="contents-bottom"></div> </div><!--end of container--> </div> <?php include("footer.php");?> |