PHP - How To Display X Amount Of Tables Rows Depending On Y Amount Of Info In A Query
Heres what i got...
function printLB1 (){ $result = mysql_query("SELECT * FROM leaderboards ORDER BY CollegeFootballPoints DESC"); while ($row = mysql_fetch_object($result)) { $leaderboard[] = $row->Username; $leaderboardPoints[] = $row->CollegeFootballPoints; } $num = mysql_num_rows($reault); //I know from here to ................... needs to be in a var or echo or something. <tr> <td>1.</td> //This will auto increment too like i++ but i cna do that myself! <td>echo $leaderboard;</td> <td>echo $leaderboardPoints;</td> </tr> //Here......................................................... } I need to pull a table row per user. But i want to somehow do it once in a function and then ill echo the function into a table after the php stuff is done. Like i want to pull every a table row per user in the function. then display the function below that way i don't have to write a whole extra query and table row per person. If you understand please help if not please let me know where i can explain more. Thanks Similar TutorialsMy code: Code: [Select] $rank = implode(',', $ibforums->input['rank']); echo $rank; For that form, it will show: '2,0,0' Problem is, I need to update each row with each individual value, and is this possible with using 1 query? Hi, I have a 'pre-release' sign up form, where people put in their email address and name, and it transmits to a MYSQL database. That's working fine. What I want to do is to have a piece of text that reads: (insert pre release amount of signer upperers here) have signed up. Will you? I'm guessing that the amount of rows on the table, would end up being the number. How do I do this? Thanks, Jack As I title says; I need to have an image showed the number of times, the value of a table/field.. How can I do this? I have a field in my database called description. How can I echo out only 500 out of the 2000 max characters? Like for example: Code: [Select] $query = mysql_query("SELECT description FROM `servers` ORDER BY votes DESC LIMIT 5"); If I were to echo out the value of description for the database, how can I only echo out the first 500 characters? Hi, i have a folder with thumbnails and original big pictures of the thumbnails, i wanna make it so that the max amount of thumbs that can be displayed on one page would be 3 Code: [Select] <body> <div id=head></div> <div id=main> <?php include("loadimages.php") ?> //<- here i take all the thumbnails that are in my thumb folder </div> <div id=foot></div> </body> i have 5 thumbnails, it displays all of them in the "main" div, i wanna add an "Next" and "Previous" buttons, i mean, i want it to show only 3 thumbs at one time, once u click "next" it would remove the first 3 thumbs and load the other 2 thumbnails.. heres a pic maybe it will explain better of what im trying to do.. Code: [Select] ${$payment['amount']} using the $ next to it doesn't work I am using itinside double quotes, any way I can get that dollar sign right next to it? This for people buying stuff off my forum i want the amount to show right by the $ dollar sign And im working inside double quotes only Error: Code: [Select] No error, Im have trouble Having This Loop Select Only 2 Uploads At a Time. Code: Code: [Select] <?php //porperties $result = mysql_query("SELECT * FROM uploaded"); while($r=mysql_fetch_array($result)) { $link=$r["link"]; $name=$r["name"]; $type=$r["type"]; $size=$r["size"]; $date=$r["date"]; $id=$r["id"]; echo " The File $name Was Currently Updated<br> Size: $size<br> Type: $type<br> Date Updated: $date<br> Link: <a href='$link'>Download</a><br><br> "; } ?> Couldn't Think of a Good name For this,Sorry I am working on a project where I want a select form to display information from a MySQL table. The select values will be different sports (basketball,baseball,hockey,football) and the display will be various players from those sports. I have set up so far two tables in MySQL. One is called 'sports' and contains two columns. Once called 'category_id' and that is the primary key and auto increments. The other column is 'sports' and contains the various sports I mentioned. For my select menu I created the following code. <?php #connect to MySQL $conn = @mysql_connect( "localhost","uname","pw") or die( "You did not successfully connect to the DB!" ); #select the specified database $rs = @mysql_SELECT_DB ("test", $conn ) or die ( "Error connecting to the database test!"); ?> <html> <head>Display MySQL</head> <body> <form name="form2" id="form2"action="" > <select name="categoryID"> <?php $sql = "SELECT category_id, sport FROM sports ". "ORDER BY sport"; $rs = mysql_query($sql); while($row = mysql_fetch_array($rs)) { echo "<option value=\"".$row['category_id']."\">".$row['sport']."</option>\n "; } ?> </select> </form> </body> </html> this works great. I also created another table called 'players' which contains the fields 'player_id' which is the primary key and auto increments, category_id' which is the foreign key for the sports table, sport, first_name, last_name. The code I am using the query and display the desired result is as follows <html> <head> <title>Get MySQL Data</title> </head> <body> <?php #connect to MySQL $conn = @mysql_connect( "localhost","uname","pw") or die( "Err:Db" ); #select the specified database $rs = @mysql_SELECT_DB ("test", $conn ) or die ( "Err:Db"); #create the query $sql ="SELECT * FROM sports INNER JOIN players ON sports.category_id = players.category_id WHERE players.sport = 'Basketball'"; #execute the query $rs = mysql_query($sql,$conn); #write the data while( $row = mysql_fetch_array( $rs) ) { echo ("<table border='1'><tr><td>"); echo ("Caetegory ID: " . $row["category_id"] ); echo ("</td>"); echo ("<td>"); echo ( "Sport: " .$row["sport"]); echo ("</td>"); echo ("<td>"); echo ( "first_name: " .$row["first_name"]); echo ("</td>"); echo ("<td>"); echo ( "last_name: " .$row["last_name"]); echo ("</td>"); echo ("</tr></table>"); } ?> </body> </html> this also works fine. All I need to do is tie the two together so that when a particular sport is selected, the query will display below in a table. I know I need to change my WHERE clause to a variable. This is what I need help with. thanks Hey quick question on my homepage there is a featured content section, which is populated from my DB some of the posts are really long so I would like to limit the amount of text. how can I do this? also is there a way to make sure if does not cut a word in half? thanks Hi All, Im new to this forum but think its going to be a regular location for me for quite a while. Im very very new to php and the guy that was doing code for me is not responding to emails, so i thought id have a go myself...lol at the moment im going through the trial and error phase while learning. I have edited some of the code he has put on the site to create a new look. the original page: http://www.ridersguide.co.uk/county_accommodation.php?county=4; the one im trying:http://www.ridersguide.co.uk/county_accommodation2.php?county=4; The new bit is to add a preview of the text for the page. echo $row[ad_text]; the code above brings up all the text but i only want to show the first 4 or 5 lines. Is this possible in php? Any help appreciated Neil Okay, I have a healing spell that allows people to regain stats when it's cast. But, how do I limit it so that they can't go over their maxhp? Here's what I have so far: $db->execute("UPDATE `users` SET `hp`=?, `mp`=?, `energy`=? WHERE `id`=?", array($player->hp + $healspell, $player->mp - $spell['mp'], $player->energy - $spell['energy'], $player->id)); What do I need to do in this to tell it to limit it to the maxhp but never going over it? $healspell is a random number, so it is quite possible to go over the maxhp at the moment. Thank you! If I knew what to call it I could have searched it. So I will just explain. I have a form that is pulling from a database to build the following. echo <input name='$row[id]' type='text' id='$row[id]' size=2>; This will build a page that has this <input name='22' type='text' id='22' size=2> <input name='54' type='text' id='54' size=2> This part works great. The problem is when I try to add it to the database. How can I insert variables that I don't know the names of? They will be something like $_POST[22] $_POST[54] and so on. I hope someone can understand my jibberish. I am sure there is a WAY better way to do this. Hi, I have a database where I store times with the Now(); function. What I want is: When the viewer looks at the post, instead of it saying: Posted: 2010-11-14 19:08:14, I want it to say posted: x hours ago, Posted: x days ago, etc. Any help with this would be appreciated! Hi, I have a function where I want to sort an an array of this type: 0 = {'fruit' => 'banana', 'color' => 'yellow', 'age' => '1', 'weight' => '2', 'brand' => 'dole', 'store' => shaws'} 1 = {'fruit' => 'apple', 'color' => 'red', 'age' => '3', 'weight' => '5', 'brand' => 'fuji', 'store' => 'foodmaster'} etc etc. I then want to array_multisort this array with different parameters. One way is to sort by fruit, then color, then brand. The second way by age, then store. Code: [Select] //This is how I sort it for my first way //Let's call the array $rows function sort($rows) { foreach($rows as $key => $value) { $fruit[$key] = $value['fruit']; $color[$key] = $value['color']; $brand[$key] = $value['brand']; } array_multisort($fruit, SORT_ASC, $color, SORT_ASC, $brand, SORT_ASC $rows); } I want to try to reuse this function by passing in the keys that I want to sort with. Like doing sort($rows, array('fruit', 'color', 'brand')), then sort($rows, array('age', 'store')). Is this possible? Hi, I'm trying to code a page which displays the amount of users currently viewing a page. But how do I decrease the count if a user closes the page? Thanks if i want to display upcoming events and only want to show the top 3? So I wrote this piece of code that for the most part works. The problem is two things. One if I print out say $dir[$i] I get 7 directories back. if I try and store that in an array to later be access by some other function I get up to 24+ C's instead of C:/Path... Code: [Select] public function aisis_get_dir_array($dir){ if(!is_array($dir)){ aisis_get_dir($dir); return; } $count = count($dir); for($i = 0; $i<$count; $i++){ if(!is_dir($dir[$i])){ _e('Specified dir' . $dir[$i] . 'is not a directory.'); } $this->directory_list = $dir[$i]; //store these $handler = opendir($dir[$i]); while($file = readdir($handler)){ if($file != "." && $file != ".."){ $this->files[] = $file; } } } return $this->files; } right under the line: $this->directory_list = $dir[$i]; //store these if You put in echo $dir[$i] you get back directories. How ever down in this function: Code: [Select] public function load_if_extentsion_is_php($dir, $array = false){ $list = array(); $list_dir = array(); if($array == true){ $list = $this->aisis_get_dir_array($dir); $list_dir = $this->directory_list; } else{ $list = $this->aisis_get_dir($dir); } $count = count($list); for($i = 0; $i<$count; $i++){ if($array == true){ $countdir = count($this->directory_list); for($j = 0; $j<$countdir; $j++){ echo $list_dir[$j]; //echo $list_dir[$j]; //echo $list[$i]; } } //if(substr(strrchr($list[$i],'.'),1)=="php"){ //echo $list[$i]; //require_once($dir . $list[$i]); //} } } echoing out: echo $list_dir[$j]; gets you up to 24+ C's instead of the directories that are stored. You can view the whole class at Paste bin - there is an expiry: 12 hours. Essentially you call load_if_extentsion_is_php($dir, $array = false) pass it an array of directories and set the array part to true. To Summarize: If you pass in an array of directories you should get back: a echoed list of directories a echoed list of php files belonging in those directories. Currently you get the later and a series of C's for the first. Why? I am working on php script that takes an input (using html) stores those values in a separate text file. I managed to get that to work. But the thing is I wanted to be able to sort those values alphabetically. Since their are an unspecified amount of inputs I tried using an explode on my output in order to store those values as an array so that I can sort them. Problem is explode makes each input its own separate array instead of one whole array. I figure some type of loop is needed to fix that but I can't figure out how to go about creating it [I'm pretty new to php]. Any advice? Heres my code for my PHP script: $filename = "ip_collection.txt"; $fileHandle = fopen('ip_collection.txt', 'a+') OR die("can't open file\n"); $ip = $_SERVER['REMOTE_ADDR']; $name = stripslashes($_POST['lastName'] . ", " . $_POST['firstName']); $textFromForm = $name. " | " . $ip; $newtext = $textFromFile . $textFromForm; $output = explode("\n",$newtext); sort($output); foreach($output as $key => $value) { fwrite($fileHandle, $value."\n"); } fclose($fileHandle); Hi guys, Im a newb here, so bear with me! Still learning the ropes. I want to delete all files from my server that are 6 hours old since being uploaded to the site. I believe i need a cron job? I currently have this script in its framework... Code: [Select] <?php //time interval for deletion to occur... $x = 30; //timestamp $current_time = time(); //the file you wish to delete $file_name = 'file.txt'; //timestamp $file_creation_time = filemtime($filename); //extract difference $difference = $current_time - $file_creation_time; //if difference = $x...then delete file if ($difference == $x) { unlink($file_name); } Would that work automatically or would it need a cron to run it? And how could i test it, that bit worries me. Many thanks. Hey Guys, I'm looking to echo a large amount of complicated text that includes a lot of symbols, such as this: Code: [Select] V\"`'8\"`%n\"`)*$6A`!K!`2D\"`-t\"`!8\"`,?$`!1#D`\"i!`&2%` 9!`$S\"`#C)`# \"`\">\"7`)Q$`+Y\"C`!B!`%2\"`(e\"`($-`&M(`&C#F`$Q$`-P(`$P\"`#Q-`\"A\"`$CA`1e1` 5(`2GC0%2`&x!`'\"#`,i$`%D\"77`\"W!`%K!`$A.`/q+`(V\"`!J\"`,/\"`//%6E`$:#`.%)`\"u!`.d&`,K$`&F#`#V%`!z%`#2\"` &\"`&0!`3.&`2V%`)#+`\"t\"`.,\"` E!`(m&`3P(7`%l*`#q\"`-Q!`(#\"``1)\"` kC`#P+`$I2`-#\"`3<66`0H!`,|&6`#d#`$}. Can anyone shed some light as to how I would be able to echo the above without having to backlash all the clashing symbols and preferably without having to include an external file? All your help is greatly appreciated. Extreme. |