/    Sign up×
Community /Pin to ProfileBookmark

showing all FAQ’s?

Hello guys.
Hope you’re all keeping well.

Query for you…please.

I am using the following FAQ script that I made ages ago with some assistance, which uses a select menu and a redirect.php that transfers the user to the value url and then brings up the matching file.

Our answers are in files, i.e. 1.html in the ‘ans’ directory and they’re displayed.

What I want to do now is have an option of ‘Show all’, which would bring up every .html file and show all the answers.

How easy would that be to achieve?

Hope that makes sense!

THANKS!

code:

[code=php]
<form action=”/redirect.php” method=”post”>
<p><select name=”faqmenu”>
<option value=”” selected=”selected”>Please select a question</option>
<option value=”/faq/services.php?id=1″>1. qu 1</option>
<option value=”/faq/services.php?id=2″>2. qu 2</option>
<option value=”/faq/services.php?id=3″>3. qu 3</option>
<option value=”/faq/services.php?id=4″>4. qu 4</option>
</select> <input type=”submit” name=”submit” value=”Go” /></p>
</form>

<?php

$id = (int)$_GET[‘id’];
if ($id <= 19 && $id >= 1) {

$info = “/home/us/htdocs/faq/ans/$id.html”;

if (file_exists($info)) {
readfile($info);
} else {
echo “<p class=”error”>Sorry, that answer doesn’t exist. Please try again.</p>n”;
}

}
?>
[/code]

to post a comment
PHP

8 Comments(s)

Copy linkTweet thisAlerts:
@DanUKauthorOct 17.2005 — Any ideas on this?
Copy linkTweet thisAlerts:
@pointfiftyaeOct 17.2005 — Maybe put an <option value="/faq/services.php?id=all">All</option> and modify your php code a bit, something like[code=php]if ($_GET['id'] == "all") {
for ($i = 1;$i<=19;$i++) {
$info = "/home/us/htdocs/faq/ans/".$i.".html";
readfile($info); //I was too lazy to copy your complete code here but you might want to check for file existence every time
}
}
//and here the normal procedure where $_GET['id'] isn't "all"[/code]


Is that what you were asking for?
Copy linkTweet thisAlerts:
@DanUKauthorOct 18.2005 — Hiya. That sounds perfect, but I can't get it to work, the script still works, but the view all brings up nothing - no answers show at all.

Code i'm using:

[code=php]
<?php

$id = (int)$_GET['id'];
if ($id <= 17 && $id >= 1) {

$info = "/home/us/faq/ans/$id.html";

if ($_GET['id'] == "all") {
for ($i = 1;$i<=17;$i++) {
$info = "/home/us/faq/ans/".$i.".html";
readfile($info);
}
}

if (file_exists($info)) {
readfile($info);
} else {
echo "<p class="error">Sorry, that answer doesn't exist. Please try again.</p>n";
}

}
?>
[/code]


Any ideas?

Many thanks!
Copy linkTweet thisAlerts:
@chazzyOct 18.2005 — you tried to parse the word "all" as an int, for one. secondly, you tried to check "all" was between 1 and 17, and if it was then if the id = all then print out all.

all is not between 1 and 17, all is not an int.

try this
[code=php]
<?php

$id = $_GET['id'];
if ($_GET['id'] == "all") {
for ($i = 1;$i<=17;$i++) {
$info = "/home/us/htdocs/faq/ans/".$i.".html";
readfile($info); //I was too lazy to copy your complete code here but you might want to check for file existence every time
}
}
elseif ($id <= 17 && $id >= 1) {

$info = "/home/us/faq/ans/$id.html";

if (file_exists($info)) {
readfile($info);
} else {
echo "<p class="error">Sorry, that answer doesn't exist. Please try again.</p>n";
}

}
?>
[/code]
Copy linkTweet thisAlerts:
@DanUKauthorOct 18.2005 — Hi there. Thanks for that.

Unfortunately it still doesn't appear to be working.

View all still doesn't work, nothing shows up at all, but now also the actual questions I.e. 5 now shows the answer does not exist error, even though the answer is in the path.

Any ideas? Weird.
Copy linkTweet thisAlerts:
@DanUKauthorOct 21.2005 — Any new ideas on this please?

Many thanks.
Copy linkTweet thisAlerts:
@pointfiftyaeOct 22.2005 — Replace [code=php]echo "<p class="error">Sorry, that answer doesn't exist. Please try again.</p>n";[/code] by [code=php]echo "<p class="error">Sorry, the file ".$info." doesn't exist. Please try again.</p>n";[/code] to see if $info is the right one. Generally, try to see step by step what is working and what is not.
Copy linkTweet thisAlerts:
@LiLcRaZyFuZzYOct 22.2005 — try this (worked for me)

you might want to double check the url you enter
[code=php]
<?php
$id = $_GET['id'];

if($id == "all"){
for ($i = 1;$i<=17;$i++) {
$info = "faq/$i.html";
if(file_exists($info)){
readfile($info);
}else{
echo "<p class="error">Sorry, the file $info doesn't exist. Please try again.</p>n";
}
}
}elseif($id >=1 && $id <= 17){
$info = "faq/$id.html";

if(file_exists($info)){
readfile($info);
}else{
echo "<p class="error">Sorry, the file $info doesn't exist. Please try again.</p>n";
}
}
?>
[/code]
×

Success!

Help @DanUK spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...