• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 186
  • Last Modified:

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'/>";
0
pixelscape
Asked:
pixelscape
  • 3
  • 2
1 Solution
 
Chris StanyonCommented:
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 StanyonCommented:
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
 
pixelscapeAuthor Commented:
perfect, thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now