Jump to content

Selecting specific mysql record from listed records


dougj

Recommended Posts

I\'ve got a list of mysql records on a page (www.djenkins.nu/thoughts). I\'ve added images on each row of the form as <input type=\"image\"...>.

 

I\'m not sure how to setup the input tag to be able to identify the mysql record id of the selected row nor how to recognize the record id when the submission is processed. Would I use an array with a value of the record id then when the form is submited, loop thru each array element to check which one was clicked? Thanks, in advance!

 

doug

 

P.S. Sorry if you don\'t agree with the thoughts I\'ve collected. Also, if I get this nailed down, I\'ll see about submitting a user tutorial on this - unless there already is one and I\'m too blind to see it!

Link to comment
Share on other sites

it depends on how your doing it. Post some of your code and I\'m sure someone can point you in the right direction.

 

In general what you want to do is something like this. Say you want to delete a bunch of records. In your loop that displays the records put

<INPUT TYPE=\"checkbox\" NAME=\"id[]\" VALUE=\"<?= $yourid ?>\">

 

then on the next page to loop through you do

[php:1:9313730d1f]

<?

$id = $_POST[\'id\'];

 

for ($i = 0; $i < count($id); $i++)

{

//do stuff with $id[$i] like

$getthoughts = mysql_query(\"SELECT yourfields FROM table WHERE id = \'$id[$i]\'\");

}

?>

[/php:1:9313730d1f]

 

But like I said, without seeing any of your code that\'s just a generalization, you can\'t cut and paste that and expect it to work :)

Link to comment
Share on other sites

This is exactly what I was looking for. It shows how to create an input tag with an image, identify it with a mysql record id and process that record id after the image is selected. Thought I\'d pass it on. It\'s from \"Kaif\" in another forum. Thanks, all.

 

--------------------------------------------

While using the <INPUT TYPE=\"IMAGE\"> with the PHP, keep in mind that Internet Explorer 6 or earlier do not support the VALUE attribute if the INPUT TYPE is IMAGE. But if you are using Netscape or Mozilla then you can use the VALUE attribute.

Hence you can not do this in Interent Explorer:

 

print \"<input type=\"image\" name=\"imageView\" value=\"\". $row[0] . src=\"images/viewClient.gif\">\";

 

If you still want to do this in Intenent Explorer then you have to pass a Value to an Image with Hidden variable like:

 

print \"<input type=\"hidden\" name=\"clientView\" value=\"\". $row[0] . \"\">\";

print \"<input type=\"image\" name=\"imageView\" src=\"images/viewClient.gif\">\";

 

And on the next script you can get the value of these variables by doing something like:

 

$myArray = array();

$myArray = $HTTP_POST_VARS;

print_r($myArray);

for ($i=0; $i< count($myArray); $i++)

{

list($key, $value) = each($HTTP_POST_VARS);

if (substr($key, 0, 5) == \"image\")

{

$image = substr($key, 5, -2);

print \"<BR>image: \" . $image . \"<BR>\";

}

}

 

Hope this helps.

--------------------------------------------------------

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.