How to print username for each alphabet letter - php

I have script where I try to print names following its alphabetical letter:
$alphabets = 'abcdefghijklmnopqrstuvwxyz';
$usersResult = getUsersEmail();
echo "<div class='m0'>";
echo "<div id=woohoo class=hey_im_here>";
echo '<input class="search" placeholder="Enter a name">';
echo "<br><br>";
$c=26; //or count(alphabets)
$count = count($usersResult);
for ($ii=0;$ii<$c;$ii++){
echo "<div id='memberList$ii' style='display:inline-block;vertical-align:top'>";
echo "<fieldset class=fieldname style='display:inline'>";
echo "<legend class=name_legend>" . $alphabets[$ii] . "</legend>";
echo "<ul class='list'>";
while ($row_usrname = mysqli_fetch_array($usersResult)) {
if (strtolower(substr($row_usrname['username'],0,1)) == $alphabets[$ii]) {
echo '<li><label for="'.$row_usrname['username'].'">'
. '<input type="checkbox" id="'.$row_usrname['username'].'" class="empCheckBoxClass" name="employment[]" value="'.$row_usrname['staff_id'].'" />'.$row_usrname['username'].'</li> </label>';
}
}
echo "</ul>";
echo "</fieldset>";
echo "<br>";
echo "</div>";
}
echo "</div>";
echo "</div>";
I am able to print names only for A:
How can I print it for every letter?

Related

Ajax is not responding on remote server for Some PC's

