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
Joe
Forum Regular
Posts: 939 Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow
Post
by Joe » Tue Jul 27, 2004 2:46 pm
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
pickle
Briney Mod
Posts: 6445 Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:
Post
by pickle » Tue Jul 27, 2004 2:53 pm
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.
Joe
Forum Regular
Posts: 939 Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow
Post
by Joe » Tue Jul 27, 2004 2:55 pm
Hey, the query is as simple as:
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Tue Jul 27, 2004 2:57 pm
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.
pickle
Briney Mod
Posts: 6445 Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:
Post
by pickle » Tue Jul 27, 2004 3:01 pm
kind of like this:
Code: Select all
make result set
start the select tag
while(the next row can be retrieved)
{
make a new option in the select
}
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.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Tue Jul 27, 2004 3:03 pm
feels a bit like lingo
tim
DevNet Resident
Posts: 1165 Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio
Post
by tim » Tue Jul 27, 2004 8:18 pm
pickle fix my code
Code: Select all
generate($money)) {
make tim money here
} else {
make tim more money here
}
not working =[
pickle
Briney Mod
Posts: 6445 Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:
Post
by pickle » Thu Jul 29, 2004 9:44 am
tim wrote: pickle fix my code
Code: Select all
generate($money)) {
make tim money here
} else {
make tim more money here
}
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();
}
}
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.