close ad
Databridge V2 with MySQLi support IS Now Available!
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Sending query like array with coma separated to URL and echo the selected checkbox

Thread began 3/21/2021 8:55 am by Rokon | Last modified 3/24/2021 8:04 pm by Ray Borduin | 105 views | 8 replies |

Rokon

Sending query like array with coma separated to URL and echo the selected checkbox

Hello

I am having a problem to send coma separated value to url which is like as below;

I have created a repeat region where all the books names shows in separate checkbox, after that i select some random book by selecting the checkbox and after submit the value for search it shows url like book=3&book=20&book=8 and for this only the result comes from one book only and not from all the books but if i can send the query like book=3,20,8 then I get the results from all the books.

Also I need to echo back the selected checkbox which I selected before passing the query so that I know which books I selected.

The example live page is

https://www.hadithbd.com/hadith/search/filter/?q=%E0%A6%86%E0%A6%A6%E0%A6%AE&book=3&book=20&book=8&lang=bn&WADbSearch1=

Please help. I am sending the login info in the PM

Sign in to reply to this post

Ray BorduinWebAssist

To send multiple books, the url would be: https://www.hadithbd.com/hadith/search/filter/?q=%E0%A6%86%E0%A6%A6%E0%A6%AE&book[]=3&book[]=20&book[]=8&lang=bn&WADbSearch1=

you have to add the [] to allow it to be an array and pass multiple values.

Sign in to reply to this post
Did this help? Tips are appreciated...

Rokon

Originally Said By: Ray Borduin
  To send multiple books, the url would be: https://www.hadithbd.com/hadith/search/filter/?q=%E0%A6%86%E0%A6%A6%E0%A6%AE&book[]=3&book[]=20&book[]=8&lang=bn&WADbSearch1=

you have to add the [] to allow it to be an array and pass multiple values.  



Hello Ray

I tried like that but seems somewhere I am doing something wrong and for this reason now I don't get any result.

<?php
$SearchPage = new WA_MySQLi_RS("SearchPage",$hadithbd,20);
$SearchPage->setQuery("SELECT hadithmain.HadithID, hadithmain.BookID, hadithmain.SectionID, hadithmain.HadithNo, hadithmain.hadithNo2, hadithmain.hadithNo3, hadithmain.ArabicHadith, hadithmain.ArabicHadithNew, hadithmain.BanglaHadith, hadithmain.EnglishHadith, hadithmain.HadithNote, hadithbook.BookNameBD, hadithchapter.ChapterBG, hadithchapter.ChapterAR, hadithchapter.ChapterEN, hadithexplanation.explanation, hadithstatus.StatusBG, hadithsection.SectionBD, hadithsection.SectionEN FROM hadithmain LEFT OUTER JOIN hadithbook ON hadithmain.BookID = hadithbook.BookID LEFT OUTER JOIN hadithchapter ON hadithmain.chapterID = hadithchapter.chapID LEFT OUTER JOIN hadithexplanation ON hadithmain.HadithID = hadithexplanation.hadithID LEFT OUTER JOIN hadithstatus ON hadithmain.HadithStatus = hadithstatus.StatusID LEFT OUTER JOIN hadithsection ON hadithmain.SectionID = hadithsection.SectionID WHERE hadithmain.HadithActive = 1 AND hadithmain.BookID IN (?)");
$SearchPage->bindParam("il", "".(isset($_GET['book[]'])?$_GET['book[]']:"") ."", "-1"); //WAQB_Param1
$SearchPage->execute();?>

-----------------
<div class="form-check">
<?php
$wa_startindex = 0;
while(!$booksList->atEnd()) {
$wa_startindex = $booksList->Index;
?>
<label class="form-check-label pl-3">
<input name="book[]" type="checkbox" class="form-check-input" value="<?php echo($booksList->getColumnVal("BookID")); ?>"><?php echo($booksList->getColumnVal("BookNameBD")); ?>
</label>
<?php
$booksList->moveNext();
}
$booksList->moveFirst(); //return RS to first record
unset($wa_startindex);
unset($wa_repeatcount);
?>
</div>

Sign in to reply to this post

Ray BorduinWebAssist

You have to turn the array back into a comma separated string in the recordset like:

$SearchPage->bindParam("il", "".(isset($_GET['book'])?implode(","$_GET['book']):"") ."", "-1"); //WAQB_Param1

Sign in to reply to this post
Did this help? Tips are appreciated...

Rokon

Originally Said By: Ray Borduin
  You have to turn the array back into a comma separated string in the recordset like:

$SearchPage->bindParam("il", "".(isset($_GET['book'])?implode(","$_GET['book']):"") ."", "-1"); //WAQB_Param1  