*Ajax is not responding on remote server for Some PC's but working fine on mobile browsers and on PC which i have uploaded on. Please let me know whats the problem with that
This Ajax function.
<pre>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('#selTrim').change(function(){
var trim_id1 = $(this).val();
if(trim_id1){
$.ajax({
type:'POST',
url:'<?= base_url();?>H1_specifications/h1_trim_detail',
data:'trim_id1='+trim_id1,
success:function(data){
$('#specContWrap').html(data);
}
});
}
});
});
</script>
</pre>
*This Php Code-igniter Controller response *.
I am using Code-igniter framework please also let me know is this a best practice to echo response .
<pre>
public function h1_trim_detail(){
$id = $_POST['trim_id1'];
if(isset($_POST['trim_id1']) !== NULL){
$this->load->model('Admin_panel');
$rows7 =$this->Admin_panel->select_h1_details_specification($id);
$rows =$this->Admin_panel->select_h1_Cargo($id);
$rows1 =$this->Admin_panel->select_h1_engine($id);
$rows2 =$this->Admin_panel->select_h1_exterior($id);
$rows3 =$this->Admin_panel->select_h1_feul_comsuption($id);
$rows4 =$this->Admin_panel->select_h1_weight($id);
$rows5 =$this->Admin_panel->select_h1_wheels($id);
$rows6 =$this->Admin_panel->select_h1_transmission($id);
echo "<div id='specContWrap'>";
if($rows7 !== false){
echo "<div id='overViewWrap' class='overViewTableCon'>";
echo "<div class='overViewTable on'>";
echo "<div class='tit'>Overview</div>";
echo "<table class='infoTableType'>";
echo "<caption>Overview Table</caption>";
echo "<tbody>";
echo "<tr>";
echo "<th scope='row'>Product label</th>";
echo "<td>Commercial</td>";
echo "</tr>";
foreach($rows7 as $row){
echo "<tr>";
echo "<th scope='row'>Product label</th>";
echo "<td>".$row['name']."</td>";
echo "</tr>";
echo "<tr>";
echo "<th scope='row'>Model name</th>";
echo "<td>". $row['name_car']."</td>";
echo "</tr>";
echo "<tr>";
echo "<th scope='row'>Seats</th>";
echo "<td>". $row['seats']."</td>";
echo "</tr>";
}
echo "</tbody>";
echo "</table>";
echo "</div>";
echo "</div>";
}else{
echo "Not Found";
}
echo "<div class='togListWrap small sepcListWrap' id='overviewh1'>";
echo "<div class='togList'>";
echo "<button class='btnOpenClose'>Performance</button>";
echo "<div class='togCont' id='performanceWrap'>";
echo "<div class='performance on'>";
if($rows1 !== false){
echo "<dl class='specList'>";
echo "<dt>Engine Specification</dt>";
foreach($rows1 as $row){
echo "<dd>";
echo "<dl>";
echo "<dt>".$row['label']."</dt>";
echo "<dd>".$row['descriptions']."</dd>";
echo "</dl>";
echo "</dd>";
}
echo "</dl><br>";
}else{
echo "<dt>Engine Specification Not Found</dt><br>";
}
if($rows3 !== false){
echo "<dl class='specList'>";
echo "<dt>Feul Comsuption Specification</dt>";
foreach($rows3 as $row){
echo "<dd>";
echo "<dl>";
echo "<dt>".$row['label']."</dt>";
echo "<dd>".$row['description']."</dd>";
echo "</dl>";
echo "</dd>";
}
echo "</dl><br>";
}else{
echo "<dt>Feul Comsuption Specification Not Found</dt><br>";
}
if($rows6 !== false){
echo "<dl class='specList'>";
echo "<dt>Transmission Specification</dt>";
foreach($rows6 as $row){
echo "<dd>";
echo "<dl>";
echo "<dt>".$row['label']."</dt>";
echo "<dd>".$row['description']."</dd>";
echo "</dl>";
echo "</dd>";
}
echo "</dl><br>";
}else{
echo "<dt>Transmission Specification Not Found</dt><br>";
}
echo "</div>";
echo "</div>";
echo "</div>";
echo "<div class='togList'>";
echo "<button class='btnOpenClose'>Dimension</button>";
echo "<div class='togCont' id='DimensionWrap'>";
echo "<div class='Dimension on'>";
if($rows2 !== false){
echo "<dl class='specList'>";
echo "<dt>Exterior Specification</dt>";
foreach($rows2 as $row){
echo "<dd>";
echo "<dl>";
echo "<dt>".$row['label']."</dt>";
echo "<dd>".$row['descriptions']."</dd>";
echo "</dl>";
echo "</dd>";
}
echo "</dl><br>";
}else{
echo "<dt>Exterior Specification Not Found</dt><br>";
}
if($rows4 !== false){
echo "<dl class='specList'>";
echo "<dt>Weight Specification</dt>";
foreach($rows4 as $row){
echo "<dd>";
echo "<dl>";
echo "<dt>".$row['label']."</dt>";
echo "<dd>".$row['description']."</dd>";
echo "</dl>";
echo "</dd><br>";
}
echo "</dl><br>";
}else{
echo "<dt>Weight Specification Not Found</dt><br>";
}
if($rows !== false){
echo "<dl class='specList'>";
echo "<dt>Cargo Specification</dt>";
foreach($rows as $row){
echo "<dd>";
echo "<dl>";
echo "<dt>".$row['label']."</dt>";
echo "<dd>".$row['description']."</dd>";
echo "</dl>";
echo "</dd>";
}
echo "</dl><br>";
}else{
echo "<dt>Cargo Specification Not Found</dt><br>";
}
echo "</div>";
echo "</div>";
echo "</div>";
echo "<div class='togList'>";
echo "<button class='btnOpenClose'>Wheels</button>";
echo "<div class='togCont' id='WheelsWrap'>";
echo "<div class='Wheels on'>";
if($rows5 !== false){
echo "<dl class='specList'>";
echo "<dt>Wheels Specification</dt>";
foreach($rows5 as $row){
echo "<dd>";
echo "<dl>";
echo "<dt>".$row['label']."</dt>";
echo "<dd>".$row['descriptions']."</dd>";
echo "</dl>";
echo "</dd>";
}
echo "</dl><br>";
}else{
echo "<dt>Wheels Specification Not Found</dt><br>";
}
echo "</div>";
echo "</div>";
echo "</div>";
echo "</div>";
echo "</div>";
}
}
</pre>

Why I can't echo div?

I have code for list values from database but when I add them to echo "<div>" it stops working
My code:
$sql = "SELECT name, size, type, username FROM Files";
$result = $conn->query($sql);
if ($result->num_rows > 0)
{
while($row = $result->fetch_assoc())
{
echo "<div class='filediv'>";
echo "<a href='uploads/$row['name']' download>$row['name']</a>";
echo "<p>Size: $row['size']KB</p>";
echo "<p>Type: $row['type']</p>";
echo "<p>Creator: $row['username']</p>";
echo "</div>";
echo "<hr>";
}
}
you have a syntax error
echo "<div class='filediv'>";
echo "<a href='uploads/".$row['name']."' download>".$row['name']."</a>";
echo "<p>Size:". $row['size']."KB</p>";
echo "<p>Type: ".$row['type']."</p>";
echo "<p>Creator: ".$row['username']."</p>";
echo "</div>";
echo "<hr>";
You can use {} for print php variables in html.
echo "<div class='filediv'>";
echo "<a href='uploads/{$row['name']}' download>{$row['name']}</a>";
echo "<p>Size: {$row['size']}KB</p>";
echo "<p>Type: {$row['type']}</p>";
echo "<p>Creator: {$row['username']}</p>";
echo "</div>";
echo "<hr>";

