Show multiple images but not selectoptions

Hello,

I need help with some code because I cant figure it out on my own:(

This is my Class:

[php]<?php

include_once “connect.class.php”;

class merken extends connect
{

private $merkenlijst;

public function getMerken($database, $id = NULL)
{
    $sql = "SELECT * FROM ".$database."_merken";
    if(!empty($id))
    {
        $sql .= " WHERE merk_code=:id LIMIT 1";
    }
    else
    {
        $sql .= " ORDER BY merk_naam ASC";
    }
    try
    {
        $stmt = $this->db->prepare($sql);
        if(!empty($id)){ $stmt->bindParam(":id", $id, PDO::PARAM_STR); }
        $stmt->execute();
        $this->merkenlijst = $stmt->fetchAll(PDO::FETCH_OBJ);
        $stmt->closeCursor();
        
        return $this->merkenlijst;
    }
    catch (Exception $e)
    {
        die ( $e->getMessage() );
    }
}

public function __construct($dbo = NULL)
{
    parent::__construct($dbo);
}

}

?>[/php]

And this is my code for the output:

[php]<?php
include_once “class/merken.class.php”;
$merkclass = new merken($dbo);
?>










Zoek op merk
Merk:

- Merk - <?php $merken = $merkclass->getMerken($website); foreach($merken as $merk) { echo "\t\t\t\t\t\t\t\t\t\t\tmerk_code."\""; if(isset($_GET['search']) && $_GET['search'] == "wiel" && isset($_GET['merk']) && $_GET['merk'] == $merk->merk_code || isset($_POST['wiel_submit']) && $_POST['wiel_merk'] == $merk->merk_code) { echo " selected=\"selected\""; } echo ">".$merk->merk_naam."\n"; } ?>
                                    </select>
                                </td>
                            </tr>
                            <tr>
                                <td>&nbsp;</td>
                                <td><input type="submit" name="wiel_submit" value="Zoek" /></td>
                            </tr>
                            <tr>
                                <td colspan="2">&nbsp;</td>
                            </tr>
                            <tr>
                                <td colspan="2">&nbsp;</td>
                            </tr>
                        </table>
                    </form>
                </div>
                <div class="clearboth"></div>
                <br />
<?php if(isset($_POST['wiel_submit']) && $_POST['wiel_submit'] == "Zoek" || isset($_GET['merk'])) { $merk = NULL; if(isset($_POST['wiel_submit']) && $_POST['wiel_submit'] == "Zoek") { $merk = $_POST['wiel_merk']; } $merken = $merkclass->getMerken($website, $merk); ?>
                <img src="http://www.etyre.net/preview/bnet/logos/<?php echo str_replace(".png", "_150.png", $merken[0]->merk_logo); ?>" width="150" class="logo" alt="<?php echo $merken[0]->merk_naam; ?>"/>
                <div id="merken">
                <li><span class="title">Foto <?php echo $merken[0]->wiel_foto; ?></span>
                        <a href="http://www.inter-tyre.nl/inter-tyre/images/w3/<?php echo $merken[0]->wiel_foto; ?>" class="preview" title="Fotonummer: <?php echo $merken[0]->wiel_foto;  ?>">
                            <img src="http://www.inter-tyre.nl/inter-tyre/images/w2/<?php echo $merken[0]->wiel_foto; ?>" alt="Fotonummer: <?php echo $merken[0]->wiel_foto; ?>" class="wheelImg"/>
                        </a>
                    <div class="clearboth"></div>
                </div>
<?php } ?> [/php]

What I try to accomplish is the following:

I got a option selectfield and you can select different brands. After you submit you get the name and logo of the brand and the wheel that has that brand.

Now I only have 11 different brands with a wheel but I got more wheels with the same brand and I want to show all the wheels that belong to the brand you selected.

Here is how my database looks like:

So lets say I put in another Rosso with a different picture. When I select Rosso and click submit I get 2 wheels of Rosso. The only thing that is happening now is that in my selectbox I can choose Rosse 2 times! And when I add another Rosso wheel I can choose 3 times. Same is with merk_logo that is there 3 times…

Can somebody help me with the code I got this far and help me getting this thing to work like a charm? :slight_smile:

I know I am very close but just need to fix this…

Thanks

Well, I am not quite sure what you need help with. You said:

Now I only have 11 different brands with a wheel but I got more wheels with the same brand and I want to show all the wheels that belong to the brand you selected.

So, this tells me that you might just be using an incorrect query.
Normally to execute a query to pull only certain data, you just ad a “WHERE” clause to it.
You would have the user select the brand and then do another query pulling just the rows of data that
are set on that brand. Something like “SELECT * FROM wheels WHERE brand=$_POST[‘brand’]”
Just a sample, not your real code to use!

Is that what you are asking for? Good luck!

Hello,

I want to pull out the wheels that belong to the same brand… He is doing that now but also the brand names in the select option box… So how can I manage that? Can you help me out?

Well, as I said before, it is all done in your query. If you have three select drop-downs, you just use the values of two or three, whatever you need. So, basically, once the user selects the 2 or 3 drop-downs and presses the submit button, your PHP code would run a new query using these values. In general terms something like this:

$sql = “SELECT * FROM wheels_table WHERE option_name_1 = $_POST[‘drop_down_1’] and option_name_2 = $_POST[‘drop_down_2’] and option_name_3 = $_POST[‘drop_down_2’]”;

Basically, you can pull your values out of the select’s using the posted values. (I used names for the select as drop_down_1, for example) This can be compared to the data in the table that corresponds to each. (I used names for the table columns as option_name_1, for example) Then results pulled from the database table after the query will contain all wheels where the three options fit.

When you need to pull more values of several select drop-down’s, you usually just post it to a second file and that file pulls what you need and displays it. Some programmers post the page back to itself for this display. You showed us two short segments of your code. Not enough to tell how you are calling this section. But, the general way above should give you an idea how it works.

Is that what you are asking? If not, can you post a link to the live page so we can see what it looks like?

We can help you. Let us know if you can’t figure it out…

Hello,

I cant give you guys a link for a live version… But I’m going to explain my problem again.

I only got one selectbox with 11 diffrent options you can choos from. After selecting a option and after the submit you get a picture of that brand and a picture of the wheel that belongs to that brand.

Now when I add another wheel with the same brand and I press submit after selected that specific brand I got 2 wheels… But I also got the brandlogo 2 times and that is not what I want… The other problem is that in my selectbox I got two options of the same brand!

I know the Distinct funtion to solve this problem but when I use it, it goes very wrong… Can you help me out with that?

Try taking the line where you call the logo out of the loop where you call the other images. By looking at your code it looks like you do both one right after the other in the same loop so every time you get a picture of a wheel you get the logo just before it. it should be something closer to

get logo

then loop through all the wheels in that logo.

Hi,

Thanks for your reply! I will try that… But the main problem is that I get double merk_naam in my selectbox…

When I use this Class:
[php]public function getMerken($database, $id = NULL)
{
$sql = “SELECT merk_code, merk_naam, merk_logo, wiel_foto, wiel_nummer, wiel_info FROM “.$database.”_merken GROUP BY merk_code, merk_naam, merk_logo”;
if(!empty($id))
{
$sql .= " WHERE merk_code=:id";
}
else
{
$sql .= " ORDER BY merk_naam ASC";
}
try
{
$stmt = $this->db->prepare($sql);
if(!empty($id)){ $stmt->bindParam(":id", $id, PDO::PARAM_STR); }
$stmt->execute();
$this->merkenlijst = $stmt->fetchAll(PDO::FETCH_OBJ);
$stmt->closeCursor();

		return $this->merkenlijst;
	}
	catch (Exception $e)
	{
		die ( $e->getMessage() );
	}
}[/php]

I get the following error:

Fatal error: Call to a member function bindParam() on a non-object in /class/merken.class.php on line 34

This is the code I’m reading the Class with:

[php]

<?php include_once "class/merken.class.php"; $merkclass = new merken($dbo); ?>
				<br />
				<div class="bandwielkolom">
					<form action="index.php?lang=nl&amp;p=<?php echo $_GET['p']; ?>#keuze" method="post">
						<table class="bandentabel">
							<tr>
								<th colspan="2">Zoek op merk<a name="wiel"></a></th>
							</tr>
							<tr>
								<td>Merk:</td>
								<td>
									<select name="wiel_merk">
										<option value="0">- Merk -</option>
<?php $merken = $merkclass->getMerken($website, $merk_code); foreach($merken as $merk) { echo "\t\t\t\t\t\t\t\t\t\t\tmerk_code."\""; if(isset($_GET['search']) && $_GET['search'] == "wiel" && isset($_GET['merk']) && $_GET['merk'] == $merk->merk_code || isset($_POST['wiel_submit']) && $_POST['wiel_merk'] == $merk->merk_code) { echo " selected=\"selected\""; } echo ">".$merk->merk_naam."\n"; } ?>
									</select>
								</td>
							</tr>
							<tr>
								<td>&nbsp;</td>
								<td><input type="submit" name="wiel_submit" value="Zoek" /></td>
							</tr>
							<tr>
								<td colspan="2">&nbsp;</td>
							</tr>
							<tr>
								<td colspan="2">&nbsp;</td>
							</tr>
						</table>
					</form>
				</div>
				<div class="clearboth"></div>
				<br />
<?php if(isset($_POST['wiel_submit']) && $_POST['wiel_submit'] == "Zoek" || isset($_GET['merk'])) { $merk = NULL; if(isset($_POST['wiel_submit']) && $_POST['wiel_submit'] == "Zoek") { $merk = $_POST['wiel_merk']; } $merken = $merkclass->getMerken($website, $merk); foreach($merken as $merk) { ?>
				<img src="http://www.etyre.net/preview/bnet/logos/<?php echo str_replace(".png", "_150.png", $merk->merk_logo); ?>" width="150" class="logo" alt="<?php echo $merk->merk_naam; ?>"/>
				<div id="merken">
                <li><span class="title"><?php echo $merk->wiel_info; ?></span>
						<a href="http://www.inter-tyre.nl/inter-tyre/images/w3/<?php echo $merk->wiel_foto; ?>" class="preview" title="Fotonummer: <?php echo $merk->wiel_foto;  ?>">
							<img src="http://www.inter-tyre.nl/inter-tyre/images/w2/<?php echo $merk->wiel_foto; ?>" alt="Fotonummer: <?php echo $merk->wiel_foto; ?>" class="wheelImg"/>
						</a>
					<div class="clearboth"></div>
				</div>
<?php } ?> <?php } ?>[/php]

Do you know what I’m doing wrong?

Sponsor our Newsletter | Privacy Policy | Terms of Service