Page 1 of 1

Image Problems!

Posted: Tue Jul 27, 2004 2:46 pm
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)

Re: Image Problems!

Posted: Tue Jul 27, 2004 2:53 pm
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>";
}

Posted: Tue Jul 27, 2004 2:55 pm
by Joe
Hey, the query is as simple as:

Code: Select all

$query = "SELECT * FROM images";

Posted: Tue Jul 27, 2004 2:57 pm
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.

Posted: Tue Jul 27, 2004 3:01 pm
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 :))

Posted: Tue Jul 27, 2004 3:03 pm
by feyd
feels a bit like lingo ;)

Posted: Tue Jul 27, 2004 8:18 pm
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 =[

Posted: Thu Jul 29, 2004 9:44 am
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: