Forum Moderators: open

Message Too Old, No Replies

Sending specific Array values to a MySQL statement

         

JohnPorier

1:55 pm on Jul 12, 2007 (gmt 0)

10+ Year Member



I am trying to send specific array values to a MySQL statement with Ajax / PHP.

Let me elaborate on the situation.

I have a table of data that is generated, these are entries on a calender that I want in list format. I have an attendee column in this table of data and I have built functionality that allows people to click "participate" and the user is added via MySQL as a participant to the event. The table instantly is up to date (Ajax).

There is only one problem in this. I don't know how to specify only the event the user clicked on. Right now I just have a MySQL statement that updates all of the events. I just wanted to make sure I could do it. Now that I have, I need to know how to specify the exact event.

It is clear which event the user wants to participate in, I just don't know how to send that specific array value to the external MySQL statement in PHP file.

Note: Echo's need to be there, they just do =).

The data table with the arrays.

while($row = mysql_fetch_array($result))
{

echo "<tr>";
echo "<td>" . $row['name'] . "</td>";
echo "<td>" . $row['description'] . "</td>";
$row['date']=substr($row['date'],4,2) . "/" . substr($row['date'],6,2) . "/" . substr($row['date'],0,4);


echo "<td>" . $row['date'] . "</td>";

$row['time']=substr($row['time'],0,2) . ":" . substr($row['time'],2,2);
echo "<td>" . $row['time'] . "</td>";

echo "<td><a href='#' onclick='ajaxFunction2()'>" . $row['created_by'] . "</a></td>";

echo "<td>" . $row['participants'] . "<img src='new.gif' onmouseover='ajaxFunction2()' onclick='ajaxFunction()' />

</td>";
echo "</tr>";
}
echo "</table>";

This is the SQL that updates the participants column. Notice I just have the static value of "admin". I need this to specify a specific array vallue, whether it be a unique ID or the event name, it doesn't matter, I just need to know how to send the array value to the SQL statement.

"UPDATE entry SET participants='$useraccount' WHERE create_by='admin'"

Thanks in advance, I appreciate any help.

RonPK

11:08 am on Jul 13, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hello John, welcome to WebmasterWorld.

echo "<td><a href='#' onclick='ajaxFunction2()'>" . $row['created_by'] . "</a></td>";

I'd suggest to have the ajaxFunction pass the ID of the event to the server side script.

echo "<td><a href='#' onclick='ajaxFunction2(" . $row['eventID']. ")'>" . $row['created_by'] . "</a></td>";

JavaScript:


function ajaxFunction2(eventID) {
// (myreq is the HTTP-request object)
myreq.open("GET", 'http://' + location.hostname + '/script.php?eventID=' + eventID, true);
myreq.send();
}

The eventID parameter should now be available to your PHP script:

$_GET['eventID']
.

[edited by: RonPK at 11:08 am (utc) on July 13, 2007]

JohnPorier

3:53 pm on Jul 16, 2007 (gmt 0)

10+ Year Member



This worked out great. Thanks RonPK! I must say IE gives me a huge headache. If it didn't have so many bugs I probably could have conquered the world with PHP/MySQL + Ajax by now (drastic overstatement =)).

phranque

7:14 pm on Jul 16, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



welcome to WebmasterWorld, JohnP!

i would also suggest doing your js development on a more js-friendly platform such as firefox and then make it work on ie.