Image Problems!

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

Post Reply
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Image Problems!

Post by Joe »

I am making a script within the administration panel of my site which allows me to select which picture I want to display on the front page. The script go's like:

Code: Select all

while (true)
{
 $row = mysql_fetch_assoc($result);
 if ($row == false) break;

 $title = $row['title'];

 if (strlen($title) > '230') { $title = substr($title, 0, 230)."..."; }
 
 echo "<tr>";
 echo "<td><img src='".$sitename."images/".$row['image']."' title='".$row['title']."' width='120' height='120' align='left'>";
 echo "<font face='verdana' size='1'><b>".$row['name']."</b><br><br>";
 echo $title."</font><br><br>";

 echo "<b>Photograph Selection: </b><select>";
 echo "<option value='".$row['name']."'>".$row['name'];
 echo "</select>";

 echo "</td></tr>";
}
Now the problem is with the <select> tag. I want it to show all of the image names in the list but instead it only displays one which is the actual image name itself.

Hard to explain this but nevertheless, any help appreciated.


Joe 8)
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Image Problems!

Post by pickle »

What query is used to generate $result? Does it ask for all images or just the visible one?

I've fixed up your code a bit, eliminated a superflous if and shortened your $title truncation condition.

Code: Select all

while ($row = mysql_fetch_assoc($result))
{

 $title = $row['title'];

$title = (strlen($title) > 230)) ? substr($title,0,230) : $title;
 
 echo "<tr>";
 echo "<td><img src='".$sitename."images/".$row['image']."' title='".$row['title']."' width='120' height='120' align='left'>";
 echo "<font face='verdana' size='1'><b>".$row['name']."</b><br><br>";
 echo $title."</font><br><br>";

 echo "<b>Photograph Selection: </b><select>";
 echo "<option value='".$row['name']."'>".$row['name'];
 echo "</select>";

 echo "</td></tr>";
}
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Post by Joe »

Hey, the query is as simple as:

Code: Select all

$query = "SELECT * FROM images";
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

the code you have right now will show a new table row for each record found, with only 1 option in the select. You may need/want to pull some of that table row code out of the loop. Also, you may want to close the option container.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

kind of like this:

Code: Select all

make result set
start the select tag
while(the next row can be retrieved)
&#123;
    make a new option in the select
&#125;
close select tag
(how do you like that new free-form programming language :))
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

feels a bit like lingo ;)
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

pickle fix my code

Code: Select all

generate($money)) &#123;
make tim money here
&#125; else &#123;
make tim more money here
&#125;
not working =[
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

tim wrote:pickle fix my code

Code: Select all

generate($money)) &#123;
make tim money here
&#125; else &#123;

make tim more money here
&#125;
not working =[
You forgot the if clause and function declaration

Code: Select all

function generate($money)
{
   if($_AFTERLIFE['hell'] == "frozen")
  {
      $money->magically_appear();
   }
   else
    {
       $money->magically_appear_anyway();
     }
}
:lol:
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply