ARRAY and SEARCH Button

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

bluekhille
Forum Commoner
Posts: 25
Joined: Thu Jul 16, 2009 6:49 am

ARRAY and SEARCH Button

Post 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">
&nbsp;
<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."&nbsp;".$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>
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: ARRAY and SEARCH Button

Post by jaoudestudios »

its not for a school project by any chance?
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: ARRAY and SEARCH Button

Post by jackpf »

Oh, this is the thread you messaged me about.

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

Post by bluekhille »

jaoudestudios wrote:its not for a school project by any chance?
just an activity
bluekhille
Forum Commoner
Posts: 25
Joined: Thu Jul 16, 2009 6:49 am

Re: ARRAY and SEARCH Button

Post by bluekhille »

jackpf wrote:Oh, this is the thread you messaged me about.

So what, you're trying to search the array?




yeah! :D


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

Post by bluekhille »

Image

Image

Image
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: ARRAY and SEARCH Button

Post 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.
bluekhille
Forum Commoner
Posts: 25
Joined: Thu Jul 16, 2009 6:49 am

Re: ARRAY and SEARCH Button

Post 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 :)
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: ARRAY and SEARCH Button

Post 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?
bluekhille
Forum Commoner
Posts: 25
Joined: Thu Jul 16, 2009 6:49 am

Re: ARRAY and SEARCH Button

Post by bluekhille »

it doesn't display the records...
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: ARRAY and SEARCH Button

Post by jackpf »

What's your code?
bluekhille
Forum Commoner
Posts: 25
Joined: Thu Jul 16, 2009 6:49 am

Re: ARRAY and SEARCH Button

Post by bluekhille »

<html>
<body>
<form method = "POST" action = "array.php">
<br>
<br>
<center>
<input type = "radio" name = "y">
ID &nbsp; &nbsp; &nbsp;
<input type = "radio" name = "y">
Course<br>
<input type = "text" name = "a">
&nbsp;
<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>
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: ARRAY and SEARCH Button

Post by jackpf »

Yeah, turn on error reporting.

Your syntax is completely incorrect.
bluekhille
Forum Commoner
Posts: 25
Joined: Thu Jul 16, 2009 6:49 am

Re: ARRAY and SEARCH Button

Post by bluekhille »

yah rili can't find the right solution argh :banghead:
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: ARRAY and SEARCH Button

Post 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 &nbsp; &nbsp; &nbsp;
<input type = "radio" name = "y">
Course<br>
<input type = "text" name = "a">
&nbsp;
<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.
Post Reply