Unfdefine variable: workshop - php

Error
Notice: Undefined variable: workshop in C:\wamp\www\MBL\index.php on
line 273
Line 273
$workshop .= '<div class="workshopAddon col-xs-4 text-center no-padding" style="display:none;">';
Cut out of coding
</script>
<!-- Server Workshop Collection -->
<div class="col-xs-12" style="overflow:hidden;position:absolute!important;bottom:25px;">
<?php
include 'simple_html_dom.php';
$url = 'http://steamcommunity.com/sharedfiles/filedetails/?&format=json&id=124102726';
$html = file_get_html($url);
foreach($html->find('.collectionItem') as $element) {
$workshop .= '<div class="workshopAddon col-xs-4 text-center no-padding" style="display:none;">';
foreach($element->find('.workshopItemPreviewHolder') as $previewImg) {
$img = '<div class="col-xs-3 no-padding text-center circular">'.$previewImg->innertext.'</div>';
}
foreach($element->find('.workshopItemTitle') as $displayName) {
$title = '<p class="workshopItemTitle">'.$displayName->innertext.'</p>';
}
foreach($element->find('.workshopItemAuthor') as $displayName) {
$author = '<p class="workshopItemAuthor">'.$displayName->innertext.'</p>';
}
$workshop .= $img.'
<div class="col-xs-9 no-padding">
'.$title.$author.'
</div>
</div>';
}
echo $workshop;
?>
<script>

Define $workshop before you append string parts to it.
</script>
<!-- Server Workshop Collection -->
<div class="col-xs-12" style="overflow:hidden;position:absolute!important;bottom:25px;">
<?php
include 'simple_html_dom.php';
$url = 'http://steamcommunity.com/sharedfiles/filedetails/?&format=json&id=124102726';
$html = file_get_html($url);
$workshop = ''; // <!-------------------------------------------------- ADDED
foreach($html->find('.collectionItem') as $element) {
$workshop .= '<div class="workshopAddon col-xs-4 text-center no-padding" style="display:none;">';
foreach($element->find('.workshopItemPreviewHolder') as $previewImg) {
$img = '<div class="col-xs-3 no-padding text-center circular">'.$previewImg->innertext.'</div>';
}
foreach($element->find('.workshopItemTitle') as $displayName) {
$title = '<p class="workshopItemTitle">'.$displayName->innertext.'</p>';
}
foreach($element->find('.workshopItemAuthor') as $displayName) {
$author = '<p class="workshopItemAuthor">'.$displayName->innertext.'</p>';
}
$workshop .= $img.'
<div class="col-xs-9 no-padding">
'.$title.$author.'
</div>
</div>';
}
echo $workshop;
?>
<script>

Related

Dynamically building bootstrap row, 3 per row

I am not sure the best way to go about this, on a site i'm building (using bootstrap) i want to have 3 cards per row using the grid system like:
HTML:
<div class="container">
<div class="row">
<div class="col-sm">
One of three columns
</div>
<div class="col-sm">
One of three columns
</div>
<div class="col-sm">
One of three columns
</div>
</div>
</div>
Which is no problem normally, but i'm building it (or trying to) dynamically:
PHP:
<main>
<br /><br /><br />
<?php
$pages = array_slice(scandir($_SERVER['DOCUMENT_ROOT']), 2);
$mixed = shuffle($pages);
$count = 0;
echo '<div class="container"><div class="row">';
foreach($pages as $page)
{
$count++;
if (strpos($page, '.php') !== false && $page != 'index.php') {
$html = file_get_contents($page);
$code = explode("|", extractXvideos($html));
?>
<div class="col-md-4">
<div class="card" style="width: 18rem;">
<img src="<?= $code[3]; ?>" class="card-img-top" alt="<?= $code[0]; ?>">
<div class="card-body">
<p class="card-text"><?= substr($code[0], 0, 25); ?> ...</p>
</div>
</div>
</div>
<?php
if ($count == 18) {
// The reason only 15 is showing is because we ignore ".", ".." & "index.php".
break;
}
}
}
echo '</div></div>';
?>
</main>
For this project i'm scanning .php pages on the server, then trying to lay them out 3 per row, so after every row of 3 i need to start a new row echo '<div class="container"><div class="row">'; from what i can see, i do not know the best way to go about this, any help would be appreciated.
main
<?php
$pages = array_slice(scandir($_SERVER['DOCUMENT_ROOT']), 2);
$mixed = shuffle($pages);
$count = 0;
$output = '';
foreach($pages as $page) {
$count++;
if (strpos($page, '.php') !== false && $page != 'index.php') {
$html = file_get_contents($page);
$code = explode("|", extractXvideos($html));
$output .= '<div class="container">';
$output .= '<div class="row">';
$output .= '<div class="col">Column</div>';
$output .= '<div class="col">Column</div>';
$output .= '<div class="col">Column</div>';
$output .= '</div>
$output .= '</div>';
}
}
echo $output;
?>
main
try this template and apply your conditions.

