Page 1 of 2
ARRAY and SEARCH Button
Posted: Fri Jul 31, 2009 9:01 am
by bluekhille
Can anybody help me to make a program with this output using ARRAY and FOREACH for loop
this is the default output of the program
http://s782.photobucket.com/albums/yy10 ... efault.jpg
this is the output when i click the course option button and search for a course
http://s782.photobucket.com/albums/yy10 ... course.jpg
this is the output when i click the id option button and search for a id
http://s782.photobucket.com/albums/yy10 ... ent=ID.jpg
here's what the that what i have started it is still messy and complicated so hope someone would help me to finish my program tnx!
<html>
<body>
<? PHP
<form method = "POST" action = "array.php">
<br>
<br>
<center>
<input type = "radio" name = "y">
ID
<input type = "radio" name = "y">
Course<br>
<input type = "text" name = "a">
<input type = "submit" value = "Search" name = "action">
</center>
$x = array ("BSIT"=>array("1"=> "Johanna Solis",
"4"=> "Julie Garcia",
"2"=> "Rambo Abad",
"3"=> "Ismael Ibuan",
"8"=> "Remalyn Del Rosario"),
"BSCS"=>array("5"=> "Jordan Rufo",
"6"=> "Frederick Mararac",
"7"=> "Clarissa Soriano"),
"BSN"=>array("9"=> "Eloisa Buenaventura",
"10"=> "Jonathan Diaz")
);
foreach($x=>$key as $value)
echo $key." ".$value."<br>\n";
echo "<table border = 1 align = "center">";
echo "<tr>";
echo "<td> No. </td>";
echo "<td> ID </td>";
echo "<td> Student Name </td>";
echo "<td> Course </td>";
echo "</tr>";
echo "</table>";
</form>
?>
</body>
</html>
Re: ARRAY and SEARCH Button
Posted: Fri Jul 31, 2009 10:05 am
by jaoudestudios
its not for a school project by any chance?
Re: ARRAY and SEARCH Button
Posted: Fri Jul 31, 2009 10:11 am
by jackpf
Oh, this is the thread you messaged me about.
So what, you're trying to search the array?
Re: ARRAY and SEARCH Button
Posted: Fri Jul 31, 2009 10:39 am
by bluekhille
jaoudestudios wrote:its not for a school project by any chance?
just an activity
Re: ARRAY and SEARCH Button
Posted: Fri Jul 31, 2009 10:40 am
by bluekhille
jackpf wrote:Oh, this is the thread you messaged me about.
So what, you're trying to search the array?
yeah!
i need to search the records using array
Re: ARRAY and SEARCH Button
Posted: Fri Jul 31, 2009 10:46 am
by bluekhille
Re: ARRAY and SEARCH Button
Posted: Fri Jul 31, 2009 10:50 am
by jackpf
Right....
Well basically, you'll want to iterate through the array, removing values that don't match.
Something like this:
Code: Select all
foreach($array as $key => $value)
{
if(!stristr($value, $search))
unset($array[$key]);
}
That should leave $array with the matched values.
Re: ARRAY and SEARCH Button
Posted: Fri Jul 31, 2009 12:23 pm
by bluekhille
jackpf wrote:Right....
Well basically, you'll want to iterate through the array, removing values that don't match.
Something like this:
Code: Select all
foreach($array as $key => $value)
{
if(!stristr($value, $search))
unset($array[$key]);
}
That should leave $array with the matched values.
i'll try this and post it here if it works with me thanks got to sleep thanks again

Re: ARRAY and SEARCH Button
Posted: Mon Aug 03, 2009 7:00 am
by jackpf
Don't take this the wrong way, but it'd be a lot more useful if you posted here instead of PMed me. Instead of me having to go and search to find this thread, it'd appear in my "replied threads" list.
I don't mind you PMing me, but it'd just be more useful if you posted here. Also, other people can see your posts here, so you're more likely to get more help. Plus it may help others in the future.
Anyway, how does that not work? What does (or doesn't) happen?
Re: ARRAY and SEARCH Button
Posted: Mon Aug 03, 2009 8:55 am
by bluekhille
it doesn't display the records...
Re: ARRAY and SEARCH Button
Posted: Mon Aug 03, 2009 8:57 am
by jackpf
What's your code?
Re: ARRAY and SEARCH Button
Posted: Tue Aug 04, 2009 3:58 am
by bluekhille
<html>
<body>
<form method = "POST" action = "array.php">
<br>
<br>
<center>
<input type = "radio" name = "y">
ID
<input type = "radio" name = "y">
Course<br>
<input type = "text" name = "a">
<input type = "submit" value = "Search" name = "action">
</center>
<? PHP
$x = array ("BSIT"("008"=> "Johanna Solis" =>,
"001"=> "Julie Garcia",
"004"=> "Rambo Abad",
"003"=> "Ismael Ibuan",
"005"=> "Remalyn Del Rosario"),
"BSCS"("002"=> "Jordan Rufo",
"006"=> "Frederick Mararac",
"007"=> "Clarissa Soriano"),
"BSN"("009"=> "Eloisa Buenaventura",
"000"=> "Jonathan Diaz")
);
foreach($x as $key => $value)
echo $key:" .$value"[$key]";
echo "<table border = 1 align = "center" cellpadding = 20>";
echo "<tr>";
echo "<td> No. </td>";
echo "<td> ID </td>";
echo "<td> Student Name </td>";
echo "<td> Course </td>";
echo "</tr>";
echo "<tr>";
echo "<td>";
echo " ".&values;
echo"</td>";
echo"</tr>";
echo "</table>";
?>
</form>
</body>
</html>
Re: ARRAY and SEARCH Button
Posted: Tue Aug 04, 2009 6:59 am
by jackpf
Yeah, turn on error reporting.
Your syntax is completely incorrect.
Re: ARRAY and SEARCH Button
Posted: Wed Aug 05, 2009 3:27 am
by bluekhille
yah rili can't find the right solution argh

Re: ARRAY and SEARCH Button
Posted: Thu Aug 06, 2009 7:53 am
by jackpf
Well you can't have turned on error reporting then.
Look at the code:
Code: Select all
<html>
<body>
<form method = "POST" action = "array.php">
<br>
<br>
<center>
<input type = "radio" name = "y">
ID
<input type = "radio" name = "y">
Course<br>
<input type = "text" name = "a">
<input type = "submit" value = "Search" name = "action">
</center>
<? PHP
$x = array ("BSIT"("008"=> "Johanna Solis" =>,
"001"=> "Julie Garcia",
"004"=> "Rambo Abad",
"003"=> "Ismael Ibuan",
"005"=> "Remalyn Del Rosario"),
"BSCS"("002"=> "Jordan Rufo",
"006"=> "Frederick Mararac",
"007"=> "Clarissa Soriano"),
"BSN"("009"=> "Eloisa Buenaventura",
"000"=> "Jonathan Diaz")
);
foreach($x as $key => $value)
echo $key:" .$value"[$key]";
echo "<table border = 1 align = "center" cellpadding = 20>";
echo "<tr>";
echo "<td> No. </td>";
echo "<td> ID </td>";
echo "<td> Student Name </td>";
echo "<td> Course </td>";
echo "</tr>";
echo "<tr>";
echo "<td>";
echo " ".&values;
echo"</td>";
echo"</tr>";
echo "</table>";
?>
</form>
</body>
</html>
Line 31.