PHP - Help With A Php/mysql Automatic Sort Code
So basically I have a database full of players 'items'. Each player has 2 items. and I need to make a circle with these players with only specific items involved. Each circle can only contain 6 players.
The items needed to create this circle a pigs spice sugar cows aluminium marble iron lumber wheat water random random so 10 resources are literally needed to create this circle but 12 is needed to make it a 'circle' if you get me. I'd like to note that it is possible that any of these players can have a combination of any of resources listed above. I've created a form that allows people to submit players resources into my mysql database. I heard it was possible that I could code some type of filter/sort code to sort out the players resources from my database automatically into a set that will match what is needed (without any repeat of resources) and having a php code to export it into html format for viewing pleasures. I really have no idea how to go about this in mysql or php. But if somebody could help me out i'd be ever so glad. Also to note: this isn't school work or something. It's from a game I play and i'm just trying to make my job in it easier. I was thinking of maybe a php code that will run through all the possible partners in order to create this set like run through 100s of different sets until the required set is obtained. I heard this is just about possible. Can anyone help me? Looking forward to all the great help around here. Thanks Samuz PS: Each item/resource can only appear once in each circle. Similar TutorialsHi All i am wanting a column list like this http://extensions.joomla.org/extensions basically the database is set up as (id, category, parent) I want the parent to group the category section and list like the the joomla example in three columns search various threads throughout the internet but none seem to cover this entirely can any one please help????? Hi all, I have a database which contains customer details. We have a php script which pulls the records from the database and puts them into a table on the page. Currently, it fetches all the customer records. This wasn't such a problem when there was only a few customers in the db but this is a bit higher now! Is there any way I can modify the script to only show 20 per page and add links to page 2 etc along the bottom, which can be clicked to show the next 20 and so on? I can post my current code if need be, Thanks. Say I have a column in a MySQL database, that contains the following data (each piece of data is in its own row, as stored as a string): 16b 166 13A 13a 4 402c A66 A66b Currently the list sorts as follows: A66 A66b 13A 13a 16b 166 4 402c I need it to sort as follows: A66 A66b 4 13a 13A 16b 166 402c So that any strings that start with a letter are first, followed by numbers in numerical order, with lower case letters coming before upper case letters. This is a huge issue on my website, which has a database of over 35k such numbers, split up into lists. I can't get these sorted properly. At least it would be nice to sort as follows: 1 4 100 344 Instead of 1 100 344 4 Know what I mean? I know that this is complicated, because the variables are strings and not numbers, but is there an easy way to do this? How to sort data from table? Currently its sorted by ID. But I want to add option that admin can sort data (click on up/down link or whatever). Its about forum script and all forums have categories. Forum and categories are in same table. Forum "parent" is ID of category. So i have following sorting: Cat1 [ID1] ->Forum1 [ID2] [PARENT1] ->Forum2 [ID3] [PARENT1] Cat2 [ID4] ->Forum3 [ID5] [PARENT2] ->Forum4 [ID6] [PARENT2] I need to add additional field "sort". On click admin can UPDATE sorting by increasing/decreasing number. But problem is categories and forum are in same table. If I want to move up FORUM1 (ID2) with (for example) "sort" number 2 I must decrease number (-1) and that forum will be with same sort number as category above. Also if I want to move Category up/down it also must move all forums from that category (but that is not big problem). What is best way to solve this? Hello, i have a user entering dates in the format DD-MM-YYYY --> 11-12-02 when i try to sort by DESC [nearest date first] i am getting sort problems for example i'll get this.. 11-12-02 12-07-02 13-08-02 whats the best way to sort this to get the dates correct? Hi guys, Having problems sorting mysql results. I can easily order/sort table columns but would like to order the results by a variable.(Distance in Miles). Havent much experience in PHP and really struggling with this. Basically a query echoing out car make and models and how far they are located from a postcode. Can get it to work no porblem, but not to order/sort by least distance. Heres what i'm working with: Code: [Select] $res=mysql_query("SELECT * FROM cars"); while ($row = mysql_fetch_assoc($res)){ echo $row['Make']; echo $row['Model']; //variable will be determimed by user input form $postcode="W12 3SR"; $start=$postcode; $ends = array(); //finds value from database field { $ends[]=$row['Location']; } // Postcode entered by user via input form $result=mysql_query("SELECT * FROM postcodes WHERE Pcode='$start'"); while($row=mysql_fetch_array($result)){ $gridn[0]=$row['Grid_N']; $gride[0]=$row['Grid_E']; } foreach($ends as $fin){ // Postcodes within mysql table $result=mysql_query("SELECT * FROM postcodes WHERE Pcode='$fin'"); while($row=mysql_fetch_array($result)){ $gridn[1]=$row['Grid_N']; $gride[1]=$row['Grid_E']; } // TAKE GRID REFS FROM EACH OTHER TO WORK OUT DISTANCE. $distance_n=$gridn[0]-$gridn[1]; $distance_e=$gride[0]-$gride[1]; // CALCULATE THE DISTANCE BETWEEN THE TWO POSTCODES AND DIVIDE BY 1.6 TO CONVERT KM TO MILES $hypot=sqrt(($distance_n*$distance_n)+($distance_e*$distance_e))/1.609; //VARIABLE FOR DISTANCE AND ROUNDED OF TO NEAREST WHOLE NUMBER. $distance=''.round($hypot/1000,0).''; echo " $distance miles"; echo "<br>"; } } ?> I wish i could just do something like this but isnt possible, is it ? Code: [Select] "Select * FROM cars ORDER BY $distance"; Thanks! I have a MySQL table with a list of albums and there is a field called "views" with the number of views each album has received. I'm looking to generate an array of all the albums in the table and sort the array by the number of views (descending). I have a list of functions defined in a ContentController.php file. I created a new function called build_albumlist, which I've pasted below. The function "get_ip_log" already exists and works, and I used it as a template to create the "build_albumlist" function: public function build_albumlist(){ return $this->select_raw("SELECT * FROM albums WHERE deleted = '0' ORDER BY views DESC",array(),'all'); } public function get_ip_log(){ return $this->select_raw("SELECT * FROM sessions ORDER BY ID DESC",array(),'all'); } When I use the function, I get this warning: Warning: mysql_real_escape_string() expects parameter 1 to be string, array given inC:\xampp\htdocs\Controllers\DBController.php on line 10 [font=cabin, 'trebuchet ms', helvetica, arial, sans-serif]The "select_raw" function that I used in "build_albumlist" is defined in the DBController.php file, and is defined as below:[/font] private function clean_array($params){ $final=array(); foreach($params as $param){ $final[]=mysql_real_escape_string($param); } return $final; } public function select_raw($query,$params,$type=''){ $query=str_replace("?","'%s'",$query); $final_query= call_user_func_array('sprintf', array_merge((array)$query, $this->clean_array($params))); if($type==''){ $result=mysql_query($final_query) or die(mysql_error()); return mysql_fetch_assoc($result); } elseif($type=='all'){ $result=mysql_query($final_query) or die(mysql_error()); $final=array(); while($row=mysql_fetch_assoc($result)){ $final[]=$row; } return $final; } Does anyone know why the "build_albumlist" function is generating this warning, while the "get_ip_log" is not? Any help would be great, as I am obviously pretty new to this. Hi again, i'm wondering how can i make Sort (for example a-z) an column in php reading mysql informations. Here's the script: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <link rel="stylesheet" href="table.css" type="text/css"> </head> <body style="margin: 0 0 0 0;"> <? include("passwd.php"); @$start = $_GET["start"]; if($start =='') $start =0; include("lib.php"); $link = mysql_connect($host,$username,$password); if (!$link) { die('Could not connect: ' . mysql_error()); } $db_selected = mysql_select_db($db, $link); if (!$db_selected) { die ("Can't use $db : " . mysql_error()); } //total number of records in the table $res = mysql_query("SELECT * from `$table`"); @$rows = mysql_num_rows ($res); $result = mysql_query("SELECT * from `$table` limit $start,10"); if (!$result) { die('Invalid query: ' . mysql_error()); } echo "<p align=center class = 'menu'> Ocitana tabela: $table </p>"; $cols = mysql_num_fields($result); $records = mysql_num_rows ($result); echo "<table align='center' width='1200' >"; echo "<tr bgcolor='BBCCDD' class='menu'>"; for ($i = 0; $i < $cols;$i++) { echo "<td align='center'>".mysql_field_name($result,$i)."</td>"; } echo "</tr>"; while ($row = mysql_fetch_array($result, MYSQL_NUM)) { echo "<tr bgcolor='F6F6F6' class='normal'>"; foreach ($row as $value) { echo "<td align='center'>".$value ."</td>"; } echo "</tr>"; } $end = $start + $records; echo "<tr align = 'center' bgcolor = 'BBCCDD' class='menu'><td colspan=$cols> Prijema $start do $end od $rows </td></tr>"; echo "<tr align = 'center' class='mylink'><td colspan=$cols> "; if($start != 0) { $prev = $start - 10; echo "<a href='tabela.php?start=$prev'> Prethodna </a> "; } if($start<$rows-10) { $next = $start + 10; echo "<a href = 'tabela.php?start=$next'>Sledeca</a> "; } echo "</td></tr>"; echo "</table>"; ?> </body> </html> I have a website that has definitions and articles. I need a code that craws the php content pulled from my database, finds a specified word and replaced that word with a link. For example If "car" appears replace with <a href="http://www.website.com/car.php">car</a> Thanks Todd How can I make sure that when I submit an new form and new ID (record) is created it is always 4-Digits. record 14 = 0014, record 225 = 0225. Thanks At this time i am building an email generation report program. I have everything working for the first and second report. But when i try to update and get the 3 run of emails it doesnt update the previous one. below you will find the code that i have been working on and i have everything working except for the update to run every single time. Code: [Select] $con = mysql_connect("test","test","test"); // $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("test", $con); // mysql_select_db("test", $con); $id = $_POST['id']; $demo = $_POST['demo']; $limit = $row["unique_recp"]; } $res = mysql_query("SELECT emails FROM email_list WHERE custid = '$id' and demo = 'N' LIMIT ".$limit." "); while ($row = mysql_fetch_array($res)) { echo "<div id=\"left\">".$row['emails']."</div><div id=\"clr\"></div>"; } mysql_query($res); $res2 = "update email_list set demo = 'Y' WHERE custid = '$id' LIMIT ".$limit.""; mysql_query($res2); mysql_close($con); I have put in test for the actual data. Let me know if you can figure out what is going on? If you need to see the enter code i can send it. I'm trying to use php code that is stored in the sql database, but It doesn't seem to be executing the code. when I see the page source, its there but the server is not executing the command how do I accomplish this. Here is a simple code snippet to show what I am trying to do. $result = mysql_query("select * from data"); $row = mysql_fetch_array($result); echo $row['code']; In the code field in data table this is whats there. <?php echo "testing."; ?> Hey everyone, im having problems querying the results from the database using this query.... $get_points = mysql_query("SELECT * FROM points WHERE ACOS( (SIN(PI() * '41.896301269531' / '180') * SIN(PI() * latitude / '180')) + (COS(PI() * '41.896301269531' /'180') * COS(PI() * latitude / '180') * COS(PI() * longitude / '180' - PI() * '-88.744201660156' / '180')) )* '180' / PI() * '60' * '1.1515' <= '80'") or die(mysql_error()); Basically what it does it checks the for location with in 80 miles of the lat and long coordinates. The problem is no result are showing up. I know there are locations because i tested this as an sql code in my database and it ran perfectly, but i can't get it to work using php.. I get no errors, nothing. can anyone help me out? On the mainpage I am getting this error:
Fatal error: Call to a member function query() on a non-object in C:\xampp\htdocs\page\controller\function.php on line 393
$result = $db->query($query);And on the admin section: Notice: Undefined index: role in C:\xampp\htdocs\page\admin\header.php on line 7 Notice: Undefined index: role in C:\xampp\htdocs\page\admin\header.php on line 7 Fatal error: Undefined class constant 'site_url' in C:\xampp\htdocs\page\admin\header.php on line 8 if ($_SESSION['role'] !== 'admin' and $_SESSION['role'] !== 'moderator'){header( 'Location:'.config::site_url.'index.php' ); How can I insert PHP code inside MySQL DB? I have mixed HTML and PHP code like this: <div class="rightpanel"> <div class="hltred"> <div class="hlthead"> <p><?php echo $pages->naslov; ?></p> </div> <div class="hltcontent"> <p> ovde treba da ide loop sa svi podlinkovi za taj glavni koji je aktivan</p> </div> </div> </div>, but when i insert it into DB i get this code (I use htmlspecialchars function to store): <div class="rightpanel"> <div class="hltred"> <div class="hlthead"> <p> <!--?php echo $pages---> naslov; ?></p> </div> <div class="hltcontent"> <p> ovde treba da ide loop sa svi podlinkovi za taj glavni koji je aktivan</p> </div> </div> </div> Could someone please help me out here?
I've been using the code below in some of my WordPress pages, but I've looked at it so long ago that I honestly can't remember how to debug it - go figure... The only thing that changed was the database.
It works like this:
URL has parameter called id in this form: http://example.com/post?id=...
Code checks if param is present, otherwise it redirects home.
If the param is present, code gets the ID and compares it to the records in the MySQL database hosted by my ISP.
Match gets used in an echo statement.
A div on the page is activated.
Database Layout:
+-------+------------+------------+------------+------------+---------------+ | id | Naam | Metgesel | Kind1 | Kind2 | Email | +-------+------------+------------+------------+------------+---------------+ | abc12 | Bobby | Caily | * | * | b@example.com | | ... | ... | ... | ... | ... | ... | +-------+------------+------------+------------+------------+---------------+ERROR ENCOUNTERED: Warning: mysql_real_escape_string() expects parameter 1 to be string, array given in /home/.../public_html/wp-content/plugins/insert-php-code-snippet/shortcode-handler.php(32) : eval()'d code on line 4 Invalid or no security key!Code: <script> function invite(){ document.getElementById('invite').style.display=(document.getElementById('invite').style.display=='block')?'none':'block'; } </script> <script> function returnHome(){ setTimeout(function () {window.location.href = 'http://example.com';},2000); } </script> $part = $_REQUEST['id']; if(isset($_GET["id"])){ $query = sprintf("SELECT * FROM `DATABASE`.`TABLE` WHERE idquack='$part'", mysql_real_escape_string($query)); $result = mysql_query($query); if (!$result) { $message = 'Invalid or no security key!'; die($message); } else { while ($row = mysql_fetch_assoc($result)) { if ($row['Metgesel'] != "*"){ if ($row['Metgesel'] == "#"){ if ($row['Kind1'] != "*"){ if ($row['Kind2'] != "*"){ echo '<h1>' . $row['Naam'] . ", " . "Metgesel" . ", " . $row['Kind1'] . " en " . $row['Kind2'] . "</h1>"; } else { echo '<h1>' . $row['Naam'] . ", " . "Metgesel" . " en " . $row['Kind1'] . "</h1>"; } } else { echo '<h1>' . $row['Naam'] . " en " . "Metgesel" . "</h1>"; } } else{ if ($row['Kind1'] != "*"){ if ($row['Kind2'] != "*"){ echo '<h1>' . $row['Naam'] . ", " . $row['Metgesel'] . ", " . $row['Kind1'] . " en " . $row['Kind2'] . "</h1>"; } else { echo '<h1>' . $row['Naam'] . ", " . $row['Metgesel'] . " en " . $row['Kind1'] . "</h1>"; } } else { echo '<h1>' . $row['Naam'] . " en " . $row['Metgesel'] . "</h1>"; } } } else { echo '<h1>' . $row['Naam'] . "</h1>"; } echo '<script>invite();</script>'; } } mysql_free_result($result); } else{ echo 'Hold on tight - we're taking you to safety!'; echo '<script>returnHome();</script>'; } Ok, my subject line may not be exactly what I am looking for and I am not even sure what the subject should be, so let me explain what I am trying to do. My application is as such that you enter in a zip code and it returns information, however my hard copy has a range of zip codes, in this case, equaling a zone, I.E. 90076-90210 is zone A, now instead of having the following in the database: Code: [Select] ID ZIP ZONE 1 90076 a 2 90077 a 3 90078 a ... ... 134 90210 a Could I make it: Code: [Select] ID SZIP EZIP ZONE 1 90076 90210 a and though my PHP/mySQL callout compare the variable to, and find that is ZIP is between SZIP and EZIP to output a? As there are a couple od thousand zip codes I am trying to minimize my database to be a bit smaller, but am not sure how to code it. Normally I would make the database have all 99000 entries and pull from the database where ZIP = ZIP, but again I am trying to save my self some time... Could I make it somehow that if ZIP <= SZIP and >= EZIP output ZONE? Does this make any sense? My PHP Coding is unfortunately lacking, I have only been programming it heavily for the last 5 months and it has been basic stuff. Any help would be appreciated. Hi! I have a question that I need help with. I guess almost everyone of us have played a webgame where something happends automaticly. Some examples: Attacks, resources in Travian, Tribalwars, Khan Wars ... How are these things done? Now I'm talking about automatical things that happends every second. Is there a Cron Job that every second connectes to a database and adds more resources to the player? Regards Worqy I want to upload a file automatically at any time from my home PC to a website I am developing. I can upload OK using a form with 'enctype="multipart/form-data"' but this requires manual operation to select a file and to submit the upload request. Is there a way the upload process can be made to happen with no operator present? I also want to download from the website to my PC automatically ie. download a file (as it becomes available) from the website to a specified location on my PC, without operator intervention. Help. Thanks. Hi everyone! I am building an application in PHP with MySQL on my localhost. I tried to connect to the database like this: mysql_connect("localhost", "root", "password"); mysql_select_db("app-db"); but the message I get is: Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'user'@'localhost' (using password: NO) in C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\app\Source\includes\db_connect.php on line 3 Warning: mysql_select_db() [function.mysql-select-db]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\app\Source\includes\db_connect.php on line 4 Warning: mysql_select_db() [function.mysql-select-db]: A link to the server could not be established in C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\app\Source\includes\db_connect.php on line 4 I never wrote user 'user' in the whole application but root and even when I comment out that line of mysql_connect, the first error doesn't go away. The url of the index of the application is localhost/app/Source/index.php When I make a page: localhost/index2.php with the same content as my db_connec file then there is no error. When I move or copy the db_connect file to localhost/db_connect.php it also gives me those warnings. Also, when I change things in the code, PHP does not recognize them and nothing changes - meaning, that I can comment out those connect statements and still get the warnings. Can anyone offer me some advice and help me solve this, please? Thanks in advance! MiRed |