WP-JSON - Multi-endpoint - Re-occuring Foreach Error

I'm currently trying to build out a multi-endpoint system for WP-JSON between 4 websites, and most of the time it's fine, however sometimes when my page performs the process, it will throw back an error for the Foreach cycle, saying 'Warning: Invalid argument supplied for foreach() in ...'
I've tried alternative methods of merging the arrays before retrieving the body using wp_remote_retrieve_body but there's no such luck. I've looked up various google solutions on multiple-endpoints using php but nothing i've found seems to do an effective job
<?php
function limit_text($text, $limit) {
if (str_word_count($text, 0) > $limit) {
$words = str_word_count($text, 2);
$pos = array_keys($words);
$text = substr($text, 0, $pos[$limit]) . '...';
}
return $text;
}
/* BASE DETAILS FOR SEARCH*/
$b_url = get_site_url(); // Base URL
$posts_merged;
$args = array(
'sslverify' => false
);
if($_GET['search'] or !empty($_GET['search'])){
$filter_query = '?search='.$_GET['search'];
}else{
$filter_query = '';
}
$post_url_collective = array(
$b_url.'/wp-json/wp/v2/posts'.$filter_query, // Main Site
$b_url.'/db/wp-json/wp/v2/posts'.$filter_query, // DB Site
$b_url.'/dc/wp-json/wp/v2/posts'.$filter_query, // DC Site
$b_url.'/fw/wp-json/wp/v2/posts'.$filter_query // FW Site
);
$post_response = wp_remote_get($post_url_collective[0], $args);
$post_response = wp_remote_retrieve_body($post_response);
$post_response = json_decode($post_response);
$post_response_two = wp_remote_get($post_url_collective[1], $args);
$post_response_two = wp_remote_retrieve_body($post_response_two);
$post_response_two = json_decode($post_response_two);
$post_response_three = wp_remote_get($post_url_collective[2], $args);
$post_response_three = wp_remote_retrieve_body($post_response_three);
$post_response_three = json_decode($post_response_three);
$post_response_four = wp_remote_get($post_url_collective[3], $args);
$post_response_four = wp_remote_retrieve_body($post_response_four);
$post_response_four = json_decode($post_response_four);
$posts_merged = array_merge( $post_response, $post_response_two, $post_response_three, $post_response_four );
?>
<div class="container multi-search-wrap">
<div class="row" style="margin-bottom: 0px">
<div class="col sm12 m12 l12">
<form class="multi-search-form" method="GET">
<div class="row" style="margin-bottom: 0px">
<div class="col sm8 m9 l10">
<input type="text" name="search" value="<?php echo ( isset( $_GET['search'] ) ? $_GET['search'] : '' ); ?>" placeholder="Search for..."/>
</div>
<div class="col sm4 m3 l2">
<input type="submit" value="Search" />
</div>
</div>
</form>
</div>
</div>
<div class="row" style="background: #eeeeee;padding: 10px;font-size: 12px;margin:0px 0px 20px 0px">
<div class="col sm12 m12 l12">
We've found <strong><?php echo count($posts_merged);?></strong> results for <?php echo $_GET['search'];?>...
</div>
</div>
<div class="row">
<?php
// Post Loop
foreach($posts_merged as $get_post) {
$image_url = $b_url.'/wp-json/wp/v2/media/'.$get_post->featured_media;
$image_response = wp_remote_get($image_url, $args);
$image_response = json_decode($image_response['body']);
//echo'<pre>';print_r($image_response);echo'</pre>';
echo '<div class="col sm12 m6 l6 multi-search-post">';
echo '<div class="row">';
echo '<div class="col sm12 m3 l4 multi-search-post">';
if(!empty($image_response->media_details->sizes->thumbnail->source_url)){
echo '<img class="img_'.$get_post->id.'" src="'.$image_response->media_details->sizes->thumbnail->source_url.'" width="auto"><br>';
}else{
echo '<img class="img_'.$get_post->id.'" src="'.get_template_directory_uri().'/images/post-placeholder.jpg" width="auto"><br>';
}
echo '</div>';
echo '<div class="col sm12 m9 l8 multi-search-post">';
echo '<a href="'.$get_post->link.'">';
echo '<h3>'.$get_post->title->rendered.'</h3>';
echo '</a>';
echo '<p>'.limit_text($get_post->excerpt->rendered, 30).'</p>';
echo '</div>';
echo '</div>';
echo '</div>';
}
?>
</div>
</div>
I would like to improve the load speed of the queries but the most important part is ridding this occassional Foreach error.
Any help would be greatly appreciated

