[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=$HT TP_POST_VARS['searchtype'];
$searchterm=$HT TP_POST_VARS['searchterm'];
$searchterm=tri m($searchterm);
if (!$searchtype || !$searchterm)
{
echo 'You haven\'t entered search details. Please try again';
exit;
}
$searchtype = addslashes($sea rchtype);
$searchterm = addslashes($sea rchterm);
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 ".$searchty pe." LIKE '%".$searchterm ."%'" ;
$result = mysql_query($qu ery);
$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_arr ay($result);
echo '<p><strong>'.( $i+1).'. No Soalan: ';
echo htmlspecialchar s(stripslashes( $row['id']));
echo'</strong><br />Soalan: ';
echo stripslashes($r ow['soalan']);
echo '<br />Jenis: ';
echo stripslashes($r ow['jenis']);
if ($jenis == "Objektif") {
echo '<br />A: ';
echo stripslashes($r ow['jwpA']);
echo '<br />B: ';
echo stripslashes($r ow['jwpB']);
echo '<br />C: ';
echo stripslashes($r ow['jwpC']);
echo '<br />D: ';
echo stripslashes($r ow['jwpD']);
echo '<br />Jawapan: ';
echo stripslashes($r ow['jwpObj']);
}
else {
echo '<br />Jawapan: ';
echo stripslashes($r ow['jwpSubj']);
}
echo '<br />Aras Kesukaran: ';
echo stripslashes($r ow['araskesukaran']);
echo '<br />Sesi Peperiksaan: ';
echo stripslashes($r ow['sesipeperiksaa n']);
echo '<br />Bahagian: ';
echo stripslashes($r ow['bahagian']);
echo '<br />Add User: ';
echo stripslashes($r ow['adduser']);
echo '</p>';
}
?>
<p align="center"> <font face="BatangChe "><strong> </strong></font></p>
</body>
</html>
[/PHP]
NOTES: My coding 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(soala n) 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.......
1 2028
First of all, dit you test the SQL in a tool like PHPMyAdmin or, when working locale, a stand alone query tool?
Make sure that you get the results from the database as you want them.
Second, do not name a field in a table the same as the table itself, you will run in trouble soner or later.
When looking at the beginning of the code it seems you search for a type and a question together. they must be given both by the user
This means you can adjust your SQL to search for the type and the question
Inyour input form make sure you use a select statement (either radio or dropdown) to make sure you always get either a "objektif" or "subjektif"
Than you do not need a LIKE statement in your SQL, its rather time consuming
Before you submit the query to the database echo it to your screen to see if it is complete. Test this query also in the databse itself to see howmany results you can expect.
Next just print everything. If this is all OK than start working with the IF:s
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: lawrence |
last post by:
Google can't find me a good example of how to use the "if exists"
syntax in MySql. Is it right that to use it this way:
INSERT INTO IF EXISTS tMyTable VALUES("xxlk", "lkjlkjlkjljk")
I want to insert into a table but only if the table exists.
How does one, in general, from PHP, test for the existence of a table,
without getting an error message?
|
by: george young |
last post by:
I had developed the habit of using the neat python form:
if someinstance:
someinstance.memb()
because it seems cleaner than "if someinstance is not None".
{please no flames about "is not None" vs. "!= None" ...}
This seemed like a good idea at the time :(). Twice, recently,
however, as my
app grew, I thought, hmm... it would make things clearer if I gave
|
by: Emmett |
last post by:
The transform below should create a dropdown where the
entry for "SSS Building I" is selected. (Or am I missing something? )
This transform creates the dropdown but doesn't do the select.
Can "if tests" work when there are spaces?
Thanks
<xml_data>
|
by: kmunderwood |
last post by:
I am trying to combine "if match=" and "when test"
I am a newbie, and have made both work separately, but I can not seem
to combine them.
This is my xml("index.xml")page(I can not change this, it comes to me
this way.
<?xml version="1.0" encoding="iso-8859-1" ?>
|
by: qazmlp |
last post by:
There are some blocks of C/C++ code put under
#if 0
#end if
Is there anyway to make the code inside these blocks to get executed
(may be by using some command line options)?
| |
by: eyalhz |
last post by:
I have this code at button click:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If ListBox1.SelectedIndex() Then
Dim lines As String() = File.ReadAllLines(FileName, FileEncoding)
Dim Line As String = lines(Int(Rnd() * (UBound(lines) + 1)))
Dim Pos As Long = Line.IndexOf(" ")
TextBox1.Text = Line.Substring(0, Pos)
TextBox2.Text = Line.Substring(Pos + 1, Line.Length - Pos - 1)...
|
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 be the missing check ot ptr against
NULL.
|
by: MichaelZ |
last post by:
After all is done, I want query(s) which will give me the ability to create a report which will allow me to compare 3 apts with the parameters equaling bedroom size, and rents which are equal or greater to the tenant's current rent and bedroom size.
The first problem: Creating a field which will output a result which is contingent to what was inputed on the Bedroom Size. The apt.bedx is the cost of the rent.
(spelled out for one field)...
|
by: desktop |
last post by:
I have 3 types of objects: bob1, bob2 and bob3. Each object is
identified by a unique ID which gets returned by the function getId().
All bobs are descendants from class BaseBob which is an abstract class
that has the virtual function getId().
I then have a function that prints a special string when a bob meets
another bob (all combinations of bobs has to meet and since the are
schizophrenic they can also meet themselves):
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |