PHP - Show First Letter Of A List Once?
hi,
I have a list of towns and need to get the first letter from each town and just display it once before the start of that lettered group ie; what I have: Aberdeen Arundel Aberyswith Bath Bristol Brighton Cardiff coventry what I would like: A Aberdeen Arundel Aberyswith B Bath Bristol Brighton C Cardiff coventry here is the code which writes out my list: Code: [Select] <ul class="edgetoedge"> <?php while($row1 = mysql_fetch_array($locals)) { echo '<li class="forward"><a href="townpubs.php?RSTOWN='.$row1['RSTOWN'].'" rel="external">'.$row1['RSTOWN'].'<small class="listcounter">'.$row1['PubCount'].'</small></a></li>'; } ?> </ul> Similar TutorialsI have got this far that my code shows the list but say nothing starts with the letter 'y' then all of the 'x' and 'z' are grouped in the list. can anyone suggest a better way to have the list show correctly. the 'multiItemBoxes' css class is a rounded box that shows around each letter group. here is me code. Code: [Select] // $letters = array(); $letters = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ "; $L = 1; ?><div class="multiItemBoxes"><? // place first part of DIV. $previousLetter = "/"; // set previousLetter to the letter before '0' zero. used as a dummy string. while($results = mysql_fetch_assoc($getResults)) { if ($previousLetter == "/") { ?><strong style="font-size: 15pt;"><? echo(strtoupper($results['productTitle'][0])); ?></strong><br /><? } if (strtoupper($results['productTitle'][0]) == $letters[$L]) { ?></div><? // this is the ending of the DIV. If needed. ?><br class="clearfloat" /> <? if (strtoupper($results['productTitle'][0]) != " ") { ?><div class="multiItemBoxes"><strong style="font-size: 15pt;"><? echo(strtoupper($results['productTitle'][0])); ?></strong><br /><? $L++; } // this is the extra DIV start if not at end of DB list. } ?><a href="<? echo("cart.php?query=" . $results['Pid']); ?><? echo("&"); ?>i=y"><? echo(htmlspecialchars($results['productTitle'])); ?></a><br /><? $previousLetter = $results['productTitle'][0]; } // end of while ?></div><br class="clearfloat" /><? // hello, im trying to see if there is a function that can get the value of the last row in mysql and see what is in field initial (this is letters A-Z) and make it one letter higher. then, when it reaches letter Z, wrap around to A again. I am using Concrete5 on a site I'm working on. Below is the News List display view.php file needed in the block to display the content from news pages. The code allows images entered in the WSYIWYG to appear in the RSS list. I want to know how I can edit the code below, so it shows only the these images from the $content not the text. Can anybody help me on this? Thanks <?php defined('C5_EXECUTE') or die("Access Denied."); $html = Loader::helper('html'); $uh = Loader::helper('concrete/urls'); $bt = BlockType::getByHandle('news_list'); global $c; $rss_address = $controller->getRssUrl().'?ctID='.$ctID.'&bID='.$bID ; if (isset($_GET['pageno'])) { $pageno = $_GET['pageno']; } else { $pageno = 1; } // if ?> <div class="newsflash"> <div class="headtitle"> <h1><?php echo $rssTitle ?></h1> </div> <?php if (!function_exists('newslistParse')) { function newslistParse($url,$thumbnail,$thumbwidth,$time,$content,$title,$date){ //###################################################################################// //here we lay out they way the page looks, html with all our vars fed to it // //this is the content that displays. it is recommended not to edit anything beyond // //the content parse. Feel free to structure and re-arrange any element and adjust // //CSS as desired. // // available vars: $url,$thumbnail,$thumbwidth,$time,$content,$title,$date // //###################################################################################// ?> <div class="newsflashcontain"> <div class="title"> <?php echo $title ; ?> </div> <div class="time"> <?php echo $date ; ?><?php echo $time ; ?> </div> <div class="description"> <?php echo $content; ?> </div> </div> <?php //#####################################################################################// //this is the end of the recommended content area. please do not edit below this line // //#####################################################################################// } } $db = Loader::db(); //go grab the posts, check if they are current, return only current posts Loader::model('newzy','simplenews'); $news = NewsCheck::getCurrentBlocks($ctID,$ordering); //count the number of current posts returned $pcount = count($news); //if no events are returned, then we display a user defined message if($pcount==0){ echo $nonelistmsg; } //now calc the last page $lastpage = ceil($pcount/$num); //set the current page min max keys -1 as array key's start @ 0 $sKey = $num * ($pageno-1) ; $eKey = ($num * ($pageno-1)) + ($num-1) ; //take each current post and treat it like a query, for each one do X foreach($news as $key => $row){ //check for external URL, if none, rout to parent page if(!empty($row['urlLink'])){ $url = $row['urlLink']; }else{ $url = $controller->grabURL($row['cParentID']); } //check if thumbnail is there, if so get it, if not, null if($row['graphic']>0){ $thumbnail = $controller->getThumbnail($row['graphic']); }else{ $thumbnail = NULL; } //set vars $time = $controller->replaceTimeString($row['nbID']); $date = $row['sdt']; $title = $row['title']; //$content = strip_tags($controller->translateFrom($row['content'])); $content = $controller->translateFrom($row['content']); //if truncation is enabled if($truncateSummaries == 1){ if (strlen($content) >= $truncateChars){ //truncate to suplied truncation value //$content = substr($content,0,$truncateChars).'.....'; $content = wordwrap($content, $truncateChars); $content = substr($content, 0, strpos($content, "\n")).'.....'; } } //check if paging is enabled if($isPaged){ //check to make sure the array key is within the range if($key >= $sKey && $key <= $eKey){ newslistParse($url,$thumbnail,$thumbwidth,$time,$content,$title,$date); } //if paging is not selected, use number of items designated in the list block }else{ $i += 1; newslistParse($url,$thumbnail,$thumbwidth,$time,$content,$title,$date); //once we reach the set number stop the script if($i >= $num){ break; } } } ?> </div> <?php //is iCal feed option is sellected, show it if($showfeed==1){ ?> <div class="rssfeed"> <img src="<?php echo $uh->getBlockTypeAssetsURL($bt, 'rss.png');?>" width="14" height="14" alt="rss feed" /> <a href="<?php echo $rss_address ; ?>" id="getFeed">Get this Feed</a> <link href="<?php echo $controller->getRssUrl();?>" rel="alternate" type="application/rss+xml" title="<?php echo t('RSS');?>" /> </div> <?php } //$c = Page::getCurrentPage(); $link = Loader::helper('navigation')->getLinkToCollection($c); $link = $controller->URLfix($link); //if pagination is set, if it is needed, show it if($isPaged==1){ if ($pcount > $num) { echo '<div id="pagination">'; if ($pageno == 1) { echo " FIRST PREV "; } else { echo '<a href="'.$link.'pageno=1">FIRST </a>'; $prevpage = $pageno-1; echo '<a href="'.$link.'pageno='.$prevpage.'"> PREV</a>'; } // if echo ' ( Page '.$pageno.' of '.$lastpage.' ) '; if ($pageno == $lastpage) { echo " NEXT LAST "; } else { $nextpage = $pageno+1; echo '<a href="'.$link.'pageno='.$nextpage.'">NEXT </a>'; echo '<a href="'.$link.' pageno='.$lastpage.'"> LAST</a>'; } // if echo '</div>'; } } if (isset($bID)) { echo '<input type="hidden" name="bID" value="'.$bID.'" />';} ?> hi, at the moment, my page only works with the County: Angus (2nd in the list) List of Counties County List Angus County List The code for my Pubs page is below..., I think I need to change the hard coded bit that reads: Code: [Select] echo "<ul title=\"Pubs in Angus\" id=\"Angu\">"; and the SQL string: Code: [Select] $query = "SELECT * FROM pubs WHERE rsCounty = 'Angus' LIMIT $offset, $rowsPerPage"; pubs page Code: [Select] <?php include_once("config.php"); include_once("functions.php"); // Check user logged in already: checkLoggedIn("no"); //doCSS(); ?> <!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=iso-8859-1" /> <title>My Pub Space</title> <link rel="stylesheet" type="text/css" href="stylesheets/style1.css" title="default" /> <meta name="viewport" content="width=device-width; initial-scale=1.0; minimum-scale=1.0; maximum-scale=1.0; user-scalable=0;"/> <link rel="apple-touch-icon" href="../iui/iui/mps-icon.png" /> <style type="text/css" media="screen">@import "../iui/iui/iui.css";</style> <script type="application/x-javascript" src="../iui/iui/iui.js"></script> <meta name="apple-touch-fullscreen" content="YES" /> <script type="text/javascript" src="js/jva.js"></script> </head> <body> <? $offset = (isset($_GET['start'])) ? (int)$_GET["start"] : 0; $rowsPerPage = (isset($_GET['count'])) ? (int)$_GET["count"] : 10; $query = "SELECT * FROM pubs WHERE rsCounty = 'Angus' LIMIT $offset, $rowsPerPage"; $result = mysql_query($query) or die(mysql_error().'<br>SQL: ' . $query); //looping counties $query1 = "SELECT rsCounty, COUNT(PUBID) AS County_Count FROM pubs GROUP BY rsCounty"; $result1 = mysql_query($query1) or die(mysql_error().'<br>SQL: ' . $query1); $County1 = $result1['rsCounty']; $CountyCount = $result1['County_Count']; ?> <div class="toolbar"> <h1 id="pageTitle">Select County</h1> <a id="backButton" class="button" href="#"></a> <a class="button" href="logout.php" target="_self">Logout</a> </div> <ul title="Select County" id="county" selected="true"> <?php while ($row = mysql_fetch_assoc($result1)){ $RSCOUNTY1 = $row['rsCounty']; $RSCOUNTY1short = substr($row['rsCounty'],0,4); $CountyCount = $row['County_Count']; echo <<<EOF <li><a href="#$RSCOUNTY1" class="digg-count">$CountyCount</a> <a href="#$RSCOUNTY1short">$RSCOUNTY1</a></li> EOF; } echo "</ul>"; // start East Sussex echo "<ul title=\"Pubs in Angus\" id=\"Angu\">"; while($row = mysql_fetch_array($result)){ $PUBID = $row['PUBID']; $rsPubName = $row['rsPubName']; $rsAddress = $row['rsAddress']; $rsPostCode = $row['rsPostCode']; $rsTel = $row['rsTel']; $rsTown = $row['rsTown']; $rsCounty = $row['rsCounty']; // how many rows we have in database // print the link to access each page $self = $_SERVER['PHP_SELF']; $next = "<li><a href=\"all.php?start=" . ($offset + $rowsPerPage) . "&count={$rowsPerPage}\" target=\"_replace\">View More</a></li>"; //div container of header and information echo <<<EOF <li><a href="viewpub.php?PUBID=$PUBID">$rsPubName</a></li> EOF; if ($_SESSION["RSUSER"] == "admin") { echo "<a href=\"edit.php?PUBID=$PUBID\" class=\"small\">edit this pub</a>"; } } echo $next; echo "</ul>"; // End East Sussex ?> </body> </html> Please help?! hi, I would like to show a list of pubs in a town that the user has selected from the drop down list http://www.mypubspace.com/dashtest/order.html it is all there working but in a different way If you type Brighton into the Town search, it shows a list of pubs in that town, GREAT! If you click the 'show towns list' link, a drop down appears, (this is where my problem is) When you click the town, I would like to get the list of pubs in that town basically get rid of the form where you type in the box and click the button here is my code HTML and Javascript Code: [Select] <html> <body> <script language="javascript" type="text/javascript"> <!-- //Browser Support Code function ajaxFunction(){ var townRequest; // The variable that makes Ajax possible! try{ // Opera 8.0+, Firefox, Safari townRequest = new XMLHttpRequest(); } catch (e){ // Internet Explorer Browsers try{ townRequest = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try{ townRequest = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e){ // Something went wrong alert("Your browser broke!"); return false; } } } // Create a function that will receive data sent from the server townRequest.onreadystatechange = function(){ if(townRequest.readyState == 4){ var ajaxDisplay = document.getElementById('ajaxDiv'); ajaxDisplay.innerHTML = townRequest.responseText; } } var name = document.getElementById('name').value; var county = document.getElementById('county').value; var town = document.getElementById('town').value; var queryString = "?name=" + name + "&county=" + county + "&town=" + town; townRequest.open("GET", "http://www.mypubspace.com/dashtest/pubs.php" + queryString, true); townRequest.send(null); } function townlistFunction(){ var ajaxRequest; // The variable that makes Ajax possible! try{ // Opera 8.0+, Firefox, Safari ajaxRequest = new XMLHttpRequest(); } catch (e){ // Internet Explorer Browsers try{ ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try{ ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e){ // Something went wrong alert("Your browser broke!"); return false; } } } // Create a function that will receive data sent from the server ajaxRequest.onreadystatechange = function(){ if(ajaxRequest.readyState == 4){ var ajaxDisplay = document.getElementById('ajaxTownlist'); ajaxDisplay.innerHTML = ajaxRequest.responseText; } } ajaxRequest.open("GET", "http://www.mypubspace.com/dashtest/town-select.php", true); ajaxRequest.send(null); } function countylistFunction(){ var ajaxRequest; // The variable that makes Ajax possible! try{ // Opera 8.0+, Firefox, Safari ajaxRequest = new XMLHttpRequest(); } catch (e){ // Internet Explorer Browsers try{ ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try{ ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e){ // Something went wrong alert("Your browser broke!"); return false; } } } // Create a function that will receive data sent from the server ajaxRequest.onreadystatechange = function(){ if(ajaxRequest.readyState == 4){ var ajaxDisplay = document.getElementById('ajaxCountylist'); ajaxDisplay.innerHTML = ajaxRequest.responseText; } } ajaxRequest.open("GET", "http://www.mypubspace.com/dashtest/county-select.php", true); ajaxRequest.send(null); } function MM_jumpMenu(targ,selObj,restore){ //v3.0 eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'"); if (restore) selObj.selectedIndex=0; } //--> </script> <a href="#" onClick="townlistFunction();">show towns list</a> <a href="#" onClick="countylistFunction();">show counties list</a> <div id="ajaxTownlist"></div> <div id="ajaxCountylist"></div> <form name='myForm'> Pub Name: <input type='text' id='name' /> <br /> County: <input type='text' id='county' /> <br /> Town: <input type='text' id='town' /> <input type='button' onclick='ajaxFunction()' value='Query MySQL' /> </form> <div id='ajaxDiv'></div> </body> </html> here is my pubs.php code Code: [Select] <?php $dbhost = "xxx"; $dbuser = "xxx"; $dbpass = "xxx"; $dbname = "xxx"; //Connect to MySQL Server mysql_connect($dbhost, $dbuser, $dbpass); //Select Database mysql_select_db($dbname) or die(mysql_error()); // Retrieve data from Query String $name = $_GET['rsPubName']; $sex = $_GET['rsTown']; $wpm = $_GET['rsCounty']; // Escape User Input to help prevent SQL Injection $name = mysql_real_escape_string($name); $town = mysql_real_escape_string($town); $county = mysql_real_escape_string($county); //build query $query = "SELECT * FROM pubs WHERE rsTown = '$town'"; $qry_result = mysql_query($query) or die(mysql_error()); //Build Result String $display_string = "<table>"; $display_string .= "<tr>"; $display_string .= "<th>Region</th>"; $display_string .= "<th>Pub Name</th>"; $display_string .= "<th>Town</th>"; $display_string .= "<th>County</th>"; $display_string .= "</tr>"; // Insert a new row in the table for each person returned while($row = mysql_fetch_array($qry_result)){ $display_string .= "<tr>"; $display_string .= "<td>$row[Region]</td>"; $display_string .= "<td>$row[rsPubName]</td>"; $display_string .= "<td>$row[rsTown]</td>"; $display_string .= "<td>$row[rsCounty]</td>"; $display_string .= "</tr>"; } $display_string .= "</table>"; echo $display_string; ?> here is my town_select.php code Code: [Select] <?php $dbhost = "xxx"; $dbuser = "xxx"; $dbpass = "xxx"; $dbname = "xxx"; //Connect to MySQL Server mysql_connect($dbhost, $dbuser, $dbpass); //Select Database mysql_select_db($dbname) or die(mysql_error()); // Retrieve data from Query String $town = $_GET['rsTown']; // Escape User Input to help prevent SQL Injection $town = mysql_real_escape_string($town); //build query $query = "SELECT DISTINCT rsTown, COUNT(PUBID) As PubCount FROM pubs GROUP BY rsTown ORDER BY rsTown ASC"; $qry_result = mysql_query($query) or die(mysql_error()); // Insert a new row in the table for each person returned $display_string .= "<form name=\"form3\" method=\"post\" action=\"\">"; $display_string .= "<select name=\"menu2\" onChange=\"MM_jumpMenu('parent',this,0)\" class=\"textbox\">"; $display_string .= "<option value=\"\">Search by Town...</option>"; while($row = mysql_fetch_array($qry_result)){ $display_string .= '<option value="rsTown='.$row['rsTown'].'" onclick=\"ajaxFunction()\" id=\"town\">'.$row['rsTown'].' ('.$row['PubCount'].')</option>'; } $display_string .= "</select>"; $display_string .= "</form>"; echo $display_string; ?> hey guys, I am having a small problem and I can't wrap my head around it. I want users to be able to upload up 10 photos in the database and what I want to do is check the database to see how many pics they have already and if they have 10, just show the photo with action items but if they have 7 for example, show the 7 pictures and three upload fields, if they have 4, show the pics and 6 fields and so on... let me know what you guys think and some help. Thanks in advance guys, you always come through... show list of files uploaded by current session user to the database. I want to show different users when they log in to the website...they can see a list of old files that they have uploaded. can anyone tell me the code/script to this.....please, ty what php function would I need to use to let's say I have a string I went to the Store And I want to pass that string, or any string through some type of function that would output: I Went To The Store How in the world could I do this? am I overthinking this or is this extremely difficult? hello, i have the following, which is sorting by id number with a horizontal line between. im trying to make it so that it is sorted by supplier with lines between each letter. Code: [Select] <?php if ($PreviousID!=0 && $ManID != $PreviousID) {?> <hr /> <?PHP } $PreviousID = $ManID; include 'config.php'; include 'javascript.php'; @mysql_select_db ("citycore", $conn) OR DIE (mysql_error()); $sql = "SELECT * FROM supplier ORDER BY supplier"; $result = @mysql_query($sql, $conn) or die(mysql_error()); //$row2 = mysql_query($sql, $conn); $PreviousID=0; while ($row = mysql_fetch_array($result)) { $ManID = $row['id']; $id=$row['id']; $supplier=$row['supplier']; $address=$row['address']; $city=$row['city']; $province=$row['province']; $postal=$row['postal']; $phone2=$row['phone2']; $phone=$row['phone']; $fax=$row['fax']; $email=$row['email']; ?> <div align="center"> <table border="1" width="95%" style="border-collapse: collapse"> <tr> <td><?php echo $row['supplier'];?></td> <td><a href="http://mapof.it/<?php echo($address .' ' .$city .',' .' ' .$province .' ' .$postal); ?>" target="_blank"><?php echo($address .' ' .$city .',' .' ' .$province .' ' .$postal); ?></a></td> </tr> </table> </div> <?PHP } ?> i want it so that the 1st letter in this text box when it Submited gets saved to the db as 1st letter <input name="title" type="text" id="title" size="50" /> I am trying to get a paragraph from a website. Everything works but the first letter is kept on missing. The code shown below is used to get the paragraph. Not sure why the first letter is missing. Please help!!! Code: [Select] if ( isset( $offer[ 0 ] ) ) { // Tidy it up - remove commas and weird Word chars $off = strip_tags( $offer[ 0 ] ); $off = substr( $off, strpos( $off, ";" ) + 1 ); $off = str_replace("'", "", $off ); $off = trim( $off ); } else { $off = "0"; } Hi, I have pagination system with FIRST LETTER separated and everything is OK.
$page = (int)(!isset($_GET["page"]) ? 1 : $_GET["page"]); if ($page <= 0) $page = 1; $per_page = 5; $startpoint = ($page * $per_page) - $per_page; $statement = "restaurants ORDER BY `name`"; // make foo the current db '" . addslashes($_GET['id']) . "' $result = mysqli_query($mysqli,"SELECT name FROM restaurants WHERE cuisine_ID_obsolete=5 ORDER BY name LIMIT {$startpoint} , {$per_page}"); if (mysqli_num_rows($result) == 0) { echo "No records are found."; } else { $lastFoundLetter = ''; // displaying records. while ($row = mysqli_fetch_array($result)) { $firstLetter = substr($row['name'], 0, 1); if ($firstLetter != $lastFoundLetter) { if ($lastFoundLetter != '') { echo "</br>"; } echo strtoupper($firstLetter) . "<br/>"; $lastFoundLetter = $firstLetter; } echo $row['name'] . "<br/>"; } } echo pagination($statement,$per_page,$page); ?>Function for pagination: <?php function pagination($query,$per_page=10,$page=1,$url='?'){ global $mysqli; $query = "SELECT COUNT(*) as `num` FROM restaurants WHERE cuisine_id_OBSOLETE = '12'"; $row = mysqli_fetch_array(mysqli_query($mysqli,$query)); $total = $row['num']; $adjacents = "1"; $prevlabel = "<img src='files/prev.png'>"; $nextlabel = "<img src='files/next.png'>"; $page = ($page == 0 ? 1 : $page); $start = ($page - 1) * $per_page; $prev = $page - 1; $next = $page + 1; $lastpage = ceil($total/$per_page); $lpm1 = $lastpage - 1; // //last page minus 1 $pagination = ""; if($lastpage > 1){ $pagination .= "<ul class='pagination'>"; if ($page > 1) $pagination.= "<li><a href='{$url}page={$prev}'>{$prevlabel}</a></li>"; if ($lastpage < 7 + ($adjacents * 2)){ for ($counter = 1; $counter <= $lastpage; $counter++){ if ($counter == $page) $pagination.= "<li><a class='current'>{$counter}</a></li>"; else $pagination.= "<li><a href='{$url}page={$counter}'>{$counter}</a></li>"; } } elseif($lastpage > 1 + ($adjacents * 2)){ if($page < 1 + ($adjacents * 2)) { for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++){ if ($counter == $page) $pagination.= "<li><a class='current'>{$counter}</a></li>"; else $pagination.= "<li><a href='{$url}page={$counter}'>{$counter}</a></li>"; } $pagination.= "<li class='dot'>...</li>"; $pagination.= "<li><a href='{$url}page={$lpm1}'>{$lpm1}</a></li>"; $pagination.= "<li><a href='{$url}page={$lastpage}'>{$lastpage}</a></li>"; } elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2)) { $pagination.= "<li><a href='{$url}page=1'>1</a></li>"; $pagination.= "<li><a href='{$url}page=2'>2</a></li>"; $pagination.= "<li class='dot'>...</li>"; for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++) { if ($counter == $page) $pagination.= "<li><a class='current'>{$counter}</a></li>"; else $pagination.= "<li><a href='{$url}page={$counter}'>{$counter}</a></li>"; } $pagination.= "<li class='dot'>..</li>"; $pagination.= "<li><a href='{$url}page={$lpm1}'>{$lpm1}</a></li>"; $pagination.= "<li><a href='{$url}page={$lastpage}'>{$lastpage}</a></li>"; } else { $pagination.= "<li><a href='{$url}page=1'>1</a></li>"; $pagination.= "<li><a href='{$url}page=2'>2</a></li>"; $pagination.= "<li class='dot'>..</li>"; for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++) { if ($counter == $page) $pagination.= "<li><a class='current'>{$counter}</a></li>"; else $pagination.= "<li><a href='{$url}page={$counter}'>{$counter}</a></li>"; } } } if ($page < $counter - 1) $pagination.= "<li><a href='{$url}page={$next}'>{$nextlabel}</a></li>"; $pagination.= "</ul>"; } return $pagination; } ?>Problem is, since I have FIRST LETTER separated, with $per_page. How to exclude FIRST LETTER and "<br/>" from $per_page variable? Hi.. I have code for auto increment of JO Number, now it display: 120504001 by using this code: <?php $sql = "SELECT jo_number FROM job_order ORDER BY jo_date DESC LIMIT 1"; $result = mysql_query($sql, $con); if (!$result) { echo 'failed'; die(); } $total = mysql_num_rows($result); if ($total <= 0) { $currentSRNum = 1; $currentYear = (int)(date('y')); $currentMonth = (int)(date('m')); $currentDay = (int)(date('d')); $currentSRYMD = substr($row['jo_number'], 0, 6); $currentYMD = date("ymd"); if ($currentYMD > $currentSRYMD) { $currentSRNum = 1; } else { $currentSRNum += 1; } } else { //------------------------------------------------------------------------------------------------------------------ // Stock Number iteration.... $row = mysql_fetch_assoc($result); $currentSRNum = (int)(substr($row['jo_number'],0,3)); $currentSRYear = (int)(substr($row['jo_number'],2,2)); $currentSRMonth = (int)(substr($row['jo_number'],0,2)); $currentSRNum = (int)(substr($row['jo_number'],6,4)); $currentYear = (int)(date('y')); $currentMonth = (int)(date('m')); $currentDay = (int)(date('d')); $currentSRYMD = substr($row['jo_number'], 0, 6); $currentYMD = date("ymd"); if ($currentYMD > $currentSRYMD) { $currentSRNum = 1; } else { $currentSRNum += 1; } } //------------------------------------------------------------------------------------------------------------------ $yearMonth = date('ymd'); $currentSR = $currentYMD . sprintf("%03d", $currentSRNum); ?> now I want it to be: JO120504001 JO120504002 JO120504003 JO120504004 JO120505001 JO120504002 JO120504003 Any help is highly appreciated. Thank you so much This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=350684.0 Hello, I am attempting to develop a simple php script which will generate a 4 letter sequence when a button is pressed. However the sequence has a few rules it has to follow. For example: the letters have to be A B C D E F G H J K L M P Q and R The second letter must be a letter AFTER the first The fourth letter must be a letter AFTER the third There can't be 2 of the same number. I am a bit confused on how I will do this as I am quite new to php, I though about generating the first as $1, then generating the second as $2, then if $1 > $2, then I would regenerate $2 until it wasn't. Then repeating that for $4. However I am not sure on the coding which would be involved in doing this. If someone could give me a few pointers or a link to a website which would help me it would be much appreciated. I want to be able to replace, let's say, every fifth letter from a string. The string is unknown, though, it could come from database, or a POST form. So I'm unsure if I could use str_replace. I think I may need to use preg_replace(), but I'm not not sure. I'm trying to get a listing of my directory that shows the first letter and then all the names that start with that letter. Here is my code: Code: [Select] for($i = 65; $i < 91; $i++) { foreach (glob("{".chr($i).",".chr($i+32)."}*", GLOB_BRACE|GLOB_ONLYDIR) as $directoryname) { echo chr($i)."| ".$directoryname; } } But here's my output: Quote P | Project Red P | Projects P | Pants R | Resumes W | Warehouse Files W | warrior I want it to be like: Quote P | Project Red Projects Pants R | Resumes W | Warehouse Files Warrior I know I have to move the chr($i) since it loops, but I'm not sure where to go from there. Need to change the letter spacing.. help? $tag = 'www.xxxxxx.com'; $text_draw->setFontSize(8); $text_draw->setFillColor("black"); $output_image->annotateImage($text_draw, 123, 34, 0, $tag); $text_draw->setFillColor("white"); $output_image->annotateImage($text_draw, 122, 33, 0, $tag); I am trying to make a function that will generate a random number letter combo but the letters can only be abcde, no others. It must come out in the format, 1a~3d~9b~ etc. This is what I have so far: Code: [Select] function randomNumLet($amount){ $theNos = array('1', '2', '3', '4', '5', '6', '7', '8', '9'); $theLet = array('a', 'b', 'c', 'd', 'e'); $combo = ''; for($i=0;$i<$amount;++$i) { $rand_num = array_rand($theNos, 1); $rand_let = array_rand($theLet, 1); $combo .= $theNos[$rand_num[0]].$theLet[$rand_let[0]].'~'; } return $combo; } $num_let = randomNumLet(2); echo $num_let; And it returns just '~~' with no numbers or letters. I'm a bit stuck here and would appreciate any help. How can I make the function output 1a~4d~ etc? Cheers, Joe This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=349226.0 |