Out put html div conflict

I am having the weirdest time with the html output. the first output works fine if you look at //start gallery row that is where my problems begin.
This is how the output should look
<div class='row'>
<div class='col-md-12'>
<div id='gallery-slider' class='slider responsive'>
<img class='img-responsive' src='cdn/assets/gallery/1.jpg'>
<img class='img-responsive' src='cdn/assets/gallery/3.jpg'>
<img class='img-responsive' src='cdn/assets/gallery/2.jpg'>
<img class='img-responsive' src='cdn/assets/gallery/4.jpg'>
<img class='img-responsive' src='cdn/assets/gallery/5.jpg'>
</div>
</div>
</div>
at the start of // gallery when I view source this is the out put
<div class='row'>
<div class='col-md-12'>
<div id='gallery-slider' class='slider responsive'>
<img class='img-responsive' src='cdn/assets/gallery/1.jpg'></div>
</div>
</div>
<img class='img-responsive' src='cdn/assets/gallery/3.jpg'>
<img class='img-responsive' src='cdn/assets/gallery/2.jpg'>
<img class='img-responsive' src='cdn/assets/gallery/4.jpg'>
<img class='img-responsive' src='cdn/assets/gallery/5.jpg'>
but no matter where I put the last output DIV it causes issues
<?php
$stmt = $db->prepare("my query");
$stmt->execute();
$result = $stmt->get_result();
$output = "";
$checker = [];
while ($row = mysqli_fetch_assoc($result)) {
$ID = $row['ID'];
$FullName = $row['FullName'];
$Email = $row['Email'];
$JobTitle = $row['JobTitle'];
$Bio = $row['Bio'];
$Photo = $row['Photo'];
$GalleryImage = explode(',', $row['GalleryImage']);
if (isset($Photo) && ! empty($Photo)) {
$ProfileImage = "$Photo";
} else {
$ProfileImage= "avatar.jpg";
}
if(!in_array($row['ID'], $checker)) {
$output .= "
<div class='container yep team-wrap'>
<div class='row'>
<div class='col-md-6'>
<img class='img-responsive' src='cdn/assets/artist/$ProfileImage'>
</div>
<div class='col-md-6'>
<strong>$FullName<br>$JobTitle</strong>
<br>
<p>$Bio</p>
<a href='mailto:$Email' class='btn btn-info'>Contact Me</a>
</div>
</div>";
//End of info row
$output .="<br /><br /><br />";
//Start Gallery Row
$output .= "
<div class='row'>
<div class='col-md-12'>
<div id='gallery-slider' class='slider responsive'>
";
}
foreach ($GalleryImage as $img){
//Display this row as many times as needed by data in this row.
$output .= "<img class='img-responsive' src='cdn/assets/gallery/$img'>";
}
$output .= "
</div>
</div>
</div>";
// End gallery row
array_push( $checker, $row['ID']);
}
$output .= "</div>";
echo $output;
?>
sql
$stmt = $db->prepare("
SELECT U.ID,
U.FullName,
U.Email,
U.JobTitle,
U.Bio,
U.Photo, G.GalleryImage
FROM users U
LEFT join gallery G
ON U.ID = G.ID
");
$stmt->execute();
$result = $stmt->get_result();
Ok, so I believe the best course of action is to loop through your $result and filter out all the repeated values as well as assigning images to an array with the row['ID'] as the key and then loop through them after CHECK IT!
$checker = array();
$profileArray = array();
while ($row = mysqli_fetch_assoc($result))
{
if($row['GalleryImage'])
{
$profileArray[$row['ID']]['GalleryImages'][] = $row['GalleryImage'];
}
if(!in_array($row['ID'], $checker))
{
while (list ($key, $value) = each($row))
{
if($key != 'GalleryImage')
{
$profileArray[$row['ID']][$key] = $value;
}
}
$checker[] = $row['ID'];
}
}
foreach ($profileArray as $row)
{
$ID = $row['ID'];
$FullName = $row['FullName'];
$Email = $row['Email'];
$JobTitle = $row['JobTitle'];
$Bio = $row['Bio'];
$Photo = $row['Photo'];
$GalleyImages = $row['GalleryImages'];
if (isset($Photo) && !empty($Photo))
{
$ProfileImage = "$Photo";
}
else
{
$ProfileImage = "avatar.jpg";
}
$output .= "
<div class='container yep team-wrap'>
<div class='row'>
<div class='col-md-6'>
<img class='img-responsive' src='cdn/assets/artist/$ProfileImage'>
</div>
<div class='col-md-6'>
<strong>$FullName<br>$JobTitle</strong>
<br>
<p>$Bio</p>
<a href='mailto:$Email' class='btn btn-info'>Contact Me</a>
</div>
</div>";
//End of info row
$output .= "<br /><br /><br />";
//Start Gallery Row
$output .= "
<div class='row'>
<div class='col-md-12'>
<div id='gallery-slider' class='slider responsive'>";
if(!$GalleyImages)
{
foreach ($GalleyImages as $img)
{
//Display this row as many times as needed by data in this row.
$output .= "<img class='img-responsive' src='cdn/assets/gallery/$img'>";
}
}
else
{
$output .= "HTML THAT YOU WANNA DISPLAY instead of images";
}
$output .= "
</div>
</div>
</div>
</div>";
}
echo $output;
Ok, first of all it is always good to format your code properly so you don't make these mistake.
Your first output is missing a closing div
<div class='container yep team-wrap'>
<div class='row'>
<div class='col-md-6'>
<img class='img-responsive' src='cdn/assets/artist/$ProfileImage'>
</div>
<div class='col-md-6'>
<strong>$FullName<br>$JobTitle</strong>
<br>
<p>$Bio</p>
<a href='mailto:$Email' class='btn btn-info'>Contact Me</a>
</div>
</div>
</div> <!-- This was missing-->
lastly you had close your if statement to quickly around the below code:
//Start Gallery Row
$output .= "
<div class='row'>
<div class='col-md-12'>
<div id='gallery-slider' class='slider responsive'>
";
} // CLOSED AT THE WRONG SPOT
Try the below:
<?php
$stmt = $db->prepare("my query");
$stmt->execute();
$result = $stmt->get_result();
$output = "";
$checker = [];
while ($row = mysqli_fetch_assoc($result)) {
$ID = $row['ID'];
$FullName = $row['FullName'];
$Email = $row['Email'];
$JobTitle = $row['JobTitle'];
$Bio = $row['Bio'];
$Photo = $row['Photo'];
$GalleryImage = explode(',', $row['GalleryImage']);
if (isset($Photo) && ! empty($Photo)) {
$ProfileImage = "$Photo";
} else {
$ProfileImage= "avatar.jpg";
}
if(!in_array($row['ID'], $checker)) {
$output .= "
<div class='container yep team-wrap'>
<div class='row'>
<div class='col-md-6'>
<img class='img-responsive' src='cdn/assets/artist/$ProfileImage'>
</div>
<div class='col-md-6'>
<strong>$FullName<br>$JobTitle</strong>
<br>
<p>$Bio</p>
<a href='mailto:$Email' class='btn btn-info'>Contact Me</a>
</div>
</div>
</div> <!-- This was missing-->
";
//End of info row
$output .="<br /><br /><br />";
//Start Gallery Row
$output .= "
<div class='row'>
<div class='col-md-12'>
<div id='gallery-slider' class='slider responsive'>
";
foreach ($GalleryImage as $img) {
//Display this row as many times as needed by data in this row.
$output .= "<img class='img-responsive' src='cdn/assets/gallery/$img'>";
}
$output .= "
</div>
</div>
</div>
";
// End gallery row
array_push( $checker, $row['ID']);
}
}
$output .= "</div>";
echo $output;
?>
Most of the time try to separate your PHP from HTML that you can see errors easily.
$stmt = $db->prepare("query");
$stmt->execute();
$result = $stmt->get_result();
$output = "";
$checker = [];
while ($row = mysqli_fetch_assoc($result)) {
$ID = $row['ID'];
$FullName = $row['FullName'];
$Email = $row['Email'];
$JobTitle = $row['JobTitle'];
$Bio = $row['Bio'];
$Photo = $row['Photo'];
$GalleryImage = explode(',', $row['GalleryImage']);
if (isset($Photo) && !empty($Photo)) {
$ProfileImage = "$Photo";
} else {
$ProfileImage = "avatar.jpg";
}
if (!in_array($row['ID'], $checker)) : ?>
<div class='container yep team-wrap'>
<div class='row'>
<div class='col-md-6'>
<img class='img-responsive' src='cdn/assets/artist/<?php echo $ProfileImage; ?>'>
</div>
<div class='col-md-6'>
<strong><?php echo $FullName; ?><br><?php echo $JobTitle; ?></strong>
<br>
<p><?php echo $Bio; ?></p>
<a href='mailto:$Email' class='btn btn-info'>Contact Me</a>
</div>
</div>
<!-- End of info row-->
<br/><br/><br/>
<!-- Start Gallery Row-->
<div class='row'>
<div class='col-md-12'>
<div id='gallery-slider' class='slider responsive'>
<!-- Display this row as many times as needed by data in this row.-->
<?php foreach ($GalleryImage as $img) : ?>
<img class='img-responsive' src='cdn/assets/gallery/<?php echo $img; ?>'>
<?php endforeach; ?>
</div>
</div>
</div>
</div>
<!-- // End gallery row-->
<?php array_push($checker, $row['ID']); endif;
}
?
Example output

