MythosRaconteur
Programmer
Hi gang,
I know what I am trying to do is possible, but I am not quite understanding something and thought I'd look for some help.
I am basically building a little success story rotator for a client. I want to use AJAX so it will update the page while the user is browsing it (without having to reload or navigate away for a new story to come up).
So, I have put a DIV in the page with an id of "successStory".
I have the JS code in the HEAD to build the XMLHTTP request object, call the back-end script (PHP on MySQL in this case), and another JS function to handle the result.
I have two problems, one of which may not be appropriate here, but I will ask anyway in case someone can shed some light on it.
1) I am returning from the PHP script a tilde-separated string, and then breaking it apart with SPLIT into an array on the client side. I then construct the inner html of the DIV. All of this works fine, except the IMG. I am basically writing:
innerHTML = "<img src=\"" + resultArray[4] + "\" border=\"0\" />";
The contents of resultArray[4] is the binary data of the image (I am storing the images in the MySQL table, rather than as files in a directory).
I keep getting the little red X icon of an image that cannot be displayed. If my approach is wrong, what is the right way to do this, and if the approach is viable, can anyone show what I am doing wrong?
2) The inappropriate one... I keep getting the same row returned from my query, even though I am closing the connection and reopening it every time. I am also using MYSQL_UNBUFFERED_QUERY instead of MYSQL_QUERY. I am returning one row with the SQL statement:
SELECT * FROM <table> WHERE active=1 ORDER BY RAND() LIMIT 1
Any ideas on this one?
Thanks a million anyone who can help!
Cheers,
Chris
I know what I am trying to do is possible, but I am not quite understanding something and thought I'd look for some help.
I am basically building a little success story rotator for a client. I want to use AJAX so it will update the page while the user is browsing it (without having to reload or navigate away for a new story to come up).
So, I have put a DIV in the page with an id of "successStory".
I have the JS code in the HEAD to build the XMLHTTP request object, call the back-end script (PHP on MySQL in this case), and another JS function to handle the result.
I have two problems, one of which may not be appropriate here, but I will ask anyway in case someone can shed some light on it.
1) I am returning from the PHP script a tilde-separated string, and then breaking it apart with SPLIT into an array on the client side. I then construct the inner html of the DIV. All of this works fine, except the IMG. I am basically writing:
innerHTML = "<img src=\"" + resultArray[4] + "\" border=\"0\" />";
The contents of resultArray[4] is the binary data of the image (I am storing the images in the MySQL table, rather than as files in a directory).
I keep getting the little red X icon of an image that cannot be displayed. If my approach is wrong, what is the right way to do this, and if the approach is viable, can anyone show what I am doing wrong?
2) The inappropriate one... I keep getting the same row returned from my query, even though I am closing the connection and reopening it every time. I am also using MYSQL_UNBUFFERED_QUERY instead of MYSQL_QUERY. I am returning one row with the SQL statement:
SELECT * FROM <table> WHERE active=1 ORDER BY RAND() LIMIT 1
Any ideas on this one?
Thanks a million anyone who can help!
Cheers,
Chris