PHP - Ordering Topics
Hi there! I'm still getting use to using multiple rows when ordering in SQL, but I have a question. How can I display topics that are stickied first, then display all the threads below ordered by lastpost?
I tried: //thread details $query = mysql_query("SELECT `date`,`lock`,`sticky`,`status`,`title`,`username`,`id`,`lastposter`,`lastpost` FROM threads WHERE parent = '{$_GET['forum']}' ORDER BY lastpost, sticky DESC LIMIT $start,$per_page") or die(mysql_error()); And the stickies do show up first, but all the regular threads aren't showing ordered by laspost DESC. Why is that? :/ Lastpost = datetime Similar Tutorialshi i am working on a project in which i have to retrieve the articles which are the most visited by the users. i have serched the internet but not find any useful code snippets. can any one guide me how to solve this problem. ok, so here is the basic concept I want, but it is not working, everything is bold when the database is set to 1 for $read........could you take a look and help?: Code: [Select] <?php include 'config.php'; include 'opendb.php'; // if no id is specified, list the available articles if(!isset($_GET['id'])) { $query = "SELECT * FROM messages WHERE recipient ='$name' order by date desc"; $result = mysql_query($query) or die('Error : ' . mysql_error()); // create the article list while($row = mysql_fetch_array($result, MYSQL_NUM)) { list($from1, $recipient, $title1, $content, $id, $date, $read) = $row; if ($read == $userid){ $content1 .= "<br /><br /> $from1</p>\r\n"; $content2 .= "<br /><br /> <a href=\"/message.php?id=$id\">$title1</a>\r\n"; }else { $content1 .= "<br /><br /> <strong>$from1</strong></p>\r\n"; $content2 .= "<br /><br /> <a href=\"/message.php?id=$id\">$title1</a>\r\n"; } So, you know how on forums (including this one) the icon of a topic/forum will be greyed out if your account viewed that topic's latest post, regardless of which computer you viewed it on? How exactly does it store that? I know that logically it would store it on the Database, but I'm curious as to the actual implementation. It seems to me that storing every single topic you viewed it and when would take up huge numbers of rows, even for a small number of people, like say 100. If you have a forum with 1000's of people, each viewing even 3 topics a day, you're record numbers would be huge, slowing down the database. And calling your last viewed time for each and ever topic? Wouldn't that slow down the code excecution heaps? If you have any input, I'd love to hear it. It's a question I've been wrestling with in the back of my mind for a few years now I am almost done with my website and I will use this thread to post small enhancements that would make my website better.........so #1, I have a code that will display news topics, how can I redo this code so that the topics are in reverse order and so that the title will be in bold lettering until it is read? Code: [Select] <?php session_start(); // Must start session first thing /* Created By Adam Khoury @ www.flashbuilding.com -----------------------June 20, 2008----------------------- */ // Here we run a login check if (!isset($_SESSION['id'])) { echo 'Please <a href="login.php">log in</a> to access your account'; exit(); } //Connect to the database through our include include_once "connect_to_mysql.php"; // Place Session variable 'id' into local variable $userid = $_SESSION['id']; // Query member data from the database and ready it for display $sql = mysql_query("SELECT * FROM members WHERE userid='$userid' LIMIT 1"); while($row = mysql_fetch_array($sql)){ $name = $row["name"]; $phone = $row["phone"]; $username = $row["username"]; $address = $row["address"]; $city = $row["city"]; $state = $row["state"]; $zip = $row["zip"]; $cell = $row["cell"]; $email = $row["email"]; $accounttype = $row["accounttype"]; $rank = $row["rank"]; $badges = $row["badges"]; } ?> <?php include 'config1.php'; include 'opendb.php'; // if no id is specified, list the available articles if(!isset($_GET['id'])) { $self = $_SERVER['PHP_SELF']; $query = "SELECT id, title FROM news ORDER BY id"; $result = mysql_query($query) or die('Error : ' . mysql_error()); // create the article list $content = '<ol>'; while($row = mysql_fetch_array($result, MYSQL_NUM)) { list($id, $title) = $row; $content .= "<li><a href=\"$self?id=$id\">$title</a></li>\r\n"; } $content .= '</ol>'; $title = 'News'; } else { // get the article info from database $query = "SELECT title, content FROM news WHERE id=".$_GET['id']; $result = mysql_query($query) or die('Error : ' . mysql_error()); $row = mysql_fetch_array($result, MYSQL_ASSOC); $title = $row['title']; $content = $row['content']; } include 'closedb.php'; ?> Code: [Select] <table width="600" border="0" align="center" cellpadding="10" cellspacing="1" bgcolor="#336699"> <tr> <td bgcolor="#FFFFFF"> <h1 align="center"><?php echo $title; ?></h1> <?php echo $content; // when displaying an article show a link // to see the article list if(isset($_GET['id'])) { ?> <p> </p> <p align="center"><a href="<?php echo $_SERVER['PHP_SELF']; ?>">Back to News</a></p> <?php } ?> so once this topic is resolved.......I will probably post another small topic to look at. What I'm trying to figure out how to do is near the bottom of the script where it has a for loop for numSegments and the dropdown for the sortOrder for each one. What the options are supposed to fill is the amount of matches or the event. So the option text would be "Match 1" or however many down with the numMatches variable I guess. And the option would just be the number of the match. Code: [Select] <?php require ('php/bookings.php'); ?> <script type="text/javascript"> function Competitors(matchNum) { function isDupe(which) { var result = false; $('ul#competitors'+ matchNum +' li').each(function(i, e) { if ($(e).attr('characterID') == which) { result = true; return false; // break out of .each() } }); return result; } var characterID = $('#charactersDrop'+ matchNum +' option:selected').val(); var characterName = $('#charactersDrop'+ matchNum +' option:selected').text(); if (characterID > 0 && !isDupe(characterID)) { // Create the anchor element var anchor = $( '<a href="#">Remove</a>' ); // Create a click handler for the anchor element anchor.click( function() { $( this ).parent().remove(); return false; // makes the href in the anchor tag ignored } ); // Create the <li> element with its text, and then append the anchor inside it. var li = $( '<li>' + characterName + ' </li>' ).append( anchor ); li.attr ('characterID', characterID ); // Append the new <li> element to the <ul> element $('#competitors'+ matchNum).append( li ); } } function TitlesDefended(matchNum) { function isDupe(which) { var result = false; $('ul#titlesDefended'+ matchNum +' li').each(function(i, e) { if ($(e).attr('titleID') == which) { result = true; return false; // break out of .each() } }); return result; } var titleID = $('#titlesDrop'+ matchNum +' option:selected').val(); var titleName = $('#titlesDrop'+ matchNum +' option:selected').text(); if (titleID > 0 && !isDupe(titleID)) { // Create the anchor element var anchor = $( '<a href="#">Remove</a>' ); // Create a click handler for the anchor element anchor.click( function() { $( this ).parent().remove(); return false; // makes the href in the anchor tag ignored } ); // Create the <li> element with its text, and then append the anchor inside it. var li = $( '<li>' + titleName + ' </li>' ).append( anchor ); li.attr( 'titleID', titleID ); // Append the new <li> element to the <ul> element $( '#titlesDefended'+ matchNum ).append( li ); } } function StipulationsAdded(matchNum) { function isDupe(which) { var result = false; $('ul#stipulationsAdded'+ matchNum +' li').each(function(i, e) { if ($(e).attr('stipulationID') == which) { result = true; return false; // break out of .each() } }); return result; } var stipulationID = $('#stipulationsDrop'+ matchNum +' option:selected').val(); var stipulationName = $('#stipulationsDrop'+ matchNum +' option:selected').text(); if (stipulationID > 0 && !isDupe(stipulationID)) { // Create the anchor element var anchor = $( '<a href="#">Remove</a>' ); // Create a click handler for the anchor element anchor.click( function() { $( this ).parent().remove(); return false; // makes the href in the anchor tag ignored } ); // Create the <li> element with its text, and then append the anchor inside it. var li = $( '<li>' + stipulationName + ' </li>' ).append( anchor ); li.attr( 'stipulationID', stipulationID ); // Append the new <li> element to the <ul> element $( '#stipulationsAdded'+ matchNum ).append( li ); } } $(document).ready(function() { $('div.message-error').hide(); $('div.message-success').hide(); $('li').remove('.titleName'); $('li').remove('.stipulationName'); $('li').remove('.characterName'); $("#bookerForm").validate({ rules: { introduction: { required: true }, matchtypeID: { required: true }, liCompetitors: { required: true }, matchwriterID: { required: true }, matchTitle: { required: true }, preview: { required: true }, segment: { required: true } }, messages: { introduction: "Please enter the event introduction!", matchtypeID: "Please choose the type of match!", liCompetitors: "Please choose atleast 2 competitors!", matchwriterID: "Please choose a match writer!", matchTitle: "Please enter a match title!", preview: "Please enter a preview!", segment: "Please choose a segment writer!" }, submitHandler: function(form) { var eventName = $("#event").val(); var eventID = $("#eventID").val(); var introduction = $("#introduction").val(); var type = $("#type").val(); var matchNumX = new Array; var matchTypeIDX = new Array; var titlesIDListX = new Array; var stipulationsIDListX = new Array; var competitorsIDListX = new Array; var matchWriterIDX = new Array; var matchTitleX = new Array; var previewX = new Array; var segmentArrayX = new Array; var masterIndex = 0; var masterArray = []; for(i=0;i<<?php echo $numMatches ?>; i++) { var matchNum = i + 1; var matchTypeID = $('select#matchTypeDrop'+ matchNum).val(); var liTitles = $('ul#titlesDefended'+ matchNum +' li'); var titlesIDList = ""; var j = 0; $('ul#titlesDefended'+ matchNum +' li').each(function(){ var liTitle = $( liTitles[ j ] ); // only start appending commas in after the first characterID if( j > 0 ) { titlesIDList += ","; } // append the current li element's characterID to the list titlesIDList += liTitle.attr( 'titleID' ); j++; }); var j = 0; var liStipulations = $('ul#stipulationsAdded'+ matchNum +' li'); var stipulationsIDList = ""; $('ul#stipulationsAdded'+ matchNum +' li').each(function(){ var liStipulation = $( liStipulations[ j ] ); // only start appending commas in after the first characterID if( j > 0 ) { stipulationsIDList += ","; } // append the current li element's characterID to the list stipulationsIDList += liStipulation.attr( 'stipulationID' ); j++; }); var j = 0; var liCompetitors = $('ul#competitors'+ matchNum +' li'); var competitorsIDList = ""; $('ul#competitors'+ matchNum +' li').each(function(){ var liCompetitor = $( liCompetitors[ j ] ); // only start appending commas in after the first characterID if( j > 0 ) { competitorsIDList += ","; } // append the current li element's characterID to the list competitorsIDList += liCompetitor.attr( 'characterID' ); j++; }); var matchWriterID = $('select#matchWriter' + matchNum + '').val(); var matchTitle = $('input#matchTitle'+ matchNum +'').val(); var preview = $('textarea#preview'+ matchNum +'').val(); matchNumX.push(matchNum); matchTypeIDX.push(matchTypeID); titlesIDListX.push(titlesIDList); stipulationsIDListX.push(stipulationsIDList); competitorsIDListX.push(competitorsIDList); matchWriterIDX.push(matchWriterID); matchTitleX.push(matchTitle); previewX.push(preview); masterArray[masterIndex] = new Object(); masterArray[masterIndex]['matchNum'] = matchNumX; masterArray[masterIndex]['matchtypeID'] = matchTypeIDX; masterArray[masterIndex]['titlesIDList'] = titlesIDListX; masterArray[masterIndex]['stipulationsIDList'] = stipulationsIDListX; masterArray[masterIndex]['competitorsIDList'] = competitorsIDListX; masterArray[masterIndex]['matchWriterID'] = matchWriterIDX; masterArray[masterIndex]['matchTitle'] = matchTitleX; masterArray[masterIndex]['preview'] = previewX; } var dataString = 'masterArray=' + masterArray; dataString += '&eventID=' + eventID + '&introduction=' + introduction + '&submitBooking=True'; console.log( masterArray ); $.ajax({ type: "POST", url: "processes/bookings.php", data: dataString, success: function() { $('div.message-error').hide(); $("div.message-success").html("<h6>Operation successful</h6><p>" + eventName + " saved successfully.</p>"); $("div.message-success").show().delay(10000).hide("slow"); return true; } }); return false; } }); }); </script> <p class="listInfos"> Card Lineup for <?php echo "".$event." on ".$bookingDate."" ?> </p> <!-- Form --> <form action="#" id="bookerForm" > <fieldset> <legend>Introduction</legend> <div class="field required"> <label for="introduction">Introduction:</label> <textarea name="introduction" id="introduction" title="Introduction"></textarea> <span class="required-icon tooltip" title="Required field - This field is required, it cannot be blank, and must contain something that is different from emptyness in order to be filled in. ">Required</span> </div> </fieldset> <?php for( $i = 0; $i < $numMatches; $i++ ) { ?> <fieldset> <legend>Match #<?php echo $i+1 ?></legend> <div class="field required"> <label for="matchTypeDrop<?php echo $i+1 ?>">Match Type:</label> <select class="dropdown" name="matchTypeDrop<?php echo $i+1 ?>" id="matchTypeDrop<?php echo $i+1 ?>" title="Match Type <?php echo $i+1 ?>"> <option value="">- Select -</option> <?php mysqli_data_seek( $matchtypesResult, 0 ); while ( $row = mysqli_fetch_array ( $matchtypesResult, MYSQL_ASSOC ) ) { print "<option value=\"".$row['ID']."\">".$row['matchType']."</option>\r"; } ?> </select> <span class="required-icon tooltip" title="Required field - This field is required, it cannot be blank, and must contain something that is different from emptyness in order to be filled in. ">Required</span> </div> <div class="field required"> <label for="titlesDefended<?php echo $i+1 ?>">Title On The Line:</label><ul id="titlesDefended<?php echo $i+1 ?>" style="list-style: none; margin-left: 195px;"></ul> <select class="dropdown" name="titlesDrop<?php echo $i+1 ?>" id="titlesDrop<?php echo $i+1 ?>" title="Titles Dropdown <?php echo $i+1 ?>" style="margin-left: 195px;"> <option value="">- Select -</option> <?php mysqli_data_seek( $titlesResult, 0 ); while ( $row = mysqli_fetch_array ( $titlesResult, MYSQL_ASSOC ) ) { print "<option value=\"".$row['ID']."\">".$row['titleName']."</option>\r"; } ?> </select> <input type="button" value="Add Title" class="" onclick="TitlesDefended(<?php echo $i+1?>)"/> </div> <div class="field required"> <label for="stipulationsAdded<?php echo $i+1 ?>">Stipulation:</label><ul id="stipulationsAdded<?php echo $i+1 ?>" style="list-style: none; margin-left: 195px;"></ul> <select class="dropdown" name="stipulationsDrop<?php echo $i+1 ?>" id="stipulationsDrop<?php echo $i+1 ?>" title="Stipulations Dropown <?php echo $i+1 ?>" style="margin-left: 195px;"> <option value="">- Select -</option> <?php mysqli_data_seek( $stipulationsResult, 0 ); while ( $row = mysqli_fetch_array ( $stipulationsResult, MYSQL_ASSOC ) ) { print "<option value=\"".$row['ID']."\">".$row['stipulation']."</option>\r"; } ?> </select> <input type="button" value="Add Stipulation" class="" onclick="StipulationsAdded(<?php echo $i+1 ?>)"/> </div> <div class="field required"> <label for="competitors<?php echo $i+1 ?>">Competitors:</label><ul id="competitors<?php echo $i+1 ?>" style="list-style: none; margin-left: 195px;"></ul> <select class="dropdown" name="charactersDrop<?php echo $i+1 ?>" id="charactersDrop<?php echo $i+1 ?>" title="Characters Dropdown <?php echo $i+1 ?>" style="margin-left: 195px;"> <option value="">- Select -</option> <?php mysqli_data_seek( $charactersResult, 0 ); while ( $row = mysqli_fetch_array ( $charactersResult, MYSQL_ASSOC ) ) { print "<option value=\"".$row['ID']."\">".$row['characterName']."</option>\r"; } ?> </select> <span class="required-icon tooltip" title="Required field - This field is required, it cannot be blank, and must contain something that is different from emptyness in order to be filled in. ">Required</span> <input type="button" value="Add Character" class="" onclick="Competitors(<?php echo $i+1 ?>)"/> </div> <div class="field required"> <label for="matchWriter<?php echo $i+1 ?>">Match Writer:</label> <select class="dropdown" name="matchWriter<?php echo $i+1 ?>" id="matchWriter<?php echo $i+1 ?>" title="Match Writer <?php echo $i+1 ?>"> <option value="0">- Select -</option> <?php mysqli_data_seek( $matchwriterResult, 0 ); while ( $row = mysqli_fetch_array ( $matchwriterResult, MYSQL_ASSOC ) ) { print "<option value=\"".$row['ID']."\">".$row['name']."</option>\r"; } ?> </select> <span class="required-icon tooltip" title="Required field - This field is required, it cannot be blank, and must contain something that is different from emptyness in order to be filled in. ">Required</span> </div> <div class="field required"> <label for="matchTitle<?php echo $i+1 ?>">Match Title</label> <input type="text" class="text" name="matchTitle<?php echo $i+1 ?>" id="matchTitle<?php echo $i+1 ?>" title="Match Title<?php echo $i+1 ?>"/> <span class="required-icon tooltip" title="Required field - This field is required, it cannot be blank, and must contain something that is different from emptyness in order to be filled in. ">Required</span> </div> <div class="field required"> <label for="preview<?php echo $i+1 ?>">Preview:</label> <textarea name="preview<?php echo $i+1 ?>" id="preview<?php echo $i+1 ?>" title="preview <?php echo $i+1 ?>"></textarea> <span class="required-icon tooltip" title="Required field - This field is required, it cannot be blank, and must contain something that is different from emptyness in order to be filled in. ">Required</span> </div> <input type="hidden" name="type" id="type" value="Match" /> </fieldset> <?php } ?> <?php if ($numSegments > 0) { ?> <?php for( $i = 0; $i < $numSegments; $i++ ) { ?> <fieldset> <legend>Segment <?php echo $i+1 ?></legend> <div class="field required"> <label for="segmentWriter<?php echo $i+1 ?>">Segment Writer<?php echo $i+1 ?>:</label> <select class="dropdown" name="segmentWriter<?php echo $i+1 ?>" id="segmentWriter<?php echo $i+1 ?>" title="Segment Writer <?php echo $i+1 ?>"> <option value="0">- Select -</option> <?php mysqli_data_seek( $matchwriterResult, 0 ); while ( $row = mysqli_fetch_array ( $matchwriterResult, MYSQL_ASSOC ) ) { print "<option value=\"".$row['ID']."\">".$row['name']."</option>\r"; } ?> </select> <span class="required-icon tooltip" title="Required field - This field is required, it cannot be blank, and must contain something that is different from emptyness in order to be filled in. ">Required</span> </div> <div class="field required"> <label for="segmentOrder">Segment After:</label> <select class="dropdown" name="sortOrder" id="sortOrder" title="Sort Order"> <option value="0">- Select -</option> </select> <span class="required-icon tooltip" title="Required field - This field is required, it cannot be blank, and must contain something that is different from emptyness in order to be filled in. ">Required</span> </div> <input type="hidden" name="type" id="type" value="Segment" /> </fieldset> <? } ?> <?php } ?> <fieldset> <input type="hidden" name="eventID" id="eventID" value="<?php echo $eventID; ?>" /> <input type="hidden" name="event" id="event" value="<?php echo $event; ?>" /> <input type="submit" class="submit" name="submitBooking" id="submitBooking" title="Submit Booking" value="Submit Booking"/> </fieldset> </form> <!-- /Form --> <!-- Messages --> <div class="message message-error"> <h6>Required field missing</h6> <p>Please fill in all required fields. </p> </div> <div class="message message-success"> <h6>Operation succesful</h6> <p>Booking was added to the database.</p> </div> <!-- /Messages --> I have a code Code: [Select] <?php include('dbcon.php'); $sql = mysql_query("select * from money ORDER BY sno DESC "); $num=mysql_num_rows($sql); $snumb=0; echo '<form method="post" action="edit.php?action=trunc">'; echo '<input type="submit" value="TRUNCATE TEABLE">'; echo '</form>'; echo '<form method="post" action="del_mul.php">'; echo "<table border='1' id=hor-minimalist-a style=width:1200px> <tr> <th> S No. </th> <th> Act. ID </th> <th>Jisne Diye</th> <th>Kisko diye</th> <th>Kitne Diye </th> <th>Wajah </th> <th>Kisne bhare iss site main </th> <th>Kiss time pe </th> <th>Delete Entry</th> <th>Sel for Operation</th> </tr>"; while($row = mysql_fetch_array($sql)) { ++$snumb; echo "<tr>"; echo "<td>" . $snumb. "</td>"; echo "<td>" . $row['sno'] . "</td>"; echo "<td>" . $row['name1'] . "</td>"; echo "<td>" . $row['name2'] . "</td>"; echo "<td>" . $row['amm'] . "</td>"; echo "<td>" . $row['rea'] . "</td>"; echo "<td>" . $row['usname'] . "</td>"; echo "<td>" . $row['time'] . "</td>"; echo "<td><a href=edit.php?id=" . $row['sno'] . "&action=del>DELETE</a></td>"; echo '<td><input type="checkbox" name="mul_arr[]" value='.$row[sno].'></td>'; echo "</tr>"; } echo '<input type="submit" value="DELETE SELECTED">'; echo '</form>'; ?> In this i thought that the "DELETE SELECTED" button should be below to the table but the button is getting printed above the Table... Why is it so.......?????????????? And how to fix it ???????????? - Pranshu Agrawal pranshu.a.11@gmail.com Here is question: i have db articles and categories. Now at categories i have: - id - name - info and at articles there a - id - cat_id - name - description - date Now i wonna get all articles like "SELECT * FROM articles", but i wonna order it by categories name, how can i do that? I am ordering a table by 2 different functions and am having a lot of trouble ORDER BY Level DESC, Won/(Won+Lost) ASC There has to be a simple solution for this problem that I am apparently too dense to figure out... Say on a single page, I have code like this... Code: [Select] <div id="stuff"> //stuff </div> and then further down on the page, I have code that runs and produces a variable ($i) that is a number. I then want to check to see if that number is 10 or higher, or not, (which I can handle doing ) and if it is 10 or higher, then I want to hide the "stuff" div that is further up on the page. What is the best way to do this? It's like I need the code to run and then go back and add something to the "stuff" div to make it not show, if the variable is 10 or higher. Any thoughts? This has to be easy so I"m feeling particularly newbie tonight Code: [Select] if ($i >=10) { //the number is 10 or higher so let's somehow hide the "stuff" div that is further up on the page. but how? :) } else { // the number is less than 10 so it's cool to continue to display the "stuff" div } Hi I have an array which pull data from a DB (which I didn't create nor can modify) I need to be able to export it to an excel sheet with the data in a specified order. how do I do this? eg run sql queries and end up with array which would be - a [1] - b [2] - c [3] - d [4] - e how would I be able to specify the order eg d , a, c, e, b. to match it up with the column headers on the excel sheet? To make it more of a challenge, I can't amend the column headers either. I can only manipulate the array. I will be pulling multiple arrays out and not all have all the value is them!!! Deep Deep Joy!!! Hi, i have been thinking on ways to make an ordering system for my web site. The code bellow shows how i populate the page. i desplay the pizza's from the data base. i want at the end of each line a box thati allows the user to pick howmany pizzas they want. from they when they click order i want it to send all the information of what they want so they can double check it and when they click the final order button it will send to a diffrent order table. Code: [Select] <? session_start(); if ($_SESSION['userName']) {} else { header('location:../index.php'); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Deliver-Pizza Topping</title> <link href="css/pizza-topping.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="container"> <div id="header"> <img src="images/logo.jpg" alt="logo" /> <a href="log-off.php" id="logg-off" >log off</a> <ul id="nav"> <li><a href="home.php" target="_self">Home</a></li> <span> | </span> <li><a href="Pizza-Topping.php" target="_self">Pizza Topping</a></li> <span> | </span> <li><a href="order.php" target="_self">Order</a></li> <span> | </span> <li><a href="Account.php" target="_self">Account Details</a></li> <span> | </span> </ul> </div> <div id="Featured"> <img src="images/banner1.jpg" alt="banner" name="banner"" ID="banner"></div><!--end Featured--> <div class="featuredimage" id="main"> <div id="content" class="tiles"> <h1>Pizza-Topping</h1><hr /> <p>Please select the pizza you would like bellow</p> <div id ="staff"><div style="width:970px; height:300px; overflow:auto" <left> <table> <tr> <th>Type</th> <th>Size</th> <th>Topping</th> <th>Cost</th> <th>Information</th> <th>Order</th> </tr> <tr> <form name="input" action="order.php" method="post"> <?php mysql_connect("localhost", "root", "")or die("cannot connect"); mysql_select_db("deliverpizza")or die("cannot select DB"); $sql="SELECT * FROM `pizzatopping` "; $result= mysql_query($sql); while($row =mysql_fetch_assoc($result)) { ?> <td><?php echo $row['type'] ?></td> <td><?php echo $row['size'] ?></td> <td><?php echo $row['topping'] ?></td> <td><?php echo $row['cost'] ?></td> <td><?php echo $row['info'] ?></td> <td> <input type:"text" name:"pizza<?php echo $row['id'] ?>" /></td> </tr></left> <?php } ?> <input type="submit" value="Order" /> </table> </div> </div> </div> </div> <!--end content--> <div id="footer"><span><p>Created By Ryan Williams</p></span></div><!--end footer--> </div><!--end container--> </body> </html> Help please I've got a file that I haven't worked on in awhile and am needing to make a little change to it. Not too sure of how to do it though. The portion of the script I am looking at should be this: Code: [Select] $indexH[$var][] = array('firstname' => "$r2[firstname]", 'lastname' => "$r2[lastname]", 'number' => "$r2[number]", 'id' => "$r2[id]", 'q1' => "$r2[q1]", 'q2' => "$r2[q2]", 'q3' => "$r2[q3]", 'q1rt' => "$r2[q1rt]", 'q2rt' => "$r2[q2rt]", 'q3rt' => "$r2[q3rt]", 'q1s' => "$r2[q1s]", 'q2s' => "$r2[q2s]", 'q3s' => "$r2[q3s]", 'regid' => "$r2[regid]", 'eventid' => "$r2[eventid]"); Code: [Select] $ir = 0; foreach ( $indexH[$var] as $val ){ $q1 = $val[q1]; $q2 = $val[q2]; $q3 = $val[q3]; $var2 = substr($var,0,5); $var2 = substr_replace($var2, "0", 4, 1); if ($q1 < "$var2") { $q1 = '99.999'; } else { $q1 = $val[q1]; } if ($q2 < "$var2") { $q2 = '99.999'; } else { $q2 = $val[q2]; } if ($q3 < "$var2") { $q3 = '99.999'; } else { $q3 = $val[q3]; } if (($q1 == $q2) && ($q1 == $q3)) { $indexH[$var][$ir][bq] = "$q1"; } elseif (($q1 <= $q2) && ($q1 <= $q3)) { $indexH[$var][$ir][bq] = "$q1"; } elseif ($q2 <= $q3) { $indexH[$var][$ir][bq] = "$q2"; } else { $indexH[$var][$ir][bq] = "$q3"; } $ir++; } foreach ($indexH[$var] as $key => $value) { uasort($indexH[$var], 'compare'); } This is taking three dfferent values (q1, q2, q3) getting the best value of the three and then sorting the array based on the best value chosen. Now the addition. If two entries in the array have the same best value resulting in a tie, I need to compare their qXs from that best value, higher qXs gets put above the lower. X = 1,2,3 depending on which is best value. If any more information is needed let me know, sort of hard to explain. Hi, I am using multiple rows in my table and I want to order it in ascending order from a column. With SQL statement it is simple as saying ORDER BY column but how I can do this with just numbers? So I want for example: (goes in correct order) Col 1 Col 2 Col3 # 5 # # 43 # # 87 # # 113 # instead of: Col 1 Col 2 Col3 # 113 # # 43 # # 87 # # 5 # Thanks for any help!! Hi all, I've got a couple of these event entries with dates attached to them in the format of day-month-year (example: 31-01-2001) and I've got a script to display the name+date in a list. How could I go about making it so that it orders by the oldest on top like: Event A October 5, 2011 - October 8, 2011 Event B October 6, 2011 - October 7, 2011 Event C October 9, 2011 - December 1, 2011 Any help would be appreciated I have a lottery PHP script which i have been creating. The lottery contains four different numbers in which are four different fields in my database. On the random ticket buy the code for the four numbers are like this $ticketone = rand(1,25); $tickettwo = rand(1,25); $ticketthree = rand(1,25); $ticketfour = rand(1,25); I am wanting to do it so they can be put in order and then imported into my database in that right order. For example, If ticketone was 20, an tickettwo was 13, i would want it to be imported into the database so that ticketone would be 13. (being put into order) and ticket two would be 20 etc....
I've a php "program" that helps me manage sales.
php file in pdf: https://we.tl/t-D4xTtG3Ync Hi Guys, I am to ordering list things by date from my database i.e. from 01/08/2011 to 31/08/2011. I now have dates which are next years date such as 05/01/2012 and 09/01/2011 and this is causing problems it doesnt order correctly. The date 05/01/2012 come right after 04/08/2011 and 09/01/2012 comes right after 08/08/2011 which is not what I want it to do. Is there any way I can put the dates in the proper order so the dates for next year appear mixed up with these years dates. Thanks Hi everyone, I'm making an admin page which will contain a number of articles. Unlike most sites, these articles won't be ordered based on date, but however the admin wishes. To do this I've added an order column to the mysql, in the admin page all the articles are displayed and next to them a text input, with the value set to their current order number (1,2,3, 4 etc) Here's selections of the code <?php $o = $_GET['o']; if($o == 'new') { $order1 = $_POST['order1']; $update = "UPDATE `content` SET `order` = '$order1' WHERE `id` = '1'"; $result=mysql_query($update) or die(mysql_error()); } ?> <form method="post" action="?o=new" name="order_form"> <!-- CONTENT --> <div id="content"> <?php $sql="SELECT * FROM `content` ORDER BY `order` ASC"; $result=mysql_query($sql); while($rows=mysql_fetch_array($result)){ ?> <ul> <li class="article_left"> <input type="text" value="<?php echo $rows['order']; ?>" name="order<?php echo $rows['id']; ?>" class="order"> </li> <li class="article_left_title"> <?php echo $rows['title']; ?> </li> <li <?php if ($rows['live'] == '1') { echo 'class="live"'; }else echo 'class="launch"'; ?>> <?php if ($rows['live'] == '1') { echo 'Now Live'; }else { echo 'Launch'; } ?> </li> <div class="clear"></div> </ul> <?php } ?> </div> <!-- END CONTENT --> <div id="submit_order"> <input type="submit" name="submit" value="Submit Re-Order"> </div> </form> My problem is hard to explain, but as you can tell $update only does it for the first article. How can I make it change the `order` column for all the articles. Feel free to ask more questions. Would really appreciate any help! I have an Job, which i need some help with.
Its an ordering system.
its probably really simple to do, and i even know how i want it set up.
all databases are setup.
i cant pay much but my payment will be : 178.59 dollar
which in this point of time is calculated from 1000 dkk
the task:
an ordering system which contains:
selection menu - to select an activity, stored in an database an starting time textfield. just a normal textfield i guess a selection menu - for package selection- wich will find the packages in the package database with the matching target id for the selected Activity a textfield for amount of people participating, as a multiplier for the price. a selection menu - for additions selecting. same as the Package selector. and an price field this is in one row, where there should be a way to add these, so that its possible to get more acticity orderes + an Total amount field all this data should then be viewable in a table, which ill create, and after that be able to be send through an email that is setup in html, which ill make:) Why i need help: i took my hands full with this project, and im leaving soon for thailand, and that is why im a bit screwed;/ hope to hear from somone fast many thanks Joachim Gerber How can I order this query of zip codes within the radius by nearest? /** * Get Zipcode By Radius * @param string $zip US zip code * @param ing $radius Radius in miles * @return array List of nearby zipcodes */ protected function get_zipcodes_by_radius ( $zip, $radius ) { $sql = 'SELECT distinct(zip) FROM zip_codes WHERE (3958*3.1415926*sqrt((latitude-'.$zip->latitude.')*(latitude-'.$zip->latitude.') + cos(latitude/57.29578)*cos('.$zip->latitude.'/57.29578)*(longitude-'.$zip->longitude.')*(longitude-'.$zip->longitude.'))/180) <= '.$radius.';'; $zip_codes = array(); if ( $result = $this->db->query( $sql ) ) { while( $row = $result->fetch_object() ) { array_push( $zip_codes, $row->zip ); } $result->close(); } return $zip_codes; }
|