PHP - Sorting By Letter
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 } ?> Similar Tutorialshello, 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 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" /> 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 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. 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 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> This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=350684.0 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 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"; } 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. This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=349226.0 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 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 create a glossary, and I am not sure how to group the letters of the same words underneath each other. Right now, it is appearing as this: A apple A animal A amazing A attention A aero A axiom B butt B butter b brilliant but i need it to appear as this: A apple amazing attention aero axiom B butt butter brilliant here is my code: $query = exec_mysql_query("SELECT *,substring(en,1,1) as term FROM translations WHERE substring(en,1,1) RLIKE '[$letter]' ORDER by en asc"); while ($row = mysql_fetch_assoc($query)) { $term = $row['term']; $enterm = htmlentities($row['en']); $esterm = htmlspecialchars($row['es']); $alt = htmlentities($row['alt']); $notes = htmlentities($row['notes']); if ($term == substr($enterm,0,1)) { echo "<b>$term</b><br />"; echo "$enterm - $esterm - $alt - $notes<br />"; } } } any ideas how i can fix this? Hi everyone, I have a script below, which uplads an image, however, the image name always starts with a capital letter, I want all letters to be small, how to adjust this please, thank you
$target_dir = ""; $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]); $target_file = "$get_current_user.jpg"; $uploadOk = 1; $imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION)); // Check if image file is a actual image if(isset($_POST["submit"])) { $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]); if($check !== false) { echo ""; /// was File is an image $uploadOk = 1; } else { echo "File is not an image<br>"; $uploadOk = 0; } } // Check file size if ($_FILES["fileToUpload"]["size"] > 10000000) { echo "Sorry, this image is too large, please resize using Paint<br>"; $uploadOk = 0; } // Allow certain file formats if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" && $imageFileType != "gif" ) { echo "Only JPG, JPEG, PNG & GIF files are allowed<br>"; $uploadOk = 0; } // Check if $uploadOk is set to 0 by an error if ($uploadOk == 0) { echo "There was an error<br>"; } else { if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) { echo "Uploaded successfully (You may need to clear Cache to see the new image)"; mysql_query("UPDATE user SET user_image = 'https://.../images/users/$get_current_user.jpg' WHERE user_name = '$get_current_user' "); } else { echo ""; /// was Select a suitable image, file not uploaded yet } }
From what I understand we can use ucfirst to convert the first letter within a string to upper case. What I would like to know is if there is a function that exists that would convert the first letter of every paragraph to upper case. For example: From: Code: [Select] This is a paragraph. is this the car blue? let's go for a pint of beer! To: Code: [Select] This is a paragraph. Is this the car blue? Let's go for a pint of beer! Does any such function exist? okay so this is a pretty weird one but if it's possible it would be a much easier solution that the road I'll have to take. Is it possible to code for.. $description = insert a space between a lowercase and uppercase letter is found together and not currently having a space.. within the first 50 letters of the description. Code: [Select] if (substr($description,0,50) ?..... Thanks! Hi!
I'm fairly new to PHP & MySQL (from a programmer's perspective) and have just started seriously building my own applications using PHP. I need some help bridging the gap with this MySQL query I have created that is to find only the organizations that have names that start with the letter 'A'. The initial query that I have written does work. However, I need to refine the query to "skip" over the first word -- example "The" so that I can get the complete correct results.
Here is my code:
include_once("dbconnect.php"); $linkA = "SELECT church_org FROM ics_data WHERE church_org LIKE 'A%' ORDER BY church_org ASC"; $queryA = mysql_query($linkA); $dataA = array(); while ($row = mysql_fetch_array($queryA) ) array_push ($dataA, array('church_org' => $row[0])); echo json_encode(array("dataA" => $dataA));This fetches every organization that starts with the letter 'A'. However, some organizations have St. or The in front of their names. So the query doesn't pick those up because it doesn't match what I have specified. I have tried the following: $linkA = "SELECT church_org FROM ics_data WHERE church_org LIKE 'A%' & TRIM('St. ', 'St ' church_org) ORDER BY church_org ASC";This doesn't do what I wanted it to do and after further research, I believe it is because TRIM only trims the words specified from the end-result string. I *think* I need to use REGEX to define a better pattern for the query but am still a little confused after reading the documentation on how to go about building that out. How would I accomplish this? I appreciate any help or guidance! Hopefully, I have posted this in the right forum. |