473,396 Members | 2,013 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

problem in "if-else" statement

<html>
<head>
<title>Search Questions</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<?php

$query = '';
$jenis = '';


$searchtype=$HTTP_POST_VARS['searchtype'];
$searchterm=$HTTP_POST_VARS['searchterm'];
$searchterm=trim($searchterm);

if (!$searchtype || !$searchterm)
{
echo 'You haven\'t entered search details. Please try again';
exit;
}

$searchtype = addslashes($searchtype);
$searchterm = addslashes($searchterm);

error_reporting(0);
@ $db = mysql_pconnect('localhost', 'root', '');
mysql_select_db('sistem bank soalan');
$jenis = $_GET["jenis"];

if (!$db)
{
echo 'Error: Xle connect pd db..hahaha padan muker!! ;p';
exit;
}

$query = "SELECT * FROM soalan WHERE ".$searchtype." LIKE '%".$searchterm."%'" ;

$result = mysql_query($query);


$num_results = mysql_num_rows($result);

echo '<p>Number of question found: '.$num_results.'</p>';

for ($i=0; $i <$num_results; $i++)
{
$row = mysql_fetch_array($result);
echo '<p><strong>'.($i+1).'. No Soalan: ';
echo htmlspecialchars(stripslashes($row['id']));
echo'</strong><br />Soalan: ';
echo stripslashes($row['soalan']);
echo '<br />Jenis: ';
echo stripslashes($row['jenis']);


if ($jenis == "Objektif") {
echo '<br />A: ';
echo stripslashes($row['jwpA']);
echo '<br />B: ';
echo stripslashes($row['jwpB']);
echo '<br />C: ';
echo stripslashes($row['jwpC']);
echo '<br />D: ';
echo stripslashes($row['jwpD']);
echo '<br />Jawapan: ';
echo stripslashes($row['jwpObj']);
}
else {
echo '<br />Jawapan: ';
echo stripslashes($row['jwpSubj']);
}

echo '<br />Aras Kesukaran: ';
echo stripslashes($row['araskesukaran']);
echo '<br />Sesi Peperiksaan: ';
echo stripslashes($row['sesipeperiksaan']);
echo '<br />Bahagian: ';
echo stripslashes($row['bahagian']);
echo '<br />Add User: ';
echo stripslashes($row['adduser']);
echo '</p>';
}
?>
<p align="center"><font face="BatangChe"><strong> </strong></font></p>
</body>
</html>


NOTES: The above code is for the searching process. In my system there exists two types of question to be searched (means "objektif" and "subjektif" questions). The problem arises when I tried to display the search result. To explain my problem, u may refer the bold-codes. Those code (mainly in bold) do not flows well. Hopefully, anyone can help me to solve this problem.
Sep 13 '06 #1
2 3590
ronverdonk
4,258 Expert 4TB
What do you mean by "do not flows well"?? Does it work or does it not?
And display your code within PHP tags next time, it is almost unreadable this way.

Ronald :cool:
Sep 13 '06 #2
[PHP]
<html>
<head>
<title>Search Questions</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<?php

$query = '';
$jenis = '';


$searchtype=$HTTP_POST_VARS['searchtype'];
$searchterm=$HTTP_POST_VARS['searchterm'];
$searchterm=trim($searchterm);

if (!$searchtype || !$searchterm)
{
echo 'You haven\'t entered search details. Please try again';
exit;
}

$searchtype = addslashes($searchtype);
$searchterm = addslashes($searchterm);

error_reporting(0);
@ $db = mysql_pconnect('localhost', 'root', '');
mysql_select_db('sistem bank soalan');
$jenis = $_GET["jenis"];

if (!$db)
{
echo 'Error: Cannot connect to database!! ;p';
exit;
}

$query = "SELECT * FROM soalan WHERE ".$searchtype." LIKE '%".$searchterm."%'" ;

$result = mysql_query($query);


$num_results = mysql_num_rows($result);

echo '<p>Number of question found: '.$num_results.'</p>';

