0

Good day, i'm new here and did'nt really know what to search for. I have a question about getting certain rows out of a db. I cant put it in a while loop, beacause i would output the HTML over and over again.

Anyway i'll show the code and my question.

<?php 

        $q = "SELECT * FROM image, pakket
        WHERE pakket.pakket_id = image.pakket_id 
        AND pakket.pakket_id='$packageid'";

        $image = $row['img'];           

        if ($result = mysql_query($q)){
        <a href="<?php echo $image; ?>"  rel="fancybox-thumb" class="fancybox-thumb"><img width="370" src="<?php echo $image;; ?>" style="border: 1px solid #ccc;" ></a>
        <a href="<?php echo $image; ?>" rel="fancybox-thumb" class="fancybox-thumb"><img width="119" src="<?php echo $image; ?>" style="border: 1px solid #ccc;"></a>
        <a href="img/screens/1/EO_screen3.jpg" rel="fancybox-thumb" class="fancybox-thumb"><img width="119" src="img/screens/1/EO_screen3.jpg" style="border: 1px solid #ccc;"></a>
        <a href="img/screens/1/EO_screen2.jpg" rel="fancybox-thumb" class="fancybox-thumb"><img width="119" src="img/screens/1/EO_screen2.jpg" style="border: 1px solid #ccc;"></a>
        }
        else {
            echo "Afbeeldingen konden niet opgehaald worden.";
        }
        ?>

What i want is to display the right image inside the right piece of HTML. I'm thinking i shoud have a counter which counts the number of rows in the array, but i have no idea how i should handle this.

i apreciate any help.

Rodracover
  • 13
  • 5
  • Welcome to Stack Overflow! [Please, don't use `mysql_*` functions](http://stackoverflow.com/q/12859942/1190388) in new code. They are no longer maintained and are [officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). See the red box? Learn about prepared statements instead, and use [tag:PDO] or [tag:MySQLi]. – hjpotter92 Apr 08 '13 at 10:14
  • 1. Do not use `mysql_*` functions as they are deprecated, use `mysqli_*` or PDO instead (details in manual) 2. use `echo` before ` – Voitcus Apr 08 '13 at 10:14

1 Answers1

0

I agree with chandresh...your code is pretty messed up....try using it this way

$link = mysqli_connect("localhost", "my_user", "my_password", "world");
$q = "SELECT * FROM image, pakket
        WHERE pakket.pakket_id = image.pakket_id 
        AND pakket.pakket_id='$packageid'";

$result = mysqli_query($link, $q);
$rs = mysqli_fetch_array($result)
while($rs)
{

// now print the image code in this using 
//$row['image']

}

you need to put the result set of the select query in an array before you can use it....go through php docs once.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459