Fatal error: Switch statements may only contain one default clause (php7) - php

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;
}
}

Related

If Statement Inside Html

I am trying to use an IF statement if variable $credit is not empty. However, I get a parse error. Could anyone please help with my syntax?
$credit = get_field('fl_credit', $image['id']);
return '<div class="kalim"><img title="' .
esc_attr( sprintf( the_title_attribute( 'echo=0' ) ) ) .
'" alt="' . esc_attr( sprintf( the_title_attribute( 'echo=0' ) ) ) .
'" src="' . $image['url'] . '" /><div class="kalca">' .
$image['caption'] . '</div>' .
if($credit) {'<div class="kalcr">Credit:' . $credit . '</div></div>' };
Without knowing the error, I suggest do a short if, so:
$credit = get_field('fl_credit', $image['id']);
return '<div class="kalim"><img title="' .
esc_attr( sprintf( the_title_attribute( 'echo=0' ) ) ) .
'" alt="' . esc_attr( sprintf( the_title_attribute( 'echo=0' ) ) ) .
'" src="' . $image['url'] . '" /><div class="kalca">' .
$image['caption'] . '</div>' .
(!empty($credit) ? '<div class="kalcr">Credit:' . $credit . '</div></div>': '' ) ;
You can see more here
Check this if it help you
<?php
$credit = get_field('fl_credit', $image['id']);
$return_data = '<div class="kalim"><img title="'.esc_attr( sprintf( the_title_attribute( 'echo=0' ) ) ) . '" alt="' . esc_attr( sprintf( the_title_attribute( 'echo=0' ) ) ) . '" src="' . $image['url'] . '" /><div class="kalca">' . $image['caption'] . '</div>';
if(!empty($credit)){
$return_data .= '<div class="kalcr">Credit:' . $credit . '</div>';
}
$return_data .= '</div>';
return $return_data;
?>

PHP - define variable with condition while doing it

I don't know how to describle it, just look at the code:
$html =
'<table>
<tr>
<td>'
if(strlen($parse['abweichend_name']) > 2)
{
'Lieferanschrift<br>' . $parse['abweichend_firma'] . '<br>' . $parse['abweichend_name'] . '<br>' . $parse['abweichend_strasse'] . '<br>' . $parse['abweichend_plz'] . ' ' . $parse['abweichend_ort'];
}
else
{
'Lieferanschrift<br>' . $parse['firma'] . '<br>' . $parse['name'] . '<br>' . $parse['strasse'] . '<br>' . $parse['plz'] . ' ' . $parse['ort'];
}
'</td>
<td align="right" valign="top">
<font size="5" color="#808080">bla</font>
</td>
</tr>
</table>';
Is it even possible to do it somehow? xD I know how to do it right/normally but just wonder if there is any way to do it this way
In your case, as all fields have prefix abweichend_ you can do this:
$html = '<table><tr><td>';
$prefix = strlen($parse['abweichend_name']) > 2? 'abweichend_' : '';
$html .= 'Lieferanschrift<br>' . $parse[$prefix . 'firma'] . '<br>' . $parse[$prefix . 'name'] . '<br>' . $parse[$prefix . 'strasse'] . '<br>' . $parse[$prefix . 'plz'] . ' ' . $parse[$prefix . 'ort'];
$html .= '</td><td align="right" valign="top"><font size="5" color="#808080">bla</font></td></tr></table>';
And of course, I replaced $html = $html . "string" with $html .= "string".
You can use a normal if condition and append to the string variable.
$html = '<table><tr><td>';
if(strlen($parse['abweichend_name']) > 2) {
$html = $html . 'Lieferanschrift<br>' . $parse['abweichend_firma'] . '<br>' . $parse['abweichend_name'] . '<br>' . $parse['abweichend_strasse'] . '<br>' . $parse['abweichend_plz'] . ' ' . $parse['abweichend_ort'];
} else {
$html = $html . 'Lieferanschrift<br>' . $parse['firma'] . '<br>' . $parse['name'] . '<br>' . $parse['strasse'] . '<br>' . $parse['plz'] . ' ' . $parse['ort'];
}
$html = $html . '</td><td align="right" valign="top"><font size="5" color="#808080">bla</font></td></tr></table>';
Or you can use the ternary operator, but in my opinion the readability of this solution is worse.
$html = '<table><tr><td>' .
(strlen($parse['abweichend_name']) > 2) ?
('Lieferanschrift<br>' . $parse['abweichend_firma'] . '<br>' . $parse['abweichend_name'] . '<br>' . $parse['abweichend_strasse'] . '<br>' . $parse['abweichend_plz'] . ' ' . $parse['abweichend_ort']) :
('Lieferanschrift<br>' . $parse['firma'] . '<br>' . $parse['name'] . '<br>' . $parse['strasse'] . '<br>' . $parse['plz'] . ' ' . $parse['ort']) .
'</td><td align="right" valign="top"><font size="5" color="#808080">bla</font></td></tr></table>'

PHP query - on 1st, 5th, 9th record add a class

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++;
}

How to sort from for each in PHP

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;

Could this code be cleaner?? It looks a right state?

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);
//....

Categories