Page 1 of 1

1 line of code

Posted: Thu Sep 09, 2010 12:01 pm
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

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

Re: 1 line of code

Posted: Thu Sep 09, 2010 1:21 pm
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

Re: 1 line of code

Posted: Thu Sep 09, 2010 1:49 pm
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

Re: 1 line of code

Posted: Thu Sep 09, 2010 2:43 pm
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

Re: 1 line of code

Posted: Thu Sep 09, 2010 5:29 pm
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