PHP - define variable with condition while doing it - php

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>'

Related

How to show more info of the table

I have table with informations from database. There are ID, Name, Subject and Date. And I want to show more data like Message, OS, IP etc. when I click on one line (tr) of table. I found solution, but it is woking only on the first tr, not all.
Here is my code:
while($row = $result->fetch_assoc())
{
$id=$row['ID'];
$name=$row['Name'];
$mail=$row['Email'];
$subject=$row['Subject'];
$message=$row['Message'];
$date=$row['Date'];
$ip=$row['IP'];
$device=$row['Device'];
$os=$row['OS'];
$browser=$row['Browser'];
$finish=$row['Finish'];
echo
'<tr class="trX" id="flip">
<td class="tdX">' . $id . '</td>
<td class="tdX">' . $name . '</td>
<td class="tdX">' . $subject . '</td>
<td class="tdX">' . $date . '</td>
<div id="panel">
ID:' . $id . '
Name:' . $name . '
Email:' . $mail . '
Subject:' . $subject . '
Message:' . $message . '
Date:' . $date . '
IP:' . $ip . '
Mobile:' . $device . '
OS:' . $os . '
Browser:' . $browser . '
Finish:' . $finish . '
</div>
</tr>';
}
echo ' </table> ';
And JS Query
$(document).ready(function(){
$("#flip").click(function(){
$("#panel").slideToggle("slow");
});
});
Thanks for tips
It's only working on first tr because you can not reuse the ID flip for other elements. Few solutions I can think of:
Have a variable which increments and assign it to the id like flip-i, i here is the incrementing variable. Attach click event to this and then toggle the child elements.
Attach click event to a class and then toggle children of that clicked class.
I changed your code this way:
<tr class="trX" id="flip_".$i onclick="flippanel($i)">
<td class="tdX">' . $id . '</td>
<td class="tdX">' . $name . '</td>
<td class="tdX">' . $subject . '</td>
<td class="tdX">' . $date . '</td>
<div id="panel_".$i>
ID:' . $id . '
Name:' . $name . '
Email:' . $mail . '
Subject:' . $subject . '
Message:' . $message . '
Date:' . $date . '
IP:' . $ip . '
Mobile:' . $device . '
OS:' . $os . '
Browser:' . $browser . '
Finish:' . $finish . '
</div>
</tr>
In jQuery you can call this like
function flippanel(i)
Then you can access panel by individual ID easily

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

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

Want to increase width of specific column in table php

Here are the columns like student id, student name and question 1 etc. I want to increase the width of column "question". How can I do this?
I tried add width through adding object in table header tag like width="100", it works as simple html code but doesn't work here in my required code. `
<?php
if (isset($result_display)) {
echo "<p><u>Result</u></p>";
if ($result_display == 'No record found !') {
echo $result_display;
} else {
echo "<table class='result_table'>";
echo '<tr><th>Student ID</th><th>Student Name</th><th>Question#1</th><th>Answer#1</th><th>Question#2</th><th>Answer#2</th><th>Question#3</th><th>Answer#3</th><th>Question#4</th><th>Answer#4</th><th>Question#5</th><th>Answer#5</th><th>Question#6</th><th>Answer#6</th><th>Question#7</th><th>Answer#7</th><th>Question#8</th><th>Answer#8</th><th>Question#9</th><th>Answer#9</th><th>Question#10</th><th>Answer#10</th><th>Question#11</th><th>Answer#11</th><th>Question#12</th><th>Answer#12</th><th>Question#13</th><th>Answer#13</th><th>Question#14</th><th>Answer#14</th><th>Question#15</th><th>Answer#15</th><tr/>';
foreach ($result_display as $value) {
echo '<tr>' . '<td class="e_id">' . $value->id . '</td>' .'<td class="name">' . $value->Student_name . '</td>' . '<td>' . $value->question1 . '</td>' . '<td class="j_date">' . $value->Answer1 . '</td>' . '<td>' . $value->question2 . '</td>' . '<td class="mob">' . $value->Answer2 . '</td>' . '<td >' . $value->question3 . '</td>' . '<td>' . $value->Answer3 . '</td>' . '<td>' . $value->question4 . '</td>' . '<td>' . $value->Answer4 . '</td>' . '<td>' . $value->question5 . '</td>' . '<td>' . $value->Answer5 . '</td>' . '<td>' . $value->question6 . '</td>' . '<td>' . $value->Answer6 . '</td>' . '<td>' . $value->question7 . '</td>' . '<td>' . $value->Answer7 . '</td>' . '<td>' . $value->question8 . '</td>' . '<td>' . $value->Answer8 . '</td>' . '<td>' . $value->question9 . '</td>' . '<td>' . $value->Answer9 . '</td>' . '<td>' . $value->question10 . '</td>' . '<td>' . $value->Answer10 . '</td>' . '<td>' . $value->question11 . '</td>' . '<td>' . $value->Answer11 . '</td>' . '<td>' . $value->question12 . '</td>' . '<td>' . $value->Answer12 . '</td>' . '<td>' . $value->question13 . '</td>' . '<td>' . $value->Answer13 . '</td>' . '<td>' . $value->question14 . '</td>' . '<td>' . $value->Answer14 . '</td>' . '<td>' . $value->question15 . '</td>' . '<td>' . $value->Answer15 . '</td>' . '<tr/>';
}
echo '</table>';
}
}
?>
</div>
</div>
Use a style attribute in the th tag e.g.
<th style="width: 100px;">Question#1</th>
This should do the job, otherwise, you can also use % e.g.
<th style="width: 30%;">Question#1</th>

