PHP - Php Read From Mysql - Make Sort Buttons On Tables
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> 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????? <html> <body> <script type='text/javascript'> var currenttime = new Date() var montharray=new Array('Jan','Feb','March','April','May','June','July','Aug','Sept','Oct','Nov','Dec') var serverdate=new Date(currenttime) function padlength(what){ var output=(what.toString().length==1)? '0'+what : what return output } function displaytime(){ serverdate.setSeconds(serverdate.getSeconds()+1) var timestring=padlength(serverdate.getHours())+':'+padlength(serverdate.getMinutes())+':'+padlength(serverdate.getSeconds()) document.getElementById('servertime').innerHTML=timestring+' MST ' document.getElementById('nav_servertime').innerHTML=timestring+' MST ' } window.onload=function(){ setInterval('displaytime()', 1000) } </script> </body> </html> <html> <head> <link rel="shortcut icon" href="http://www.toxicpets.co.uk/favicon.ico" > <meta name="description" content="toxicpets Is A FREE Online Virtual Pet Site For All Ages"> <meta name="keywords" content="Toxicpets, adopt, free, online, site, pets, kids, games, children, safe, virtual, fun, Jack, Wright"> <meta name="google-site-verification" content="BeR9LIHxeOGKgw90pAZG6o3dS-Ym3lxxPlH1LTgFiLY" /> <meta name="google-site-verification" content="JXFL8M3LU47SMJZ6aNi4u8BSyD8PWqsqlrORFHkvDfE" /> <meta name="CREATOR" content="Jack Wright"> <meta name="copyright" content="Copyright Toxicpets - 2010"> <meta name="author" content="Jack Wright"> <meta name="email" content="admin@toxicpets.co.uk"> <meta name="Charset" content="ISO-8859-1"> <meta name="Distribution" content="Global"> <meta name="Rating" content="General"> <meta name="Robots" content="INDEX,FOLLOW"> <meta name="Revisit-after" content="1 Day"> </body> </html> <?php $time = date("H"); if ($time <= 5 || $time >= 19) { $backgroundColor = "#3366FF"; $tableOutline = "#000000"; $topAndBottomBG = "#003399"; $topAndBottomText = "#FFFFFF"; $middleBG = "#99CCFF"; $middleTEXT = "#000000"; $reallyLight = "#DEF2FF"; $menuColor = "#FFFFFF"; $maincellColor = "#FFFFFF"; $maincellText = "#000000"; $menulinkColor = "#003399"; $mainlinkColor = "#003399"; $bottomlinkColor = "#FFFFFF"; } else { $backgroundColor = "#333333"; $tableOutline = "#333333"; $topAndBottomBG = "#000000"; $topAndBottomText = "#FFFFFF"; $middleBG = "#CCCCCC"; $middleTEXT = "#000000"; $reallyLight = "#F8F8F8"; $maincellColor = "#FFFFFF"; $maincellText = "#000000"; $menuColor = "#666666"; $menulinkColor = "#FFFFFF"; $menutextColor = "#FFFFFF"; $mainlinkColor = "#003399"; $bottomlinkColor = "#FFFFFF"; } // Page Colors // End Page Colors // Ranks ect if ($rank == { $admin_line .= "<br><a href=$base_url1/admin/admin.php?game=$game class=menu>Admin Panel</a><BR> <a href=$base_url1/dom.php>Show Maintenance?</a> "; } if ($rank == 5) { $admin_line .= "<p align=center>Admin Stuff: <br> <a class=menu href=# onClick=\"window.open('$base_url1/admin/admin_remote.php?game=$game','remote','toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=200,height=60')\">Mute User</a> <br> <a class=menu href=$base_url1/warn_user.php?game=$game>Warn User</a>"; //$get = mysql_query("SELECT number FROM dom"); //if ($get = 1) //echo "<meta http-equiv='refresh' content='0;url=http://toxicpets.co.uk/down_for_maitenence.php'>"; //elseif ($get = 0) //echo "<meta http-equiv='refresh' content='0;url=http://toxicpets.co.uk/index.php'>"; } if ($rank == 7) { $admin_line .= "<br><a href=$base_url1/admin/admin.php?game=$game class=menu>Admin Panel</a>"; //$get = mysql_query("SELECT number FROM dom"); //if ($get = 1) //echo "<meta http-equiv='refresh' content='0;url=http://toxicpets.co.uk/down_for_maitenence.php'>"; //elseif ($get = 0) //echo "<meta http-equiv='refresh' content='0;url=http://toxicpets.co.uk/index.php'>"; } if ($rank == null) { $updateLine2 = "<p><a href=register.php?game=$game><img src=http://toxicpets.co.uk/images/nav_register.jpg width=113 height=101 border=0></a></p>"; //End Ranks } { } $rc = mysql_fetch_array( mysql_query("SELECT * FROM members2 WHERE id = '$userid'") ); $menu = "$updateLine2<p><ul id='MenuBar1' class='MenuBarVertical'> <li><a class='MenuBarItemSubmenu' href='#'>My Profile</a> <ul> <li><a href='#'>$username</a></li> <li><a href='#'>Control Panel</a></li> <li><a href='#'>Edit Profile</a></li> <li><a href='#'>Toxic Mail</a></li> <li><a href='#'><span id='nav_servertime'></span></a></li> </ul> </li> <li><a class='MenuBatItemSubmenu' href='/mypets.php?game=1'>Pets</a> <ul> <li><a href='/adopt.php?game=1'>Adoption Center</a></li> </ul> </li> <li><a class='MenuBarItemSubmenu' href='/index.php'>Explore</a> <ul> <li><a href='/index.php?game=$game'>Toxopada</a></li> <li><a href='/blanchills.php?game=$game'>Blanc Hills</a></li> <li><a href='/rija?game=$game'>Rija Mountian</a></li> </ul> </li> </li> <li><a class='MenuBarItemSubmenu' href='/games.php'>Games</a></li> <li><a class='MenuBarItemSubmenu href='#'>Your Stuff</a> <ul> <li><a href='/bank.php'>Slime: $points</a></li> <li><a href='#'>Hunger Level : $hungerLevel</a></li> <li><a href='/myitems.php'>Your Items</a></li> <li><a href='/myshop.php'>Your Shop</a></li> <li><a href='/rarerumble.php'>Rare Coins : $rc[rc]</a></li> </ul> </li> </ul> <script type='text/javascript'> var MenuBar1 = new Spry.Widget.MenuBar('MenuBar1', {imgRight:'../SpryMenuBarRightHover.gif'}); </script> </font></p>$admin_line <center> "; $userInfo = "<P><FONT SIZE=\"-1\"> Username: <A HREF=$base_url1/update_profile.php?game=$game class=menu>$display_name</A><BR> Hunger: <A HREF=$base_url1/myitems.php?game=$game class=menu><FONT SIZE=-1>$hungerLevel</A><BR> $pointVar: <a href=$base_url1/bank.php?game=$game>$points</a><BR> $rp_: <a href=$base_url1/bank.php?game=$game>???</a><BR>"; //PUT IN $rp_: TO ACTIVATE RP!!! //$rp___ $links = "<center><p><b><u>My Prefs</u></b></p></center> <center><a href=$base_url1/myitems.php?game=$game>Items</a><center> <center><a href=$base_url1/mypets.php?game=$game>Pets</a></center> <center><a href=$base_url1/nursery.php?game=$game>Nursery</a></center>"; // SearchBox $searchBox = "<form action=$base_url1/search.php?game=$game method=post><p align=center><INPUT TYPE=text NAME=command VALUE='' SIZE=8><BR><INPUT TYPE=submit NAME=submit VALUE='Do it'></P></form>";; //End SearchBox // Bottom Copyright $Time = "<span id='servertime'></span>"; $Toxicpets = "<a href=http://www.toxicpets.co.uk class=bottom>Run By ToxicPets.co.uk</a><br>"; $Terms = "<a href=$base_url1/tos.php?game=$game class=bottom>Terms/Rules</a>"; $Privacy = "<a href=$base_url1/privacy.php class=bottom>Privacy</a>"; $Upgrade = "<a href=upgrade.php?game=$game class=bottom>Upgrade to Premium Now!</a>"; $Sitemap = "<a href=http://toxicpets.co.uk/sitemap2.xml class=bottom onclick='return popitup('popupex.html')'>Sitemap</a>"; $copywrite =" $Time | $Toxicpets | $Terms | $Privacy | $Upgrade | $Sitemap "; //End Bottom Copyright // // // (C) // // // // CSS // //CSS INCUDED IN PHP// $openHTML = " <HTML> <HEAD> <center><TITLE>$gameName2 - $page_title</TITLE></center> <style><!-- INPUT {color:#000000; font: 9pt verdana; font-weight: none; text-decoration: none; background: $maincellColor; border: 1 solid $topAndBottomBG; } TEXTAREA {color:#000000; font: 9pt verdana; font-weight: none; text-decoration: none; background: $maincellColor; border: 1 solid $topAndBottomBG; } BUTTON {color:#000000; font: 9pt verdana; font-weight: none; text-decoration: none; background: $maincellColor; border: 0 solid $topAndBottomBG; } SELECT {color:#000000; font: 9pt verdana; font-weight: none; text-decoration: none; background: $maincellColor; border: 1 solid $topAndBottomBG; } INPUT {color:#000000; font: 9pt verdana; font-weight: none; text-decoration: none; background: $maincellColor; border: 1 solid $topAndBottomBG; } OPTION {color:#000000; font: 9pt verdana; font-weight: none; text-decoration: none; background: $maincellColor; border: 1 solid $topAndBottomBG; } RESET {color:#000000; font: 9pt verdana; font-weight: none; text-decoration: none; background: $maincellColor; border: 1 solid $topAndBottomBG; } SUBMIT {color:#000000; font: 9pt verdana; font-weight: none; text-decoration: none; background: $maincellColor; border: 1 solid $topAndBottomBG; } A:link { text-decoration: underline; color: $mainlinkColor; } A:visited { text-decoration: underline; color: $mainlinkColor; } A:hover { text-decoration: underline; color: $mainlinkColor; } A:active { text-decoration: underline; color: $mainlinkColor; } A:link.menu { text-decoration: underline; color: $menulinkColor; } A:visited.menu { text-decoration: underline; color: $menulinkColor; } A:hover.menu { text-decoration: underline; color: $menulinkColor; } A:active.menu { text-decoration: underline; color: $menulinkColor; } A:link.bottom { text-decoration: underline; color: $bottomlinkColor; } A:visited.bottom { text-decoration: underline; color: $bottomlinkColor; } A:hover.bottom { text-decoration: underline; color: $bottomlinkColor; } A:active.bottom { text-decoration: underline; color: $bottomlinkColor; } p { font-family: verdana; font-size: 11pt; color: black; } p.error { font-family: verdana; font-weight: bold; color: red; } p.white { font-family: verdana; color: white; } a.white { color: white; text-decoration: underline; } hr { margin: -1; } img { border: 0 } --></style> <script type=text/javascript src=popupBox.js></script> <script type='text/javascript'> var MenuBar1 = new Spry.Widget.MenuBar('MenuBar1', {imgRight:'../SpryMenuBarRightHover.gif'}); </script> <script src='../SpryMenuBar.js' type='text/javascript'></script> <link href='../SpryMenuBarVertical.css' rel='stylesheet' type='text/css' /> </HEAD> <BODY BGCOLOR=\"$backgroundColor\"> <TR BGCOLOR=\"#FFCC00\" width=100%> <TD VALIGN=bottom COLSPAN=2 HEIGHT=60 body background=\"bg.jpg\" width=12> <CENTER> <a href='http://www.toxicpets.co.uk/login.php' onMouseOver=\"image3.src='http://toxicpets.co.uk/login_over.png';\" onmouseout=\"image3.src='http://toxicpets.co.uk/login.png';\"><img name=\"image3\" src='http://toxicpets.co.uk/login.png' border=0></a> <a href='http://www.toxicpets.co.uk/logout.php' onMouseOver=\"image12.src='http://toxicpets.co.uk/logout_over.png';\" onMouseOut=\"image12.src='http://toxicpets.co.uk/logout.png';\"><img name=\"image12\" src='http://toxicpets.co.uk/logout.png' border=0></a> <a href='http://www.toxicpets.co.uk/mypets.php' onMouseOver=\"image1.src='http://toxicpets.co.uk/pets_over.png';\" onMouseOut=\"image1.src='http://toxicpets.co.uk/pets.png';\"><img name=\"image1\" src='http://toxicpets.co.uk/pets.png' border=0></a> <a href='http://www.index.php/explore.php' onMouseOver=\"image2.src='http://toxicpets.co.uk/explore_over.png';\" onMouseOut=\"image2.src='http://toxicpets.co.uk/explore.png';\"><img name=\"image2\" src='http://toxicpets.co.uk/explore.png' border=0></a> <a href='http://www.toxicpets.co.uk/forums.php' onMouseOver=\"image4.src='http://toxicpets.co.uk/forums_over.png';\" onMouseOut=\"image4.src='http://toxicpets.co.uk/forums.png';\"><img name=\"image4\" src='http://toxicpets.co.uk/forums.png' border=0></a> <a href='http://www.toxicpets.co.uk/clubs.php' onMouseOver=\"image6.src='http://toxicpets.co.uk/clubs_over.png';\" onMouseOut=\"image6.src='http://toxicpets.co.uk/clubs.png';\"><img name=\"image6\" src='http://toxicpets.co.uk/clubs.png' border=0></a> <BR style='padding:0;'> <a href='http://www.toxicpets.co.uk/shops.php' onMouseOver=\"image7.src='http://toxicpets.co.uk/shops_over.png';\" onMouseOut=\"image7.src='http://toxicpets.co.uk/shops.png';\"><img name=\"image7\" src='http://toxicpets.co.uk/shops.png' border=0></a> <a href='http://www.toxicpets.co.uk/upgrades.php' onMouseOver=\"image8.src='http://toxicpets.co.uk/upgrade_over.png';\" onMouseOut=\"image8.src='http://toxicpets.co.uk/upgrade.png';\"><img name=\"image8\" src='http://toxicpets.co.uk/upgrade.png' border=0></a> <a href='http://www.toxicpets.co.uk/updates.php' onMouseOver=\"image9.src='http://toxicpets.co.uk/news_over.png';\" onMouseOut=\"image9.src='http://toxicpets.co.uk/news.png';\"><img name=\"image9\" src='http://toxicpets.co.uk/news.png' border=0></a> <a href='http://www.toxicpets.co.uk/battle_center.php' onMouseOver=\"image10.src='http://toxicpets.co.uk/battle_over.png';\" onMouseOut=\"image10.src='http://toxicpets.co.uk/battle.png';\"><img name=\"image10\" src='http://toxicpets.co.uk/battle.png' border=0></a> <a href='http://www.toxicpets.co.uk/auctions.php' onMouseOver=\"image11.src='http://toxicpets.co.uk/auctions_over.png';\" onMouseOut=\"image11.src='http://toxicpets.co.uk/auctions.png';\"><img name=\"image11\" src='http://toxicpets.co.uk/auctions.png' border=0></a><BR style='padding:0;'> <TABLE BGCOLOR=\"$tableOutline\" CELLSPACING=1 CELLPADDING=0 WIDTH=\"95%\"> <TR BGCOLOR=\"#FFCC00\" width=100%> <TD VALIGN=bottom COLSPAN=2 HEIGHT=60 BGCOLOR=\"$topAndBottomBG\" width=12> <P ALIGN=right><FONT SIZE=\"+3\" COLOR=\"$topAndBottomText\"><B>$gameName</B></FONT></P> </TD> </TR> <TR> <TD VALIGN=top BGCOLOR=\"$menuColor\" width=120> $menu $userInfo $links $searchBox </TD> <TD VALIGN=top BGCOLOR='$maincellColor'><font color=$maincellText> "; $closeHTML = " </font></TD> </TR> </CENTER> </TABLE> </BODY> </HTML> <TR BGCOLOR='$topAndBottomBG'> <TD COLSPAN=150> <center><P align=center><FONT SIZE= '-1' color='$topAndBottomText'>$copywrite</FONT></P></center> </TD> </TR> "; ?> form example, in the first page, there is a article, it takes contents from database, if a article is shorter than 1000, it displays the full content on the first page, if its longer than 1000, it will display a short part of article, and displays a 'read more' on the end of the article. how to make this? I think we cant do this by paging function, can we? HI, I have a ms-access file which has linked table. The linked table is connected to a ODBC source (e.g MS-SQL or 3rd Party ODBC Driver). WebPage(php) Apache, connecting to a ODBC DSN of MS-Access, MS-Access is having linked tables. Linked tables as from another ODBC source. On the PHP Page, When I am trying to connect the ms-access odbc dsn , I am able to connect. But when I query any of the linked tables, PHP is not able to query and is failing. Does php has capabilities to read/write to linked tables in ms-access file. Or it is issue with MS-Access Or is it I am missing something. Microsoft says, its an issue of PHP https://social.msdn....forum=accessdev Requesting you to please share your feedback Regards Rajendra Dewani I am new to PHP and currently trying to develop a website... i am stuck at one place. Lets say i'm a user(mrX) that has 4 types of car that are Ferrari, Lamborghini, Evo and BMW. So, i will register to the system about my details and all of my car info such as their cc, transmission, plat number, engine capacity. Then, i will log on into the system and after log on, there will be a drop down list. If i pick Ferrari for example, under the drop down list there will be all the information about the car. The same on the other car also. This portion is kind of stumping me. Basically, I have a two tables in this DB: users and users_access_level (Separated for DB normalization) users: id / username / password / realname / access_level users_access_level: access_level / access_name What I'm trying to do, is echo the data onto an HTML table that displays users.username in one table data and then uses the users.access_level to find users_access_level.access_name and echo into the following table data, I would prefer not to use multiple queries if possible or nested queries. Example row for users: 1234 / tmac / password / tmac / 99 Example row for users_access_level: 99 / Admin Using the examples above, I would want the output to appear as such: Username: Access Name: Tmac Admin I am not 100% sure where to start with this, but I pick up quickly, I just need a nudge in the right direction. The code I attempted to create just shows my lack of knowledge of joining tables, but I'll post it if you want to see that I did at least make an effort to code this myself. Thanks for reading! 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? 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? 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! 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. 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 On my xampp server's database I get the warning that my database is read-only when I try to insert something into a table. I think I may know what cause this, because I created an export/import app that exports/import important data to the database... How can I remove the read-only from the database, because I am scared that the same thing might happen to my server's database? And is there a mysql query that test if the database is read-only? Thanks in advance MOD: Thanks for moving to the correct forum - much appreciated! OK, I've taken a look around and cannot find a complete tutorial on how to do this. I have created a database with a table and the following fields; id, day, month, year, event, type What I am trying to do is read the data held in the table by referencing the type field (unique data), have it populate data firleds which are user editable and then once all changes are made have it update into the table. I can't imagine that this is that hard at all, but I cannot for the life of me figure it out! Anybody got a tutorial or some code which will do this? I am working on a simple web app in which I want to store about 20 variables in a MYSQL table so when I hand off the project the variables can be easily edited by the end user. Is it easy to store variables in a MYSQL table then query those and make them PHP variables? Really I just need to read a MYSQL table and pull two columns; AppOption and AppOptionValue then create PHP variables for each of the results making the AppOption the variable name and the AppOptionValue the value of said varible. Any Ideas? Thanks! Sean Once upon a time needed help on March 12, 2008 this community helped me, I am still a learner tried to help back but all the problems posted here beyond my skills to solve them so I kept quiet. and Now I need help once again hope I will get it done. Its PHPPOS developed in Codeigniter This code below is from application\controllers\inventory_summary.php file Code: [Select] <?php require_once("report.php"); class Inventory_summary extends Report { function __construct() { parent::__construct(); } public function getDataColumns() { return array($this->lang->line('reports_item_name'), $this->lang->line('reports_item_number'), $this->lang->line('reports_description'), $this->lang->line('reports_count'), $this->lang->line('reports_reorder_level')); } public function getData(array $inputs) { $this->db->select('name, item_number, quantity, reorder_level, description'); $this->db->from('items'); $this->db->where('deleted', 0); $this->db->order_by('name'); return $this->db->get()->result_array(); } public function getSummaryData(array $inputs) { return array(); } } ?> And this partial code below is from application\controllers\report.php file Code: [Select] function inventory_summary($export_excel=0) { $this->load->model('reports/Inventory_summary'); $model = $this->Inventory_summary; $tabular_data = array(); $report_data = $model->getData(array()); foreach($report_data as $row) { $tabular_data[] = array($row['name'], $row['item_number'], $row['description'], $row['quantity'], $row['reorder_level']); } $data = array( "title" => $this->lang->line('reports_inventory_summary_report'), "subtitle" => '', "headers" => $model->getDataColumns(), "data" => $tabular_data, "summary_data" => $model->getSummaryData(array()), "export_excel" => $export_excel ); $this->load->view("reports/tabular",$data); } } ?> Together they get the job done as follow: Item Name Item Number Description Count Reorder Level (Count is quantity in stock) Item 1 0002 xyz 5 3 Item 2 0s00 xyz 5 3 Item 3 0005 xyz 5 3 Item 4 0006 xyz 5 3 The output I want need to be like this: Item Name Item Number Description cost price Count Reorder Level Item 1 0002 xyz 250 5 3 Item 2 0s00 xyz 120 5 3 Item 3 0005 xyz 300 5 3 Item 4 0006 xyz 500 5 3 Total Stock Value 5850 Total Count 20 <-- this doesn't require any formation just needs to be at bottom of all the queries like shown here. This is what I want mainly >>>>>>>>>> Total Stock Value (cost price * count foreach and then sum of all results ) and sum of all count cost price table and column is different than one used above in the code which is: databse table is ' receivings_items ' Column is 'item_cost_price' example php code to fetch is : Code: [Select] $sql = "SELECT `item_cost_price` FROM `receivings_items`"; config.php contains all the connection variables to MySQL Please Help me I am having trouble trying to save my image file names to mysql after reading a dir. I am trying to use the file below.
Any help would be appreciated. I was originallly getting the files to list but they we not showing up in the database.
Now the page shows up blank.
<?php require("config_0.php"); // Connect to server and select database. mysql_connect($dbhost, $dbuser, $dbpass)or die("cannot connect"); mysql_select_db("test")or die("cannot select DB"); $files = glob("images/*.jpg"); for ($i=1; $i<count($files); $i++) { $num = $files[$i]; $sql="INSERT INTO images (url) VALUES ('$num')"; if (!mysql_query($sql)) { die('Error: ' . mysql_error()); } echo '<img src="'.$num.'" alt="random image">'." "; } ?> Hi Guys, I building a system, where i have a customer table where user info is saved, and customer can choose the package like silver, gold, and platinum customer table: ID Username Password Name Address Active Now i want to make a table for choosing packages: package table: Package_ID Package_Name Package_Description Package_Duration Package_Amount Package_Active 1.Now my doubt is, whether Duration can be kept in days/month for example: 90 days or January, February, March 2.Package_Amount: what currency to be specify. Because am building a system for international users, what currency to be specify. (500 INR or 10USD) 3. what about upgrade of package: give me some ideas how to handle this. Please Help me, and i guess i have a design a table right. Thanks, I have a MySQL database with each record of a person who has registered for an event, I am displaying the information on a web page for a user, but he wants to be able to print out all the records in alphabetical order by last name, first name later on so he will have a hard copy of each person who has registered at the table when they arrive. How can I write each record to a Txt file that he can print out later that will be formated with the record contents along with each fields definition (Ex. Last Name - Smith, First Name - John, etc)? I'm working on a web based RPG game, and I want the ability to run different "servers" but I'm not sure what the best way to go about it would be.
First idea: Create a table which would be named, "world" when a character is created, they get to choose a world to join, and then use world_id to know what items, mobs, npc, is in that world. Here is just a quick mock-up of the table.
Second idea: Create a whole new database for the game data, creature_game contains the accounts and forum data. While creature_server_x contains the rest of the game. The structure of each database would be exactly the same.
I want the people that runs the different "servers" to be able to do whatever changes they want, even if that would mean to rewrite the story line. I could do it with both the first and second idea. But I want to hear about what people here think is best and why. Ofc, they won't be able to access or change the tables inside the databases, just the data the tables contains.
|