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
joepiooo1988
Forum Newbie
Posts: 11 Joined: Tue May 29, 2012 8:36 am
Post
by joepiooo1988 » Mon Jul 09, 2012 4:07 am
Hallo,
I'm making a dropdown menu with information out of my database. It has to get different brands in my dropdown and when selecting a brand and submit search it will show information about that brand. It gets the brands correct from bij database but after submit nothing happens. Can somebody help me out... Here is my dropdown menu and search (submit) code:
Code: Select all
<div class="bandwielkolom">
<form action="index.php?lang=nl&p=<?php echo $_GET['p']; ?>#keuze" method="post">
<table class="bandentabel">
<tr>
<th colspan="2">Op merk zoeken<a name="band"></a></th>
</tr>
<tr>
<td>Merk:</td>
<td>
<select name="band_merk">
<option value="0">- Merk -</option>
<?php
$wielen = $wielclass->getMerkenWielen($website);
foreach($wielen as $wiel)
{
echo "\t\t\t\t\t\t\t\t\t\t\t<option value=\"".$wiel->merk_code."\"";
if(isset($_GET['search']) && $_GET['search'] == "band" && isset($_GET['wiel']) && $_GET['wiel'] == $wiel->merk_code || isset($_POST['band_submit']) && $_POST['band_merk'] == $wiel->merk_code) { echo " selected=\"selected\""; }
echo ">".$wiel->merk_naam."</option>\n";
}
?>
</select>
</td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="band_submit" value="Zoek"/></td>
</tr>
</table>
</form>
</div>
This is my class:
Class:
Code: Select all
<?php
class wielen extends connect
{
private $wielenlijst;
public function getMerkenWielen($database)
{
$sql = "SELECT * FROM ".$database."_wielen ORDER BY merk_nummer";
try
{
$stmt = $this->db->prepare($sql);
$stmt->execute();
$this->wielenlijst = $stmt->fetchAll(PDO::FETCH_OBJ);
$stmt->closeCursor();
return $this->wielenlijst;
}
catch (Exception $e)
{
die ($e->getMessage());
}
}
public function __construct($dbo)
{
parent::__construct($dbo);
}
}
?>
Maybe a fresh look at it will help
thnx for any help
social_experiment
DevNet Master
Posts: 2793 Joined: Sun Feb 15, 2009 11:08 am
Location: .za
Post
by social_experiment » Mon Jul 09, 2012 11:35 am
Code: Select all
<?php
isset($_POST['band_submit']) && $_POST['band_merk'] == $wiel->merk_code)
?>
One of the conditions in the above statement is most likely not being met;
When you load the page; is the dropdown menu displayed with the options from the database?
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Joepiooo
Forum Newbie
Posts: 4 Joined: Thu Apr 08, 2010 2:00 am
Post
by Joepiooo » Mon Jul 09, 2012 3:23 pm
Hi,
Thanks for your answer! Yes it loads my database info! But I'm not realy à pro at php so I dont know how I can realise what I want now... Can't figure It out... Can you help me out?
social_experiment
DevNet Master
Posts: 2793 Joined: Sun Feb 15, 2009 11:08 am
Location: .za
Post
by social_experiment » Tue Jul 10, 2012 1:36 am
What does happen when you submit the page and do you call this page on itself, meaning is the form on index.php and it goes to index.php when you click submit
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
joepiooo1988
Forum Newbie
Posts: 11 Joined: Tue May 29, 2012 8:36 am
Post
by joepiooo1988 » Tue Jul 10, 2012 1:42 am
Yes it is on index.php?lang=nl&p=8 ect ect
I got this peace of code now and I will explain what is happening and what I want:
Code: Select all
<div class="bandwielkolom">
<form action="index.php?lang=nl&p=<?php echo $_GET['p']; ?>#keuze" method="post">
<table class="bandentabel">
<tr>
<th colspan="2">Op merk zoeken<a name="band"></a></th>
</tr>
<tr>
<td>Merk:</td>
<td>
<select name="band_merk">
<option value="0">- Merk -</option>
<?php
$wielen = $wielclass->getMerkenWielen($website);
$get_wiel = isset($_GET['wiel']) ? $_GET['wiel'] : '';
$post_wiel = isset($_POST['band_merk']) ? $_POST['band_merk'] : '';
foreach($wielen as $wiel) {
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$selected = $post_wiel['wiel'] === $wiel->merk_code ? ' selected="selected"' : '' ;
}
else {
$selected = $get_wiel['wiel'] === $wiel->merk_code ? ' selected="selected"' : '' ;
}
echo '\t\t\t\t\t\t\t\t\t\t\t<option value="' . $wiel->merk_code . '"' . $selected . '>' . $wiel->merk_naam . '</option>';
}
?>
</select>
</td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="band_submit" value="Zoek"/></td>
</tr>
</table>
</form>
</div>
<?php
if(isset($_POST['band_submit']) && $_POST['band_merk'] == $wiel->merk_code)
echo $wiel->merk_naam;
?>
Precess code:
Code: Select all
if(isset($_POST['band_submit']) && $_POST['band_merk'] == $wiel->merk_code)
echo $wiel->merk_naam;
I get a selectbox with four options out of my database so that is working correct. These options has data in it like a picture and text. When I select one and press submit he has to show the information of the selected option and that should stay selected.
What is happening now is that when I select a option and press submit nothing happens... The button is working but I dont get any output of the selected option and it wont stay selected.
Doing something wrong but I cant figure out what
social_experiment
DevNet Master
Posts: 2793 Joined: Sun Feb 15, 2009 11:08 am
Location: .za
Post
by social_experiment » Tue Jul 10, 2012 4:14 am
what is printed to the browser if you dump the contents of $wielen?
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
joepiooo1988
Forum Newbie
Posts: 11 Joined: Tue May 29, 2012 8:36 am
Post
by joepiooo1988 » Tue Jul 10, 2012 4:58 am
array(4) { [0]=> object(stdClass)#11 (5) { ["merk_code"]=> string(2) "RO" ["merk_naam"]=> string(5) "Rosso" ["merk_nummer"]=> string(1) "1" ["wiel_foto"]=> string(7) "001.png" ["wiel_info"]=> string(8) "16"- 18"" } [1]=> object(stdClass)#12 (5) { ["merk_code"]=> string(2) "FO" ["merk_naam"]=> string(10) "FOX-Wheels" ["merk_nummer"]=> string(2) "12" ["wiel_foto"]=> string(7) "012.png" ["wiel_info"]=> string(9) "14" - 19"" } [2]=> object(stdClass)#13 (5) { ["merk_code"]=> string(2) "AN" ["merk_naam"]=> string(5) "ANZIO" ["merk_nummer"]=> string(2) "22" ["wiel_foto"]=> string(7) "022.png" ["wiel_info"]=> string(9) "14" - 17"" } [3]=> object(stdClass)#14 (5) { ["merk_code"]=> string(2) "LE" ["merk_naam"]=> string(6) "League" ["merk_nummer"]=> string(2) "43" ["wiel_foto"]=> string(7) "043.png" ["wiel_info"]=> string(9) "15" - 19"" } }
that is what he printed
joepiooo1988
Forum Newbie
Posts: 11 Joined: Tue May 29, 2012 8:36 am
Post
by joepiooo1988 » Tue Jul 10, 2012 8:13 am
Code: Select all
if ( $_SERVER['REQUEST_METHOD'] === 'POST' )
{
$selected = $post_wiel == $wiel->merk_code ? ' selected="selected"' : '' ;
}
else
{
$selected = $get_wiel == $wiel->merk_code ? ' selected="selected"' : '' ;
}
This was the solution of my select problem... Now I only have to fix to get some output from my databse...