Update a whole table with mysqli and php

I have created a page to list all users with their rights on the website. I used the code below to create and fill the table and it works great.
echo '<form method="post" id="detail" class="group" action="includes/setup_change.php?change=rights">';
echo '<div class="group">';
if (!empty($_GET['change'])) {
if ($_GET['change'] == 'rights') { echo '<span class="message_alert success"><span class="icon success"></span><span class="text">' . _('Your password was successfully changed') . '.</span></span>'; }
}
echo '<h2>' . _('Change') . ' ' . _('rights') . '</h2>';
// select database
mysqli_select_db( $mysqli, 'db_ccadmin' );
// check connection
if ( $mysqli->connect_errno > 0 ) {
trigger_error( _('Database connection failed') . ': ' . $mysqli->connect_error, E_USER_ERROR );
}
// sql query
$sql = "SELECT * FROM users";
$res = $mysqli->query( $sql );
if( !$res ) {
trigger_error( _('Wrong') . ' SQL: [' . $sql . ']. ' . _('Error') . ' : [' . $mysqli->error . ']' );
} else {
echo '<table id="table_sort_no_search">';
echo '<thead><tr>
<th class="username">' . _('Username') . '</th>
<th class="readonly">' . _('Read-only') . '</th>
<th class="manage">' . _('Manage') . '</th>
<th class="admin">' . _('Admin') . '</th>
</tr></thead>';
echo '<tbody>';
// output query results
while($row = $res->fetch_assoc()) {
echo '<tr>';
echo '<td><input type="text" name="username" value="' . $row['username'] . '" readonly></td>';
echo '<td><label><input type="radio" class="rights" name="rights_' . $row['username'] . '" value="1" ' . (isset($row['rights']) ? (($row['rights'] == '1') ? 'checked="checked"' : '' ) : '') . '></label></td>';
echo '<td><label><input type="radio" class="rights" name="rights_' . $row['username'] . '" value="2" ' . (isset($row['rights']) ? (($row['rights'] == '2') ? 'checked="checked"' : '' ) : '') . '></label></td>';
echo '<td><label><input type="radio" class="rights" name="rights_' . $row['username'] . '" value="3" ' . (isset($row['rights']) ? (($row['rights'] == '3') ? 'checked="checked"' : '' ) : '') . '></label></td>';
echo '</tr>';
}
echo '</tbody>';
echo '</table>';
// free results to free up some system resources
$res->free();
The trouble is updating the whole table in the database. I don't know how to do this. Is it even possible to update the whole table (as generated) at once? If yes, how?
What would be the code that I need to put in my setup_change.php?
It would be great if you could help me!
It is not clear what you want to update, but this is how you can update (example):
$mysqli->query("UPDATE birthday SET Manage = null");
Of course, this does not solve your problem, as there is infinite ways to update the whole table. What table do you want to update, what values do you want to set?

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

Categories