Using while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) to display images from database but only 1 image is shown

I try to fetch all image from database but only one image is shown.
this is my code:
<?php
$query = "SELECT id, name, image, price FROM products ORDER BY name";
$stmt = $con-> prepare ( $query );
$stmt->execute();
$num = $stmt->rowCount();
if($num>0){
//some html code
this is my while loop:
while ($row = $stmt->fetch(PDO::FETCH_ASSOC))
{
extract($row);
echo "<div class='inner'>";
//creating new table row per record
echo "<ul>";
echo "<li>";
echo "<a class='thumb' href='images/{$image}'>";
echo "<div class='product-id' style='display:none;'>{$id}</div>";
echo "<span class='hoodnamecarousel'>{$name}</span>";
echo"</a>";
echo "</li>";
echo "</ul>";
echo "</div>";
echo "</div>";
This is second part of displaying image after click on any image:
echo "<div id='thumbs2' style='display:none;'>";
echo "<div class='inner'>";
echo "<ul>";
echo "<li>";
echo "<a class='thumb' href='images/{$image}'></a>";
echo "<div class='product-id' style='display:none;'>{$id}</div>";
echo "<span class='hoodnamecarousel'>{$name}</span>";
echo "<br />";
echo "<span class='price'>{$price}</span>";
echo "<br />";
echo "<a href='add_to_cart.php?id={$id}&name={$name}' class='button btn btn-primary'>";
echo "افزودن به سبد <span class='glyphicon glyphicon-shopping-cart'></span>";
echo "</a>";
echo "</li>";
echo"</ul>";
echo "</div>";
echo "<div id='closeBtn'>بستن</div>";
}
echo "</div>";
echo "</div>";
}
else {
echo "محصولات در حال بروزرسانی می باشند.";
}
?>
this code only display 1 image and doesn't show other images from database
please help me!

PHP Counting With Related Articles

