View Full Version : use the button name in an SQL query

12-06-2010, 04:24 PM
if somone can help me,

i have a problem with my PHP and SQL code,

in fact i have a "while" function that create many button pictures in an HTML page,

each picture has the format:

<img src="./images/bat.png" border="0" alt="<?php echo $row[$i]["CSTip"]; ?>" name[/COLOR]="<?php echo $row[$i]["CSTip"]; ?>" width="80" height="90"></img>

the idea is when i click on a picture, i should generate an SQL query:

$query = "SELECT volt FROM table where picture_name='%NAME%'";

the NAME value shoold be the name in the picture definition to differentiate between them. i dont know the correct syntax

So how can i reslove this problem??

12-06-2010, 05:47 PM
Are you submitting a form when an image is clicked? Or are you initiating a POST request via AJAX?

Either way, DOM element information (other than values in form elements) don't get sent to the server, unless you specifically send it. You'll need to use a bit of Javascript to grab the value of your "name" attribute and send it down the pipe when you kick back to the server (however it is you do that).

12-07-2010, 04:15 PM
yes, i submit a form, so when i click on the image, i will redirect to a tread that filter all my informations in the database according to the name of the image where i click,

for example; in the while function, the query fetch all the database and select distinct the ip addresses, then it creats images for each ip address founded and diferenciates these images by their name which is the ip address... so when i click on an image, i should in an sql query do a sum to all the numbers that have an ip address the name of the button....

12-07-2010, 04:33 PM
in an other way:

the definition of the image button:

<a onClick="window.open('real_time_graph-v1.php','Quality_Graph','width=1000,height=500,resizable=yes,scrollbars=yes')" target="_blank">
<img src="./images/bat.png" border="0" alt="<?php echo $row[$i]["CSTip"];?>" name="<?php echo $row[$i]["CSTip"];?>" width="80" height="90"></img>

the Sql query:
$voltage_query = "SELECT volt FROM volt_table where date='%CSXdate%' and ipaddress= '%the name value in the image definition%'";

12-07-2010, 05:49 PM
Send real_time_graph-v1.php the information via the query string. Use Javascript to pull the information out of the name attribute.