Get single varible from database

I want to replace walnut_portraitsm.jpg with field image_portraitsm. This variable exists for each instance of a finish. So for example 4 'walnut' finish rows each has this field ... same info inside it... just need one as pic is same for each of same finish. Make sense?

$result = mysql_query("SELECT * FROM product
WHERE finish= '".$_SESSION['finish']."'");


echo "<img class='imagebox-active' src='awards/walnut_portraitsm.jpg' width='190' height='250'/>";
pixelscapeAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Chris StanyonWebDevCommented:
Have a go with this. It assumes your database connection is already up and running
$sql = "SELECT image_portraitsm FROM product WHERE finish={$_SESSION['finish']} GROUP BY finish LIMIT 1;

$result = mysql_query($sql);

if ($result) {
     $row = mysql_fetch_assoc($result)
     echo "<img class='imagebox-active' src='awards/{$row['image_portraitsm']}' width='190' height='250'/>";
}

Open in new window

0
pixelscapeAuthor Commented:
I am pulling this right under my echo "<img class='imagebox-active...


while($row = mysql_fetch_array($result))
  {
 
  echo "<label class='darkertextheading2'><input type='radio' name='size' value='".$row['size']."'>
                            ".$row['productcode']." - <strong>".$row['size']."</strong><br/>
                            <span class='darkertextnote'>".$row['price']."</span>
                            </label>";
                            
   echo "<br/><br/>";                         
                            
                            
  }
0
pixelscapeAuthor Commented:
Can you have two mysql_query calls within one connection? I wrote a new mysql_query just to grab the single image path from image_portraitsm... what am I missing? Thanks!

$pic = mysql_query("SELECT image_portraitsm FROM product WHERE finish= '".$_SESSION['finish']."' LIMIT 1");

if ($pic) {
     $row = mysql_fetch_assoc($pic)
     echo "<img class='imagebox-active' src='awards/{$row['image_portraitsm']}' width='190' height='250'/>";
}
0
Chris StanyonWebDevCommented:
Instead of have two queries, just reset the internal pointer before looping.


//before your echo statement
$row = mysql_fetch_array($result);
echo "<img class='imagebox-active' src='awards/{$row['image_portraitsm']}' width='190' height='250'/>";

//now reset the pointer
mysql_data_seek ($result, 0);

//now loop through it
while($row = mysql_fetch_array($result))
{
//do whatever you need to in the loop
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
pixelscapeAuthor Commented:
perfect, thanks!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.