my goal is to display related articles below a post (check if available, then loop through the ones that are there). It works fine if I have 3 or 6 setup but if I have only 5, it displays automatically the original post as the sixth related article.
echo "<div class='related-posts'>";
$related_articles = get_field('related_articles', false, false);
$id = $related_articles[0];
if($id) {
echo "<h5 class='related-posts_h'>Ähnliche Artikel, die du lesen musst</h5>";
echo "<ul class='related-posts_list clearfix'>";
for ($i=1; $i <= 6; $i++) {
$id = $related_articles[$i-1];
if ( has_post_thumbnail($id) ) {
echo "<li class='related-posts_item'>";
echo "<figure class='featured-thumbnail thumbnail large'>";
echo "<div class='hider-page'></div>";
echo "<a href='".get_permalink($id)." title='".get_the_title($id)."'>";
echo get_the_post_thumbnail( $id, 'medium-thumb' );
echo "<span class='zoom-icon'></span>";
echo "</a>";
echo "</figure>";
} else {
"<figure class='thumbnail featured-thumbnail'>";
echo "<div class='hider-page'></div>";
echo "<a href='".get_permalink($id)."' title='".get_the_title($id)."'>";
echo "<img src='".get_template_directory_uri()."/images/empty_thumb.gif' alt='".get_the_title($id)."' />";
echo "</a>";
echo "</figure>";
}
echo "<h6><a href='".get_permalink($id)."'>";
echo get_the_title($id);
echo "</a>";
echo "</h6>";
echo "</li>";
}
echo "</ul>";
echo "</div><!-- .related-posts -->";
Try this.. check after the for loop whether the related Post ID is not equals to the original post ID then only display the related Posts
that is
$id = $related_articles[$i-1];
if(get_the_ID() != $id){
//then do the stuff
}
I Hope you are in the details or single.php page so you will get the ID of original post by get_the_ID()
echo "<div class='related-posts'>";
$related_articles = get_field('related_articles', false, false);
$id = $related_articles[0];
if($id) {
echo "<h5 class='related-posts_h'>Ähnliche Artikel, die du lesen musst</h5>";
echo "<ul class='related-posts_list clearfix'>";
for ($i=1; $i <= 6; $i++) {
$id = $related_articles[$i-1];
if(get_the_ID() != $id){
if ( has_post_thumbnail($id) ) {
echo "<li class='related-posts_item'>";
echo "<figure class='featured-thumbnail thumbnail large'>";
echo "<div class='hider-page'></div>";
echo "<a href='".get_permalink($id)." title='".get_the_title($id)."'>";
echo get_the_post_thumbnail( $id, 'medium-thumb' );
echo "<span class='zoom-icon'></span>";
echo "</a>";
echo "</figure>";
} else {
"<figure class='thumbnail featured-thumbnail'>";
echo "<div class='hider-page'></div>";
echo "<a href='".get_permalink($id)."' title='".get_the_title($id)."'>";
echo "<img src='".get_template_directory_uri()."/images/empty_thumb.gif' alt='".get_the_title($id)."' />";
echo "</a>";
echo "</figure>";
}
echo "<h6><a href='".get_permalink($id)."'>";
echo get_the_title($id);
echo "</a>";
echo "</h6>";
echo "</li>";
}
}
echo "</ul>";
echo "</div><!-- .related-posts -->";

XML link into a PHP array

I'm having trouble getting this page (http://ventrilostatus.net/xml/V98.DARKSTARLLC.COM:3789/) to array into php. I'm not very good with xml and I currently can only get it to display:
Server
Channel
Channel
Channel
(etc)
Could anyone help me get it to show the channel name and the users?
if there are not clients when you look at it it will be:
<client admin="1" cid="994" phan="0" ping="186" sec="56935" name="WHERE USER'S NAME HIS HERE" comm=""/>
U can use the simple_xml functions of PHP to load the xml file into a class.
http://php.net/manual/de/book.simplexml.php
Edit with an example:
// XML example
$xmlContent = '<server name="GuiltyofDestruction" phonetic="God" comment="http://guiltyofdestruction.com" auth="1" maxclients="25" uptime="137600" platform="Linux-i386" version="3.0.6" channelcount="36" clientcount="1" voicecodec="GSM 6.10" voiceformat="44 KHz, 16 bit"><channel cid="0" pid="-1" prot="0" name="Lobby" comm="">
<channel cid="1033" pid="0" prot="1" name="Admin" comm=""/>
<channel cid="1030" pid="0" prot="0" name="AFK Channel" comm="AFK">
<client admin="1" cid="1030" phan="0" ping="182" sec="67575" name="US_ChairForce" comm=""/>
</channel>
</channel>
</server>';
// Loading XML information as object
//$xml = simplexml_load_file('http://ventrilostatus.net/xml/V98.DARKSTARLLC.COM:3789/'); // for files
$xml = simplexml_load_string($xmlContent); // for strings
foreach($xml->channel->channel as $channel) {
if($channel->client)
echo $channel->client->attributes()->name; // returns "US_ChairForce"
}
I think it's clear now. You have to iterate through every channel and look for clients.
sorry this is the code I updated:
<?PHP
echo "<table width=\"209\" bgcolor=\"#0d0d0d\">";
$xml = simplexml_load_file('http://ventrilostatus.net/xml/V98.DARKSTARLLC.COM:3789/'); // for files
//$xml = simplexml_load_string($xmlContent); // for strings
foreach($xml->channel as $lobby) {
echo "<tr><td>";
echo "<img src='http://view.light-speed.com//images/s_vent2/server_icon.gif' />";
echo "<font color=\"#FFFFFF\">";
echo $lobby->attributes()->name;
echo "</font>";
echo "</td></tr>";
}
foreach($xml->channel->channel as $channel) {
if($channel->attributes()->prot == "0"){
echo "<tr><td> ";
echo "<img src='http://view.light-speed.com//images/s_vent2/channel_0_empty.gif' />";
echo "<font color=\"#ffffff\">";
echo $channel->attributes()->name;
echo "</font>";
echo "</td></tr>";
}else{
echo "<tr><td> ";
echo "<img src='http://view.light-speed.com//images/s_vent2/channel_1_empty.gif' />";
echo "<font color=\"#ffffff\">";
echo $channel->attributes()->name;
echo "</font>";
echo "</td></tr>";
}
if($channel->client){
for ( $i = 0; $i < count($channel->client); $i++ ){
$client = $channel->client[ $i ];
if ( $client->attributes()->cid != $client->attributes()->cid )
continue;
echo "<tr><td> ";
echo "<img src='http://view.light-speed.com//images/s_vent2/player.gif' /><font color=\"#009e1a\">";
if($client->attributes()->admin == "1"){
echo $client->attributes()->name;
echo " <font color=\"#ff0000\">(Admin)</font>";
}else{
echo $client->attributes()->name;
}
echo "</td></tr>";
}
}
foreach($channel->channel as $subchannel) {
if($subchannel->attributes()->prot == "0"){
echo "<tr><td> ";
echo "<img src='http://view.light-speed.com//images/s_vent2/channel_0_empty.gif' />";
echo "<font color=\"#ffffff\">";
echo $subchannel->attributes()->name;
echo "</font>";
echo "</td></tr>";
}else{
echo "<tr><td> ";
echo "<img src='http://view.light-speed.com//images/s_vent2/channel_1_empty.gif' />";
echo "<font color=\"#ffffff\">";
echo $subchannel->attributes()->name;
echo "</font>";
echo "</td></tr>";
}
if($subchannel->client){
for ( $i = 0; $i < count($subchannel->client); $i++ ){
$client = $subchannel->client[ $i ];
if ( $client->attributes()->cid != $client->attributes()->cid )
continue;
echo "<tr><td> ";
echo "<img src='http://view.light-speed.com//images/s_vent2/player.gif' /><font color=\"#009e1a\">";
if($client->attributes()->admin == "1"){
echo $client->attributes()->name;
echo " <font color=\"#ff0000\">(Admin)</font>";
}else{
echo $client->attributes()->name;
}
echo "</td></tr>";
}
}
foreach($subchannel->channel as $subchannel2) {
if($subchannel2->attributes()->prot == "0"){
echo "<tr><td> ";
echo "<img src='http://view.light-speed.com//images/s_vent2/channel_0_empty.gif' />";
echo "<font color=\"#ffffff\">";
echo $subchannel2->attributes()->name;
echo "</font>";
echo "</td></tr>";
}else{
echo "<tr><td> ";
echo "<img src='http://view.light-speed.com//images/s_vent2/channel_1_empty.gif' />";
echo "<font color=\"#ffffff\">";
echo $subchannel2->attributes()->name;
echo "</font>";
echo "</td></tr>";
}
if($subchannel2->client){
for ( $i = 0; $i < count($subchannel2->client); $i++ ){
$client = $subchannel2->client[ $i ];
if ( $client->attributes()->cid != $client->attributes()->cid )
continue;
echo "<tr><td> ";
echo "<img src='http://view.light-speed.com//images/s_vent2/player.gif' /><font color=\"#009e1a\">";
if($client->attributes()->admin == "1"){
echo $client->attributes()->name;
echo " <font color=\"#ff0000\">(Admin)</font>";
}else{
echo $client->attributes()->name;
}
echo "</td></tr>";
}
}
foreach($subchannel2->channel as $subchannel3) {
if($subchannel3->attributes()->prot == "0"){
echo "<tr><td> ";
echo "<img src='http://view.light-speed.com//images/s_vent2/channel_0_empty.gif' />";
echo "<font color=\"#ffffff\">";
echo $subchannel3->attributes()->name;
echo "</font>";
echo "</td></tr>";
}else{
echo "<tr><td> ";
echo "<img src='http://view.light-speed.com//images/s_vent2/channel_1_empty.gif' />";
echo "<font color=\"#ffffff\">";
echo $subchannel3->attributes()->name;
echo "</font>";
echo "</td></tr>";
}
if($subchannel3->client){
for ( $i = 0; $i < count($subchannel3->client); $i++ ){
$client = $subchannel3->client[ $i ];
if ( $client->attributes()->cid != $client->attributes()->cid )
continue;
echo "<tr><td> ";
echo "<img src='http://view.light-speed.com//images/s_vent2/player.gif' /><font color=\"#009e1a\">";
if($client->attributes()->admin == "1"){
echo $client->attributes()->name;
echo " <font color=\"#ff0000\">(Admin)</font>";
}else{
echo $client->attributes()->name;
}
echo "</td></tr>";
}
}
}
}
}
}
echo "</table>";
?>
which shows
lobby
channel
subchannel
subchannel

Categories