for ($i=0; $i <$num_results; $i++)
{
$row = mysql_fetch_array($result);
echo '<p><strong>'.($i+1).'. No Soalan: ';
echo htmlspecialchars(stripslashes($row['id']));
echo'</strong><br />Soalan: ';
echo stripslashes($row['soalan']);
echo '<br />Jenis: ';
echo stripslashes($row['jenis']);


if ($jenis == "Objektif") {
echo '<br />A: ';
echo stripslashes($row['jwpA']);
echo '<br />B: ';
echo stripslashes($row['jwpB']);
echo '<br />C: ';
echo stripslashes($row['jwpC']);
echo '<br />D: ';
echo stripslashes($row['jwpD']);
echo '<br />Jawapan: ';
echo stripslashes($row['jwpObj']);
}
else {
echo '<br />Jawapan: ';
echo stripslashes($row['jwpSubj']);
}
echo '<br />Aras Kesukaran: ';
echo stripslashes($row['araskesukaran']);
echo '<br />Sesi Peperiksaan: ';
echo stripslashes($row['sesipeperiksaan']);
echo '<br />Bahagian: ';
echo stripslashes($row['bahagian']);
echo '<br />Add User: ';
echo stripslashes($row['adduser']);
echo '</p>';
}
?>
<p align="center"><font face="BatangChe"><strong> </strong></font></p>
</body>
</html>
[/PHP]

NOTES: Thanks. I mean it cannot funtion well. it doesnt work..urmm.. okay, let me explain bout it first.. there's a table name SOALAN in my system that contain some field such as id, soalan, jwpA, jwpB, jwpC, jwpD, jwpObj, jwpSubj, jenis(which is type), and many more. I've two types(jenis) of questions(soalan) in my system; which is "subjektif" and "objektif".

For type "Objektif", only jwpA, jwpB, jwpC, jwpD and jwpObj that exist the content (its empty for field jwpSubj for this type), meanwhile for type "Subjektif", its only exist the content for jwpSubj and empty for the others field(i mean jwpA, jwpB, jwpC, jwpD, jwpObj).

So, when i want to call the question(soalan) field, i want to make a if-else statement to call the different types of question; which is like in the above coding.. hv i make it clear...? i just don't know why it can't funtion well.. i think its because of the system didn't recognize which type the question would be.. hurm.. anyone.. please help me with this.......
Sep 14 '06 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: LRW | last post by:
I'm not exactly sure how to even ask the question, and I know my terminology is not good as I'm a SQL beginner, but, here goes. I need to find a way to make an if statement within an array...or,...
9
by: Scott Beavers | last post by:
I'm trying to create a form in Excel to sort from the form and take the data to another worksheet. I am very new to this and any help would be appreciated. I have a value in a cell that will...
1
by: M Wells | last post by:
Hi All, Just wondering if anyone can tell me if you can test for multiple conditions as part of an "IF" statement in T-SQL in SQL Server 2000? ie something like: IF @merr = 1 or @merr=2...
6
by: JS | last post by:
In this sample code: if(n==0&&args>1){ for(i=num;args>i+1;i++){ s.length = 0; opt = document.createElement('OPTION'); s.appendChild(opt); opt.value = ""; opt.text = "\74-- Vælg --"; }
145
by: Sidney Cadot | last post by:
Hi all, In a discussion with Tak-Shing Chan the question came up whether the as-if rule can cover I/O functions. Basically, he maintains it can, and I think it doesn't. Consider two...
32
by: Stephen | last post by:
Is there a standard way to remove the warning that a C compiler might produce from the statement: if (a = b) {} I don't want to do: if ((a = b) != 0) {} Because my "a = b" is actually...
3
by: Mark Sullivan | last post by:
When I trace through a csharp program I came to a situation where a certain values has an "undefined value" as shown in the debugger DbgClr. I want to check this but the following statements did...
6
by: Jacob.Bruxer | last post by:
Hi, I'm pretty new to Visual Basic and programming in general. I want to know if it's possible to create an If statement that asks if a value is an integer. If it's an integer it does one thing,...
2
by: marsarden | last post by:
write code like: int main(void) { int a=10; if(a<20) {} } Compiler ok on dev-cpp . don't we have to add a ";" after if
6
by: vl106 | last post by:
A static code analysis tool gave me a warning on if (ptr && ptr->data) { ... } I assumed the tool doesn't get the "short circuit behaviour" in the if statement. But a collegue said it may...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.