From an array I start for each entry a function with a argument from the array (its friends from facebook). The function returns either 0 or a number bigger than 0. So at the moment, it justs displays it all mixed up, but I want it to show first all entries which get the result bigger than 0 from the function and then all, which are 0. I've no idea, how to do this.
This is my current code.
foreach ($friends as $key=>$value) {
//removed unimportant things
$friendresult = friendscore($id = $fvalue[id]);
if ($friendresult == "0") {
echo '<li>';
echo '<a class="box" href="javascript:invite('. $fvalue[id] . ')">';
echo '<img src="https://graph.facebook.com/' . $fvalue[id] . '/picture" title="' . $fvalue[name] . '" />';
echo '<label>' . $fvalue[name] . '</label>';
echo '<b>Invite</b>';
echo '</a>';
echo '</li>';
}
if ($friendresult !=="0"){
echo '<li>';
echo '<a class="box">';
echo '<img src="https://graph.facebook.com/' . $fvalue[id] . '/picture" title="' . $fvalue[name] . '" />';
echo '<label>' . $fvalue[name] . '</label>';
echo '<div class="totaltext">Score:'.$friendresult. '</div>';
echo '</a>';
echo '</li>';
}}
Edit: Found solution. Sometimes its too simple.
if ($friendresult == "0") {
$friend.= '<li>';
$friend.= '<a class="box" href="javascript:invite('. $fvalue[id] . ')">';
$friend.= '<img src="https://graph.facebook.com/' . $fvalue[id] . '/picture" title="' . $fvalue[name] . '" />';
$friend.= '<label>' . $fvalue[name] . '</label>';
$friend.= '<b>Invite</b>';
$friend.= '</a>';
$friend.= '</li>';
}
if ($friendresult !="0"){
$nofriend.= '<li>';
$nofriend.= '<a class="box">';
$nofriend.= '<img src="https://graph.facebook.com/' . $fvalue[id] . '/picture" title="' . $fvalue[name] . '" />';
$nofriend.= '<label>' . $fvalue[name] . '</label>';
$nofriend.= '<div class="totaltext">Score:'.$friendresult. '</div>';
$nofriend.= '</a>';
$nofriend.= '</li>';
}
echo $friend.$nofriend;
Related
I use php ver. 7.1.0 and now I have problem
Fatal error: Switch statements may only contain one default clause in
/icore.php on line 477
Here's the code:
476 case 'html':
477 default:
478 echo $std;
479
480 if ( $desc != '' )
481 echo '<br /><span class="description">' . $desc . '</span>';
482
483 break;
Can I fix it?
Full code for switch:
switch ( $type ) {
case 'heading':
echo '</td></tr><tr valign="top"><td colspan="2"><h4>' . $desc . '</h4>';
break;
case 'checkbox':
echo '<input class="checkbox' . $field_class . '" type="checkbox" id="' . $id . '" name="' . $shortname_options . '[' . $id . ']' . '" value="1" ' . checked( $options[$id], 1, false ) . ' /> <label for="' . $id . '">' . $desc . '</label>';
break;
case 'select':
echo '<select class="select' . $field_class . '" name="' . $shortname_options . '[' . $id . ']' . '">';
foreach ( $choices as $value => $label )
echo '<option value="' . esc_attr( $value ) . '"' . selected( $options[$id], $value, false ) . '>' . $label . '</option>';
echo '</select>';
if ( $desc != '' )
echo '<br /><span class="description">' . $desc . '</span>';
break;
case 'radio':
$i = 0;
foreach ( $choices as $value => $label ) {
echo '<input class="radio' . $field_class . '" type="radio" name="' . $shortname_options . '[' . $id . ']' . '" id="' . $id . $i . '" value="' . esc_attr( $value ) . '" ' . checked( $options[$id], $value, false ) . '> <label for="' . $id . $i . '">' . $label . '</label>';
if ( $i < count( $options ) - 1 )
echo '<br />';
$i++;
}
if ( $desc != '' )
echo '<br /><span class="description">' . $desc . '</span>';
break;
case 'textarea':
echo '<textarea class="' . $field_class . '" id="' . $id . '" name="' . $shortname_options . '[' . $id . ']' . '" placeholder="' . $std . '" rows="5" cols="30">' . wp_htmledit_pre( $options[$id] ) . '</textarea>';
if ( $desc != '' )
echo '<br /><span class="description">' . $desc . '</span>';
break;
case 'password':
echo '<input class="regular-text' . $field_class . '" type="password" id="' . $id . '" name="' . $shortname_options . '[' . $id . ']' . '" value="' . esc_attr( $options[$id] ) . '" />';
if ( $desc != '' )
echo '<br /><span class="description">' . $desc . '</span>';
break;
case 'text':
default:
echo '<input class="regular-text' . $field_class . '" type="text" id="' . $id . '" name="' . $shortname_options . '[' . $id . ']' . '" placeholder="' . $std . '" value="' . esc_attr( $options[$id] ) . '" />';
if ( $desc != '' )
echo '<br /><span class="description">' . $desc . '</span>';
break;
case 'html':
default:
echo $std;
if ( $desc != '' )
echo '<br /><span class="description">' . $desc . '</span>';
break;
case 'upload':
default:
echo '<input id="' . $id . '" class="upload-url' . $field_class . '" type="text" name="' . $shortname_options . '[' . $id . ']' . '" value="' . esc_attr( $options[$id] ) . '" /><input id="st_upload_button" class="st_upload_button" type="button" name="upload_button" value="Upload" />';
if ( $desc != '' )
echo '
<span class="description">' . $desc . '</span>';
echo '<div class="upload-img-preview">';
if (esc_attr( $options[$id] <> '')) {
echo '<img class="upload-img-preview" src='.esc_attr( $options[$id]).' />';
echo '<a class="removeupload">'. __('Delete Image', 'icore') .'</a>';
}
echo '</div>';
break;
case 'slide':
if ( $desc != '' )
echo '<span class="description' . $field_class . '">' . $desc . '</span>';
echo '<br /><span id="slides-details-button"></span>';
echo '<ul id="slideshow_list">';
if ( $options['slider'] <> '' ) {
$slides = array();
foreach ($options[$id]['title'] as $k => $v) {
$slides[] = array(
'title' => $v,
'link' => $options[$id]['link'][$k],
'caption' => $options[$id]['caption'][$k],
'image' => $options[$id]['image'][$k]
);
}
$i = 1;
foreach ($slides as $slide) {
echo '<li class="slide">';
echo '<a class="editslideimage">edit</a>';
echo '<div class="image-details slidedetails">';
echo '<span class="description">' . __( 'Slide Title', 'icore' ) . '</span>';
echo '<input class="regular-text' . $field_class . '" name="' . $shortname_options . '[' . $id . '][title][]" placeholder="' . $std . '" id="'. $id .'_title_'.$i.'" value="'.$slide['title'].'" type="text" />';
echo '<span class="description">' . __( 'Slide Link', 'icore' ) . '</span>';
echo '<input class="regular-text' . $field_class . '" name="' . $shortname_options . '[' . $id . '][link][]" placeholder="' . $std . '" id="'. $id .'_title_'.$i.'" value="'.$slide['link'].'" type="text" />';
echo '<span class="description">' . __( 'Slide Caption', 'icore' ) . '</span>';
echo '<textarea class="'.$field_class.'" name="' . $shortname_options . '[' . $id . '][caption][]" id="'. $id .'_caption_'.$i.'" cols="40" rows="4">'.$slide['caption'].'</textarea>';
echo '<span class="description">' . __( 'Slide Image', 'icore' ) . '</span>';
echo '<input class="upload-input-text src" name="' . $shortname_options . '[' . $id . '][image][]" id="'. $id .'_image_'.$i.'" type="text" value="'.$slide['image'].'" type="text" />
' . __( 'Upload','InterStellar' ) . '';
echo '<a class="doneslideimage">Done</a>';
echo '</div>';
echo '<div class="clear"></div><div class="upload-img-preview">';
if ( $slide['image'] != "" )
{
echo '<img class="upload-img-preview" id="image_'. $id .'_image_'.$i.'" src="'.$slide['image'].'" />';
}
echo '</div>';
echo '<a class="remove_slide submitdelete">' . __( 'Delete Slide', 'InterStellar' ) . '</a>';
echo '</li>';
$i++;
}
} else {
$i = 1;
echo '<li class="slide">';
echo '<span class="description">' . __( 'Slide Title', 'icore' ) . '</span>';
echo '<input class="regular-text' . $field_class . '" name="' . $shortname_options . '[' . $id . '][title][]" placeholder="' . $std . '" id="'. $id .'_title_'.$i.'" value="" type="text" />';
echo '<span class="description">' . __( 'Slide Link', 'icore' ) . '</span>';
echo '<input class="regular-text' . $field_class . '" name="' . $shortname_options . '[' . $id . '][link][]" placeholder="' . $std . '" id="'. $id .'_title_'.$i.'" value="" type="text" />';
echo '<span class="description">' . __( 'Slide Caption', 'icore' ) . '</span>';
echo '<textarea class="'.$field_class.'" name="' . $shortname_options . '[' . $id . '][caption][]" id="'. $id .'_caption_'.$i.'" cols="40" rows="4"></textarea>';
echo '<span class="description">' . __( 'Slide Image', 'icore' ) . '</span>';
echo '<input class="upload-input-text src" name="' . $shortname_options . '[' . $id . '][image][]" id="'. $id .'_image_'.$i.'" type="text" value="" type="text" />
' . __( 'Upload', 'icore' ) . '';
echo '<div class="clear"></div><div class="upload-img-preview">';
echo '</div>';
echo '<a class="remove_slide submitdelete">' . __( 'Delete Slide','InterStellar' ) . '</a>';
echo '</li>';
}
echo '</ul>';
break;
}
}
Is this enought?
You can not use a case statement inside a case. Try this corrected code
switch ( $type ) {
case 'heading':
echo '</td></tr><tr valign="top"><td colspan="2"><h4>' . $desc . '</h4>';
break;
case 'checkbox':
echo '<input class="checkbox' . $field_class . '" type="checkbox" id="' . $id . '" name="' . $shortname_options . '[' . $id . ']' . '" value="1" ' . checked( $options[$id], 1, false ) . ' /> <label for="' . $id . '">' . $desc . '</label>';
break;
case 'select':
echo '<select class="select' . $field_class . '" name="' . $shortname_options . '[' . $id . ']' . '">';
foreach ( $choices as $value => $label )
echo '<option value="' . esc_attr( $value ) . '"' . selected( $options[$id], $value, false ) . '>' . $label . '</option>';
echo '</select>';
if ( $desc != '' )
echo '<br /><span class="description">' . $desc . '</span>';
break;
case 'radio':
$i = 0;
foreach ( $choices as $value => $label ) {
echo '<input class="radio' . $field_class . '" type="radio" name="' . $shortname_options . '[' . $id . ']' . '" id="' . $id . $i . '" value="' . esc_attr( $value ) . '" ' . checked( $options[$id], $value, false ) . '> <label for="' . $id . $i . '">' . $label . '</label>';
if ( $i < count( $options ) - 1 )
echo '<br />';
$i++;
}
if ( $desc != '' )
echo '<br /><span class="description">' . $desc . '</span>';
break;
case 'textarea':
echo '<textarea class="' . $field_class . '" id="' . $id . '" name="' . $shortname_options . '[' . $id . ']' . '" placeholder="' . $std . '" rows="5" cols="30">' . wp_htmledit_pre( $options[$id] ) . '</textarea>';
if ( $desc != '' )
echo '<br /><span class="description">' . $desc . '</span>';
break;
case 'password':
echo '<input class="regular-text' . $field_class . '" type="password" id="' . $id . '" name="' . $shortname_options . '[' . $id . ']' . '" value="' . esc_attr( $options[$id] ) . '" />';
if ( $desc != '' )
echo '<br /><span class="description">' . $desc . '</span>';
break;
case 'text':
echo '<input class="regular-text' . $field_class . '" type="text" id="' . $id . '" name="' . $shortname_options . '[' . $id . ']' . '" placeholder="' . $std . '" value="' . esc_attr( $options[$id] ) . '" />';
if ( $desc != '' )
echo '<br /><span class="description">' . $desc . '</span>';
break;
case 'html':
echo $std;
if ( $desc != '' )
echo '<br /><span class="description">' . $desc . '</span>';
break;
default:
echo '<input id="' . $id . '" class="upload-url' . $field_class . '" type="text" name="' . $shortname_options . '[' . $id . ']' . '" value="' . esc_attr( $options[$id] ) . '" /><input id="st_upload_button" class="st_upload_button" type="button" name="upload_button" value="Upload" />';
if ( $desc != '' )
echo '
<span class="description">' . $desc . '</span>';
echo '<div class="upload-img-preview">';
if (esc_attr( $options[$id] <> '')) {
echo '<img class="upload-img-preview" src='.esc_attr( $options[$id]).' />';
echo '<a class="removeupload">'. __('Delete Image', 'icore') .'</a>';
}
echo '</div>';
break;
case 'slide':
if ( $desc != '' )
echo '<span class="description' . $field_class . '">' . $desc . '</span>';
echo '<br /><span id="slides-details-button"></span>';
echo '<ul id="slideshow_list">';
if ( $options['slider'] <> '' ) {
$slides = array();
foreach ($options[$id]['title'] as $k => $v) {
$slides[] = array(
'title' => $v,
'link' => $options[$id]['link'][$k],
'caption' => $options[$id]['caption'][$k],
'image' => $options[$id]['image'][$k]
);
}
$i = 1;
foreach ($slides as $slide) {
echo '<li class="slide">';
echo '<a class="editslideimage">edit</a>';
echo '<div class="image-details slidedetails">';
echo '<span class="description">' . __( 'Slide Title', 'icore' ) . '</span>';
echo '<input class="regular-text' . $field_class . '" name="' . $shortname_options . '[' . $id . '][title][]" placeholder="' . $std . '" id="'. $id .'_title_'.$i.'" value="'.$slide['title'].'" type="text" />';
echo '<span class="description">' . __( 'Slide Link', 'icore' ) . '</span>';
echo '<input class="regular-text' . $field_class . '" name="' . $shortname_options . '[' . $id . '][link][]" placeholder="' . $std . '" id="'. $id .'_title_'.$i.'" value="'.$slide['link'].'" type="text" />';
echo '<span class="description">' . __( 'Slide Caption', 'icore' ) . '</span>';
echo '<textarea class="'.$field_class.'" name="' . $shortname_options . '[' . $id . '][caption][]" id="'. $id .'_caption_'.$i.'" cols="40" rows="4">'.$slide['caption'].'</textarea>';
echo '<span class="description">' . __( 'Slide Image', 'icore' ) . '</span>';
echo '<input class="upload-input-text src" name="' . $shortname_options . '[' . $id . '][image][]" id="'. $id .'_image_'.$i.'" type="text" value="'.$slide['image'].'" type="text" />
' . __( 'Upload','InterStellar' ) . '';
echo '<a class="doneslideimage">Done</a>';
echo '</div>';
echo '<div class="clear"></div><div class="upload-img-preview">';
if ( $slide['image'] != "" )
{
echo '<img class="upload-img-preview" id="image_'. $id .'_image_'.$i.'" src="'.$slide['image'].'" />';
}
echo '</div>';
echo '<a class="remove_slide submitdelete">' . __( 'Delete Slide', 'InterStellar' ) . '</a>';
echo '</li>';
$i++;
}
} else {
$i = 1;
echo '<li class="slide">';
echo '<span class="description">' . __( 'Slide Title', 'icore' ) . '</span>';
echo '<input class="regular-text' . $field_class . '" name="' . $shortname_options . '[' . $id . '][title][]" placeholder="' . $std . '" id="'. $id .'_title_'.$i.'" value="" type="text" />';
echo '<span class="description">' . __( 'Slide Link', 'icore' ) . '</span>';
echo '<input class="regular-text' . $field_class . '" name="' . $shortname_options . '[' . $id . '][link][]" placeholder="' . $std . '" id="'. $id .'_title_'.$i.'" value="" type="text" />';
echo '<span class="description">' . __( 'Slide Caption', 'icore' ) . '</span>';
echo '<textarea class="'.$field_class.'" name="' . $shortname_options . '[' . $id . '][caption][]" id="'. $id .'_caption_'.$i.'" cols="40" rows="4"></textarea>';
echo '<span class="description">' . __( 'Slide Image', 'icore' ) . '</span>';
echo '<input class="upload-input-text src" name="' . $shortname_options . '[' . $id . '][image][]" id="'. $id .'_image_'.$i.'" type="text" value="" type="text" />
' . __( 'Upload', 'icore' ) . '';
echo '<div class="clear"></div><div class="upload-img-preview">';
echo '</div>';
echo '<a class="remove_slide submitdelete">' . __( 'Delete Slide','InterStellar' ) . '</a>';
echo '</li>';
}
echo '</ul>';
break;
}
}
Building a page that outputs each result from a search based on location/distance/w.e however I want the first result to be a "recommended" page if it falls within the search parameters. Each entry in the database has a row "recommended" and either yes or no.
If its =="yes" then it changes the background to yellow however if could be the 3rd, 6th and 17th result in the list. I want it so it shows 1 recommended at the top of the search results and then the rest and normal.
Search results so far:
while($row = mysql_fetch_array( $result )) {
if ($row['recommended'] == "Yes") {
echo '<div id="results_box_site" style="background-color: #ffffdf;">';
}
else {
echo '<div id="results_box_site">';
}
echo '<img class="results_site_image" src="' . $row['site_logo'] . '" />';
echo '<h1><a href="site.php?id=' . $row['site_ID'] . '">' . $row['site_name'];
if ($row['recommended'] == "Yes") {
echo ' - Recommended site';
}
echo '</a></h1>';
echo '<h2>Next game date: ' . $row['next_game'] . '</h2>
<img src="images/rating/5star.png" /> (rating 5/5 - 2 reviews)
<p id="results_box_content">';
echo $row['short_desc'];
echo '<br/><br/> >> More information <<
</p>
<h3 id="results_box_content">Facilities</h3>
<div id="details">
<ul>';
echo '<li>' . $row['lunch'] . '</li>';
echo '<li>' . $row['shop'] . '</li>';
echo '<li>' . $row['toilets'] . '</li>';
echo '<li>Minimum age: ' . $row['min_age'] . '</li>';
echo '<li>Game Type: ' . $row['game_type'] . '</li>';
echo '<li>Site Type: ' . $row['site_type'] . '</li>';
echo '<li>' . $row['price'] . '</li>';
echo '<li>' . $row['packages'] . '</li>';
echo '</ul>
</div>
</div>';
}
Messy code I know but any help would be appreaciated
You want to do this in your query. Add this to the end of your query:
ORDER BY `recommended` DESC
It will return the recommended ones first and then the non-recommended one.s
This assumes the valid values for that column is "Yes" and "No"
Im wondering if its possible with PHP to add a class to X record returned. I know I can do this with JS only I'd like it to have the class added as the records are returned.
I have the following loop in my PHP, From what I've found in google I need to add a counter to do this only I've been unsuccessful so far...
while ($row = $sth->fetch(PDO::FETCH_ASSOC)) {
echo '<div class="entry span3"><span class="name">' . $row['First_Name'] . ' ' . $row['Surname'] . "</span>";
echo '<img src="' . $row["picture_1"] . '" alt="' . $row['First_Name'] . ' ' . $row['Surname'] . ', text ' . $row['Date'] . ' ">';
echo '<span class="from">seen in ' . ucwords($row["Location_County__Seen"]) . '</span>View Profile</div>';
}
In front of your while, add $c = 1
Before the end of your while loop, add $c++;
Then, modify your first line:
echo '<div class="entry span3"><span class="name">'
To
echo '<div class="entry span3';
if (($c % 4) == 1) echo ' newclassname ';
echo '"><span class="name">'
For the final result:
$c = 1;
while ($row = $sth->fetch(PDO::FETCH_ASSOC)) {
echo '<div class="entry';
if (($c % 4) == 1) echo ' newclassname ';
echo ' span3"><span class="name">' . $row['First_Name'] . ' ' . $row['Surname'] . "</span>";
echo '<img src="' . $row["picture_1"] . '" alt="' . $row['First_Name'] . ' ' . $row['Surname'] . ', text ' . $row['Date'] . ' ">';
echo '<span class="from">seen in ' . ucwords($row["Location_County__Seen"]) . '</span>View Profile</div>';
$c++;
}
I want to implement this <img src="<?php echo z_taxonomy_image_url($cat->term_id); ?>" /> into the following function.
function list_my_categories($exclude = '') {
if (!empty($exclude)) {
$exclude = 'exclude=' . $exclude;
}
$categories = get_categories($exclude);
$html = '';
foreach ($categories as $cat) {
if($cat->category_parent == 0) {
<img src="<?php echo z_taxonomy_image_url($cat->term_id); ?>" />
$html .= '<p>' . $cat->cat_name . '</p>';
$html .= '<p>' . $cat->category_description . '</p>';
$childcategories = get_categories('child_of='.$cat->cat_ID.'');
if(!empty($childcategories)){
foreach ($childcategories as $ccat) {
$html .= '<p>' . $ccat->cat_name . '</p>';
$html .= '<p>' . $ccat->category_description . '</p>';
}
}
}
}
return $html;
}
add_shortcode('show-cats', 'list_my_categories');
The function shows a list of categories in WordPress, and I have another plugin which allows you to set an image for each category, so i am trying to show it...
if($cat->category_parent == 0)
{
$html .= '<img src="' . z_taxonomy_image_url($cat->term_id) . '" />';
$html .= '<p>' . $cat->cat_name . '</p>';
$html .= '<p>' . $cat->category_description . '</p>';
$childcategories = get_categories('child_of='.$cat->cat_ID.'');
if(!empty($childcategories))
{
foreach ($childcategories as $ccat)
{
/*$html .= '<img src="' . z_taxonomy_image_url($ccat->term_id) . '" />';*/
$html .= '<p>' . $ccat->cat_name . '</p>';
$html .= '<p>' . $ccat->category_description . '</p>';
}
}
}
I have this code to pull data from the database and insert the data into one of 4 columns,
I have spent a whole day searching and just cant seem to find out how to do it..
Ideally, I want to select all from database and then where the fetch array has a column id of 1 - echo that then the sama for the next column etc..
<?php
echo '<div class="column grid_3 clearfix" id="column0" >';
echo ' ';
$user_sites_0=mysqli_query($connection, "SELECT * FROM user_sites WHERE column_id='0' ORDER BY sort_no");
if(!$user_sites_0) {
echo 'No sites added, please <a class="addsite" href="#">add one now</a>';
}
else {
while($user_site_0=mysqli_fetch_array($user_sites_0))
{
$id = stripslashes($user_site_0['id']);
$site_name = stripslashes($user_site_0['site_name']);
$site_address = stripslashes($user_site_0['site_address']);
$site_desc = stripslashes($user_site_0['site_desc']);
$site_category = stripslashes($user_site_0['site_category']);
$getImage = 'http://immediatenet.com/t/s?Size=1024x768&URL='.$site_address;
echo '<div class="dragbox" id="item'.$id.'">';
echo '<h2 class="h2handle">'.$site_name.' <span class="close"><img src="assets/img/closepanel.png"></span></h2>';
echo '<div class="dragbox-content" ';
if($user_site_0['collapsed']==1)
echo 'style="display:none;" ';
echo '>';
echo '<p><a class="sitelink" href="' . $site_address . '" title="'.$site_name.'"><img src="'.$getImage.'" alt="'.$site_name.'" title="'.$site_name.'"/></a>';
echo '<p>' . $site_category . '</p>';
echo '<p>' . $site_address . '</p>';
echo '<p>' . $site_desc . '</p>';
echo' </div>
</div>';
}
}
echo '</div>';
?>
<?php
echo '<div class="column grid_3 clearfix" id="column1" >';
echo ' ';
$user_sites_1=mysqli_query($connection, "SELECT * FROM user_sites WHERE column_id='1' ORDER BY sort_no");
if(!$user_sites_1) {
echo '';
}
else {
while($user_site_1=mysqli_fetch_array($user_sites_1))
{
$id = stripslashes($user_site_1['id']);
$site_name = stripslashes($user_site_1['site_name']);
$site_address = stripslashes($user_site_1['site_address']);
$site_desc = stripslashes($user_site_1['site_desc']);
$site_category = stripslashes($user_site_1['site_category']);
$getImage = 'http://immediatenet.com/t/s?Size=1024x768&URL='.$site_address;
echo '<div class="dragbox" id="item'.$id.'">';
echo '<h2 class="h2handle">'.$site_name.' <span class="close"><img src="assets/img/closepanel.png"></span></h2>';
echo '<div class="dragbox-content" ';
if($user_site_1['collapsed']==1)
echo 'style="display:none;" ';
echo '>';
echo '<p><a class="sitelink" href="' . $site_address . '" title="'.$site_name.'"><img src="'.$getImage.'" alt="'.$site_name.'" title="'.$site_name.'"/></a>';
echo '<p>' . $site_category . '</p>';
echo '<p>' . $site_address . '</p>';
echo '<p>' . $site_desc . '</p>';
echo' </div>
</div>';
}
}
echo '</div>';
?>
<?php
echo '<div class="column grid_3 clearfix" id="column2">';
echo ' ';
$user_sites_2=mysqli_query($connection, "SELECT * FROM user_sites WHERE column_id='2' ORDER BY sort_no");
if(!$user_sites_2) {
echo '';
}
else {
while($user_site_2=mysqli_fetch_array($user_sites_2))
{
$id = stripslashes($user_site_2['id']);
$site_name = stripslashes($user_site_2['site_name']);
$site_address = stripslashes($user_site_2['site_address']);
$site_desc = stripslashes($user_site_2['site_desc']);
$site_category = stripslashes($user_site_2['site_category']);
$getImage = 'http://immediatenet.com/t/s?Size=1024x768&URL='.$site_address;
echo '<div class="dragbox" id="item'.$id.'">';
echo '<h2 class="h2handle">'.$site_name.' <span class="close"><img src="assets/img/closepanel.png"></span></h2>';
echo '<div class="dragbox-content" ';
if($user_site_2['collapsed']==1)
echo 'style="display:none;" ';
echo '>';
echo '<p><a class="sitelink" href="' . $site_address . '" title="'.$site_name.'"><img src="'.$getImage.'" alt="'.$site_name.'" title="'.$site_name.'"/></a>';
echo '<p>' . $site_category . '</p>';
echo '<p>' . $site_address . '</p>';
echo '<p>' . $site_desc . '</p>';
echo' </div>
</div>';
}
}
echo '</div>';
?>
<?php
echo '<div class="column grid_3 clearfix" id="column3">';
echo ' ';
$user_sites_3=mysqli_query($connection, "SELECT * FROM user_sites WHERE column_id='3' ORDER BY sort_no");
while($user_site_3=mysqli_fetch_array($user_sites_3))
{
$id = stripslashes($user_site_3['id']);
$site_name = stripslashes($user_site_3['site_name']);
$site_address = stripslashes($user_site_3['site_address']);
$site_desc = stripslashes($user_site_3['site_desc']);
$site_category = stripslashes($user_site_3['site_category']);
$getImage = 'http://immediatenet.com/t/s?Size=1024x768&URL='.$site_address;
echo '<div class="dragbox" id="item'.$id.'">';
echo '<h2 class="h2handle">'.$site_name.' <span class="close"><img src="assets/img/closepanel.png"></span></h2>';
echo '<div class="dragbox-content" ';
if($user_site_3['collapsed']==1)
echo 'style="display:none;" ';
echo '>';
echo '<p><a class="sitelink" href="' . $site_address . '" title="'.$site_name.'"><img src="'.$getImage.'" alt="'.$site_name.'" title="'.$site_name.'"/></a>';
echo '<p>' . $site_category . '</p>';
echo '<p>' . $site_address . '</p>';
echo '<p>' . $site_desc . '</p>';
echo' </div>
</div>';
}
echo '</div>';
?>
The code looks a right state.. Could I do it better?
Use for and change the code, some code :
<?php
for ($i=0; $i<4; $i++)
{
echo '<div class="column grid_3 clearfix" id="column'.$i.'" >';
echo ' ';
$user_sites=mysqli_query($connection, "SELECT * FROM user_sites WHERE column_id='".$i."' ORDER BY sort_no");
if(!$user_sites) {
echo 'No sites added, please <a class="addsite" href="#">add one now</a>';
}
else
{
while($user_site=mysqli_fetch_array($user_sites))
{
... // Do it yourself
maybe
function get_site($column_id){
$str = "";
$user_sites = mysqli_query($connection, "SELECT * FROM user_sites WHERE column_id='".$column_id."' ORDER BY sort_no");
if(!$user_sites_0) {
echo 'No sites added, please <a class="addsite" href="#">add one now</a>';
}
else {
while($user_site_0=mysqli_fetch_array($user_sites_0))
{
$id = stripslashes($user_site_0['id']);
$site_name = stripslashes($user_site_0['site_name']);
$site_address = stripslashes($user_site_0['site_address']);
$site_desc = stripslashes($user_site_0['site_desc']);
$site_category = stripslashes($user_site_0['site_category']);
$getImage = 'http://immediatenet.com/t/s?Size=1024x768&URL='.$site_address;
$str.= '<div class="dragbox" id="item'.$id.'">';
$str.= '<h2 class="h2handle">'.$site_name.' <span class="close"><img src="assets/img/closepanel.png"></span></h2>';
$str.= '<div class="dragbox-content" ';
if($user_site_0['collapsed']==1)
echo 'style="display:none;" ';
$str.= '>';
$str.= '<p><a class="sitelink" href="' . $site_address . '" title="'.$site_name.'"><img src="'.$getImage.'" alt="'.$site_name.'" title="'.$site_name.'"/></a>';
$str.= '<p>' . $site_category . '</p>';
$str.= '<p>' . $site_address . '</p>';
$str.= '<p>' . $site_desc . '</p>';
$str.=' </div>
</div>';
}
}
$str.='</div>';
return $str;}
echo '<div class="column grid_3 clearfix" id="column0">';
echo ' ';
echo oget_site(0);
echo '<div class="column grid_3 clearfix" id="column1">';
echo ' ';
echo oget_site(1);
//....