responsive image and text alignment

I have a site that uses three col-md-4 as a class.
This is the code:
echo '<div class="head6 panel-heading">Local Business Listing</div>
<div class="panel-body">
';
$funcs->viewSurvey();
$array4 = $funcs->viewSurvey();
$searchengine = $array4['searchengine'];
$sum = $array4['sum'];
$searches = explode(',', $searchengine);
$searchesa = array("Google","Yahoo","Bing");
$check = '<img src="images/checked.png" height="40px" width="40px">';
$uncheck = '<img src="images/unchecked.png" height="40px" width="40px">';
foreach ($searchesa as $key_a => $val_c) {
$found = false;
echo '<div class="col-sm-4">';
foreach ($searches as $key_b => $val_d) {
if ($val_c == $val_d) {
echo ''.$check.'<h3 class="head6">'. $val_c.'</h3>' ;
$found = true;
}
}
if (!$found){
echo ''.$uncheck.'<h3 class="head6">'. $val_c.'</h3>' ;
}
echo '</div>';
}
echo '
</div>';
When the screen is smaller it appears like this
how can I place it in single line still even in a mobile display?
You can use col-xs-4 for single line still even in a mobile display.
Try This.. Change div class panel-body to this panel-body col-md-4 col-xs-4
<div class="panel-body col-md-4 col-xs-4">
</div>
Hope this could you help you.

