ARRAY and SEARCH Button
Moderator: General Moderators
-
bluekhille
- Forum Commoner
- Posts: 25
- Joined: Thu Jul 16, 2009 6:49 am
ARRAY and SEARCH Button
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>
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>
- jaoudestudios
- DevNet Resident
- Posts: 1483
- Joined: Wed Jun 18, 2008 8:32 am
- Location: Surrey
Re: ARRAY and SEARCH Button
its not for a school project by any chance?
Re: ARRAY and SEARCH Button
Oh, this is the thread you messaged me about.
So what, you're trying to search the array?
So what, you're trying to search the array?
-
bluekhille
- Forum Commoner
- Posts: 25
- Joined: Thu Jul 16, 2009 6:49 am
Re: ARRAY and SEARCH Button
just an activityjaoudestudios wrote:its not for a school project by any chance?
-
bluekhille
- Forum Commoner
- Posts: 25
- Joined: Thu Jul 16, 2009 6:49 am
Re: ARRAY and SEARCH Button
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
-
bluekhille
- Forum Commoner
- Posts: 25
- Joined: Thu Jul 16, 2009 6:49 am
Re: ARRAY and SEARCH Button
Right....
Well basically, you'll want to iterate through the array, removing values that don't match.
Something like this:
That should leave $array with the matched values.
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]);
}-
bluekhille
- Forum Commoner
- Posts: 25
- Joined: Thu Jul 16, 2009 6:49 am
Re: ARRAY and SEARCH Button
i'll try this and post it here if it works with me thanks got to sleep thanks againjackpf wrote:Right....
Well basically, you'll want to iterate through the array, removing values that don't match.
Something like this:
That should leave $array with the matched values.Code: Select all
foreach($array as $key => $value) { if(!stristr($value, $search)) unset($array[$key]); }
Re: ARRAY and SEARCH Button
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?
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?
-
bluekhille
- Forum Commoner
- Posts: 25
- Joined: Thu Jul 16, 2009 6:49 am
Re: ARRAY and SEARCH Button
it doesn't display the records...
Re: ARRAY and SEARCH Button
What's your code?
-
bluekhille
- Forum Commoner
- Posts: 25
- Joined: Thu Jul 16, 2009 6:49 am
Re: ARRAY and SEARCH Button
<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>
<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
Yeah, turn on error reporting.
Your syntax is completely incorrect.
Your syntax is completely incorrect.
-
bluekhille
- Forum Commoner
- Posts: 25
- Joined: Thu Jul 16, 2009 6:49 am
Re: ARRAY and SEARCH Button
yah rili can't find the right solution argh 
Re: ARRAY and SEARCH Button
Well you can't have turned on error reporting then.
Look at the code:
Line 31.
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>


