1 line of code

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
emelianenko
Forum Commoner
Posts: 35
Joined: Thu Sep 09, 2010 11:49 am

1 line of code

Post by emelianenko »

Hello


I am displaying pictures on a table which are loaded dynamically, ok. Now I just want to make those pictures clickable so that i pass a parameter to a Function .

It is not like passing a url parameter through something like asasf.php?id =

because it has to activate a function, so in the case of a picture, it would be onclick="showUser(parameter ...

So, actually I think what I described above, could be done in 1 step. That is, dynamically populating the table with the pictures BUT those pictures would already be active, (clickable) ...

Since it is a picture, well its line refers rather to the name of the picture such as maria.jpg that would do, (although the picture id would also do but that would mean adding yet another parameter in that line).

After that I should be ok, but I cant get the syntax for that.

Here it is:

Code: Select all


echo "<td>" . "<img name ="($row['name'])" . onclick="showUser(this.name)" . src='".htmlspecialchars($row['picname'])."' width=50 height=50 href >". "</td>";

as you see, the src would show the pic and the row[name.. would be the parameter to pass, but I am going nuts with single and double quotes. It is either parsing errors or no clickable pic.

If anybody knows how to solve that, that would be phaenomenal.

thanks a lot. I ll stay tuned like a spinster on the phone.

Emi

====================================================================================================================================
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: 1 line of code

Post by McInfo »

Code: Select all

echo '<td><img id="'.$row['name'].'" onclick="showUser(this.id);" src="'.htmlspecialchars($row['picname']).'" width="50" height="50" alt="'.$row['name'].'" /></td>';
PHP Manual: Strings
emelianenko
Forum Commoner
Posts: 35
Joined: Thu Sep 09, 2010 11:49 am

Re: 1 line of code

Post by emelianenko »

thank you truly whole heartedly!

Believe it or not, I have been nonstop since around 12 midnoon today trying to write it, when I finally decided that I was not coming on. You have helped me so much! It works wonderfully. Now nearly 21 hours I can take a walk with the task solved by you.

The string pasted perfect without errors and I passed that parameter to an ajax call which forwarded it to a brief php script that builds the tables delivering the results that correspond to that. You understood everything very quickly.

thank you very much again!

AE

=============================================================================================================================


McInfo wrote:

Code: Select all

echo '<td><img id="'.$row['name'].'" onclick="showUser(this.id);" src="'.htmlspecialchars($row['picname']).'" width="50" height="50" alt="'.$row['name'].'" /></td>';
PHP Manual: Strings
thinsoldier
Forum Contributor
Posts: 367
Joined: Fri Jul 20, 2007 11:29 am
Contact:

Re: 1 line of code

Post by thinsoldier »

Code: Select all

$tablerowformat = '<td><img name="%s" onclick="showuser(this.name)" src="%s" class="a5050img"></td>';
echo sprintf($tablerowformat, $row['name'], htmlspecialchars($row['picname']) );
You could replace w/h 50 with a css class or even omit the css class and just have a css rule that targets all images in that particular table if you gave the table an ID
Warning: I have no idea what I'm talking about.
emelianenko
Forum Commoner
Posts: 35
Joined: Thu Sep 09, 2010 11:49 am

Re: 1 line of code

Post by emelianenko »

thank you also, I will study that since it is something unknown to me but sounds very practical.

best regards

==============================================================================================================================

thinsoldier wrote:

Code: Select all

$tablerowformat = '<td><img name="%s" onclick="showuser(this.name)" src="%s" class="a5050img"></td>';
echo sprintf($tablerowformat, $row['name'], htmlspecialchars($row['picname']) );
You could replace w/h 50 with a css class or even omit the css class and just have a css rule that targets all images in that particular table if you gave the table an ID
Post Reply