html output formatting php

I am trying to format some html output from my db using php and here's my problem:
How it should be formated:
...
<li>
<div class="row-wrapper">
<div class="some-class-1">ARRAY-ELEMENT-1</div>
<div class="some-class-1">ARRAY-ELEMENT-2</div>
<div class="some-class-1">ARRAY-ELEMENT-3</div>
<div class="some-class-2">ARRAY-ELEMENT-4</div>
</div>
<div class="row-wrapper">
<div class="some-class-1">ARRAY-ELEMENT-5</div>
<div class="some-class-1">ARRAY-ELEMENT-6</div>
<div class="some-class-1">ARRAY-ELEMENT-7</div>
<div class="some-class-2">ARRAY-ELEMENT-8</div>
</div>
<div class="row-wrapper">
<div class="some-class-1">ARRAY-ELEMENT-9</div>
<div class="some-class-1">ARRAY-ELEMENT-10</div>
<div class="some-class-1">ARRAY-ELEMENT-11</div>
<div class="some-class-2">ARRAY-ELEMENT-12</div>
</div>
</li>
<li>
<div class="row-wrapper">
<div class="some-class-1">ARRAY-ELEMENT-13</div>
<div class="some-class-1">ARRAY-ELEMENT-14</div>
<div class="some-class-1">ARRAY-ELEMENT-15</div>
<div class="some-class-2">ARRAY-ELEMENT-16</div>
</div>
<div class="row-wrapper">
<div class="some-class-1">ARRAY-ELEMENT-17</div>
<div class="some-class-1">ARRAY-ELEMENT-18</div>
<div class="some-class-1">ARRAY-ELEMENT-19</div>
<div class="some-class-2">ARRAY-ELEMENT-20</div>
</div>
<div class="row-wrapper">
<div class="some-class-1">ARRAY-ELEMENT-21</div>
<div class="some-class-1">ARRAY-ELEMENT-22</div>
<div class="some-class-1">ARRAY-ELEMENT-23</div>
<div class="some-class-2">ARRAY-ELEMENT-24</div>
</div>
</li>
... etc.
Data is held inside an array gathered from mysql db, so far I got to this:
$num_thumbs = 4; //Number od elemets in a row
$result = myQueryFunction("SELECT * FROM table_name ORDER BY Id ASC");
$num_rows = mysql_num_rows($result);
if (!empty($num_rows)) {
while ($row = mysql_fetch_array($result)) {
$thumbs_array[] = "<a href=\"" . $row[0] . "\"><img src=\"" . $row[1] . "\"";
}
$thumb_p = "<div>\n";
mysql_free_result($result);
$i = 1;
foreach ($thumbs_array as &$thumb_link) {
if ($i == $num_thumbs) {
$i = 1;
$thumb_p .= "<div class=\"some-class-2\">" . $thumb_link . "</div>";
$thumb_p .= "</div>\n<div class=\"row-wrapper\">\n";
} else {
$thumb_p .= "\t\n<div class=\"some-class-1\">" . $thumb_link . "</div>";
$i++;
}
}
$thumb_p .= "\n</div>\n";
}
print($thumb_p);
this covers only this part of code formatting:
<div class="row-wrapper">
<div class="some-class-1">ARRAY-ELEMENT-13</div>
<div class="some-class-1">ARRAY-ELEMENT-14</div>
<div class="some-class-1">ARRAY-ELEMENT-15</div>
<div class="some-class-2">ARRAY-ELEMENT-16</div>
</div>
<div class="row-wrapper">
<div class="some-class-1">ARRAY-ELEMENT-17</div>
<div class="some-class-1">ARRAY-ELEMENT-18</div>
<div class="some-class-1">ARRAY-ELEMENT-19</div>
<div class="some-class-2">ARRAY-ELEMENT-20</div>
</div>
<div class="row-wrapper">
<div class="some-class-1">ARRAY-ELEMENT-21</div>
<div class="some-class-1">ARRAY-ELEMENT-22</div>
<div class="some-class-1">ARRAY-ELEMENT-23</div>
<div class="some-class-2">ARRAY-ELEMENT-24</div>
</div>
I've been thinking of using some variable $newList = null; that will be updated at each row, so I can check if it has changed the next one.
any ideas? Thanks in advance :)
It seems you're trying to put an li every three div. In this case, you can do this :
$thumb_p = "<li>\n<div class=\"row-wrapper\">\n";
mysql_free_result($result);
$i = 1;
$j = 0;
foreach ($thumbs_array as &$thumb_link) {
if ($i == $num_thumbs) {
$i = 1;
$thumb_p .= "<div class=\"some-class-2\">" . $thumb_link . "</div>";
$thumb_p .= "</div>\n";
if($j == 3)
{
$thumb_p .= "</li>\n<li>";
$j = 0;
}
$thumb_p .= "<div class=\"row-wrapper\">\n";
$j++;
} else {
$thumb_p .= "\t\n<div class=\"some-class-1\">" . $thumb_link . "</div>";
$i++;
}
}
$thumb_p .= "\n</div>\n</li>\n";
I can't actually try it but I think it's okay. A li is added every three row-wrapper you print.

Categories