=====
it shows some error and I think it should be like as below;

$SearchPage->bindParam("il", "".(isset($_GET['book'])?implode(",",$_GET['book']):"") ."", "-1"); //WAQB_Param1

=====
Meanwhile just little more help needed to echo back the checked status that means shows back which books I was selected for the query on below code

<input name="book[]" type="checkbox" class="form-check-input" value="<?php echo($booksList->getColumnVal("BookID")); ?>"><?php echo($booksList->getColumnVal("BookNameBD")); ?>

Sign in to reply to this post

Ray BorduinWebAssist

How can you tell which ones were checked? Is this on the results page? I need context. Where could I get the previously selected checkboxes? $_GET?

Sign in to reply to this post
Did this help? Tips are appreciated...

Rokon

Originally Said By: Ray Borduin
  How can you tell which ones were checked? Is this on the results page? I need context. Where could I get the previously selected checkboxes? $_GET?  



Dear Ray

I made one separate post on this subject though. This is on the same result page on a form and pls see below the code

===================

<form name="searchForm" action="/hadith/search/filter/" method="GET" accept-charset="UTF-8">
<div class="form-row">
<div class="col-md-6 col-sm-12 my-1">
<input class="form-control" type="text" name="q" value="<?php echo ((isset($_GET["q"]))?$_GET["q"]:""); ?>" placeholder="যে শব্দ দিয়ে খুঁজতে চান..." required>
</div>

<div class="col-auto my-1">
<select name="lang" id="lang" class="custom-select mr-sm-2" required>
<option value="">-ভাষা সিলেক্ট-</option>
<option value="bn" <?php if (!(strcmp("bn", ((isset($_GET["lang"]))?$_GET["lang"]:"")))) {echo "selected=\"selected\"";} ?>>শুধু বাংলা</option>
<option value="en" <?php if (!(strcmp("en", ((isset($_GET["lang"]))?$_GET["lang"]:"")))) {echo "selected=\"selected\"";} ?>>English only</option>
<option value="ar" <?php if (!(strcmp("ar", ((isset($_GET["lang"]))?$_GET["lang"]:"")))) {echo "selected=\"selected\"";} ?>>العربية</option>
<option value="all"<?php if (!(strcmp("all", ((isset($_GET["lang"]))?$_GET["lang"]:"")))) {echo "selected=\"selected\"";} ?>>বাংলা/العربية</option>
</select>
</div>
<div class="col-auto my-1">
<div class="custom-control custom-checkbox mr-sm-2">
<input type="checkbox" class="custom-control-input" id="customControlAutosizing" name="exact" value="1" <?php if (!(strcmp(((isset($_GET["exact"]))?$_GET["exact"]:""),1))) {echo "checked=\"checked\"";} ?>>

<label class="custom-control-label" for="customControlAutosizing">হুবহু শব্দে</label>
</div>
</div>

<div class="col-auto my-1">

<script language="JavaScript">
function toggle(source) {
checkboxes = document.getElementsByName('book[]');
for(var i=0, n=checkboxes.length;i<n;i++) {
checkboxes[i].checked = source.checked;
}
}
</script>
<div class="form-check pl-3">
<input type="checkbox" onClick="toggle(this)" /><span class="text-danger"> সব বই সিলেক্ট করুন</span>
</div>
<div class="form-check">
<?php
$wa_startindex = 0;
while(!$booksList->atEnd()) {
$wa_startindex = $booksList->Index;
?>
<label class="form-check-label pl-3">
<input name="book[]" type="checkbox" class="form-check-input" value="<?php echo($booksList->getColumnVal("BookID")); ?>"><?php echo($booksList->getColumnVal("BookNameBD")); ?>
</label>


<?php
$booksList->moveNext();
}
$booksList->moveFirst(); //return RS to first record
unset($wa_startindex);
unset($wa_repeatcount);
?>
</div>
</div>


<div class="col mb-2 my-1">
<button type="submit" name="WADbSearch1" class="btn btn-dark btn-block"><i class="fas fa-search"></i> খুঁজুন</button>
</div>

</div>
</form>

Sign in to reply to this post

Ray BorduinWebAssist

I think this would work then:

php:
<input name="book[]" type="checkbox" class="form-check-input" <?php echo(in_array($booksList->getColumnVal("BookID"),isset($_GET["book"])?$_GET["book"]:array())?"checked":""); ?> value="<?php echo($booksList->getColumnVal("BookID")); ?>"><?php echo($booksList->getColumnVal("BookNameBD")); ?>
Sign in to reply to this post
Did this help? Tips are appreciated...

Rokon

Thanks Ray, It works as expected.

Sign in to reply to this post

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...