Warning: in_array() expects parameter 2 to be array, object given in /home4/hsysgrpc/public_html/wp-content/themes/twentytwelve-child/custom-page_Members_Desc.php on line 91
same result, All those Books and the checkbox displays, but no check.
Where is the value being “TRUE” being passed? I guess I am not understanding where in the code the logic of
If value = “true”, check box, if not, not being enabled?
Thank you for taking all this trouble.
Yes. I made a mistake earlier.
Use this :
echo '<tr><th>All Those Books</th><td><input type="checkbox" name="AllThoseBooks" value="AllThoseBooks" ' . checked( in_array("AllThoseBooks", $row)) . ' /></td></tr>';
not this :
echo "<tr><th>All Those Books</th><td><input type=checkbox name=AllThoseBooks value='".$row->AllThoseBooks."'></td></tr>";
Yes, it not easy to program like this! Lol
You can see here what the second paramter should look like – which you have in $row
https://www.w3schools.com/php/func_array_in_array.asp
Good Morning, I’m back.
echo ‘<tr><th>All Those Books</th><td><input type=”checkbox” name=”AllThoseBooks” value=”AllThoseBooks” ‘ . checked( in_array(“AllThoseBooks”, $row)) . ‘ /></td></tr>’;
produces:
Warning: in_array() expects parameter 2 to be array, object given in /home4/hsysgrpc/public_html/wp-content/themes/twentytwelve-child/custom-page_Members_Desc.php on line 91
parameter 2 is an array? of the fields? ie, ID, FirstName, etc. Should we be examining the values of the fields somehow?
It’s getting very tedious to try to program by only seeing a tiny snippet of your entire code. Can you dump the entire file contents into pastebin pls :
https://pastebin.com/
Be sure to remove all references to usernames, password, database names, etc obviously.
I just pasted it. Thank you for your patience.
Lol. Yes, but then you need to share the link to it!
Sorry, first time. link is hsysgrp, DebugDutchess2021 name of paste is checkbox.
Hi @hsysgrp
You will need to provide a hyperlink URL that would have been provided to you from pastebin.com
Was that the correct link?
Yes.
You are going to have to check each checkbox value in it’s own array.
Inside this loop :
foreach($retrieve_data as $row){
add all your checkboxes into an array value like this :
$checkboxes = array(
'AdventuresEnSoleil'
'Bridge'
'Canasta'
'ContemporaryLit'
'Cuisine'
);
Then just use another foreach to print out all the boxes like this :
foreach ( $checkboxes as $cb ) {
$checked = ( $row->$cb == '1' ) ? 'checked' : '';
echo '<tr><th>LOOP ' . $cb . '</th><td><input type="checkbox" name="' . $cb . '" value="' . $cb . '" ' . $checked . ' /></td></tr>';
}
Putting it all together will be like this :
https://pastebin.com/LAw3cf62
I inserted your code, added commas to the array, and changed the data from “TRUE” to “1” and am looking at little blue check marks! thank you, I would never have figured out that syntax on my own.
` echo “<table>”;
echo “<tbody>”;
$checkboxes = array(
‘AllThoseBooks’,
‘ArtOnTheGo’,
‘AdventuresEnSoleil’,
‘Bridge’,
‘Canasta’,
‘ContemporaryLit’,
‘Cuisine’
);
foreach( $checkboxes as $cb) {
$checked = ($row->$cb == ‘1’) ? ‘checked’: ”;
echo ‘<tr><th>’. $cb .'</th><td><input type=”checkbox” name=”‘. $cb .'” value=”‘ . $cb .'” ‘ . $checked . ‘ /></td></tr>’;
}`
Great!
If you want to add in the headings into the checkboxes, i.e.
Ties with Community Organizations
it will get a little trickier. You would need to put conditional loops that check for the first value of the checkbox array, and insert the heading.
such as,
if $cb == ‘CivicActionGroups’
echo ‘Ties with Community Organizations’
Or, you could add these headings to you select statement.