cauca Posted October 15, 2008 Share Posted October 15, 2008 Hello, Fist i want introduce myself, My name´s Cauca I live in Brasil; I`m a student (Devoloped sistem to Internet). I want help this forum with ask and question ! Thi first I have ask ;-) ! I´m trying loader a image with code bellow: -> I have a image in BLOB format in MySQL; -> I recover this img in a variable with php and show it with echo ! EX: I have a select ... echo $img; If I access this page direct by localhost , the img is showed with no error, But what I want is: thi img be showed by the innerHTML I tray document.getElementById("ret_teste").innerHTML = "<img src='teste.php'>"; and document.getElementById("ret_teste").innerHTML = xmlHttp.responseText off course that I have a Ajax connection with all function ok, I´m having a problem to mount a img in this parameters; Thank´s for help me God Bless us Cauca Quote Link to comment Share on other sites More sharing options...
grim1208 Posted October 15, 2008 Share Posted October 15, 2008 could you post some code please Quote Link to comment Share on other sites More sharing options...
cauca Posted October 15, 2008 Author Share Posted October 15, 2008 Thank´s for read the topic ! //Code php include_once("conectadb.php"); $teste = $_GET['teste']; $query="select * from user where user_name like '%$teste%'"; $select = mysql_query($query); while ($linha = mysql_fetch_array($select)){ $img = $linha['user_img']; echo $img; } ?> //CODE AJAX function teste(){ var inp_val = frm.inp_cont.value var url="teste.php" url=url+"?teste="+inp_val url=url+"&sid="+Math.random() xmlHttp.open("GET",url,true) xmlHttp.onreadystatechange=stateChanged_r xmlHttp.send(null) function stateChanged_r() { document.getElementById('ret_teste').innerHTML = "<div align='center'><img src='./loader.gif'></div>"; if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { document.getElementById("ret_teste").innerHTML = "<img src='teste.php'>"; } } // the html code <form name="frm"> Procurar:<input type="text" name="inp_cont" onkeyup="teste(this)"><br> </form> THANKS GOD BLESS PAULOCAUCA Quote Link to comment Share on other sites More sharing options...
F1Fan Posted October 15, 2008 Share Posted October 15, 2008 First, please wrap your code in the code tags by clicking on the # button. I suggest trying a slightly different approach. You don't even need to use AJAX. Try this: JavaScript: function teste(){ document.getElementById('ret_teste').innerHTML = "<div align='center'><img src='./loader.gif'></div>"; var inp_val = frm.inp_cont.value var url="teste.php" url=url+"?teste="+inp_val url=url+"&sid="+Math.random() document.getElementById("ret_teste").innerHTML = "<img src='"+url+"'>"; } Quote Link to comment Share on other sites More sharing options...
cauca Posted October 15, 2008 Author Share Posted October 15, 2008 sorry for the large code, sorry too because I can´t find a #button ! Thank´s for the help, I try you code and the result is ok ! I take you code and put only this "<img src='"+url+"'>"; the result was the same result. Both return only one image at a time! I have in the DataBase personals name. I call the DB with LIKE %user_name% I want return for example every images that name start with PA. God Bless Paulo Cauca Quote Link to comment Share on other sites More sharing options...
cauca Posted October 15, 2008 Author Share Posted October 15, 2008 I found the # button in the next code I´ll put it Paulo Cauca Quote Link to comment Share on other sites More sharing options...
F1Fan Posted October 15, 2008 Share Posted October 15, 2008 Temm me what the unique column in your table is and I'll show you how. Quote Link to comment Share on other sites More sharing options...
cauca Posted October 15, 2008 Author Share Posted October 15, 2008 The table : user_id int(11) Não auto complet user_name varchar(30) Não user_img longblob Não Is this? God Bless Paulo Cauca Quote Link to comment Share on other sites More sharing options...
F1Fan Posted October 15, 2008 Share Posted October 15, 2008 Try this: teste.php: <?php include_once("conectadb.php"); if ($_GET['action']=="img"){ $query = "SELECT user_img WHERE user_id = '{$_GET['user_id']}'"; $result = mysql_query($query); $row = mysql_fetch_assoc($result); echo $row['user_img']; } else{ $teste = $_GET['teste']; $query="select user_id from user where user_name like '%$teste%'"; $select = mysql_query($query); while ($linha = mysql_fetch_assoc($select)){ $user = $linha['user_id']; echo "<image src='teste.php?action=img&user_id=$user'>"; } } ?> JS/AJAX: function teste(){ document.getElementById('ret_teste').innerHTML = "<div align='center'><img src='./loader.gif'></div>"; var inp_val = frm.inp_cont.value; var url="teste.php?action=users&teste="+inp_val; xmlHttp.open("GET",url,true); xmlHttp.onreadystatechange=stateChanged_r; xmlHttp.send(null); function stateChanged_r(){ if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ document.getElementById("ret_teste").innerHTML = xmlHttp.responseText; } } } Quote Link to comment Share on other sites More sharing options...
cauca Posted October 15, 2008 Author Share Posted October 15, 2008 Ok thank´s F1Fan! I tried it but didn´t have success !!! when I call the function the php don´t return the image ! God Bless Paulo Cauca Quote Link to comment Share on other sites More sharing options...
F1Fan Posted October 15, 2008 Share Posted October 15, 2008 Show me all of your new code. Also, look at your JS error console and list any errors. The code button is the 8th button from the left just above the smiley faces on the "reply" screen. Quote Link to comment Share on other sites More sharing options...
cauca Posted October 16, 2008 Author Share Posted October 16, 2008 Hello, good morning ... I put the code online in de web visit please: www.barahinformatica.com.br/testimgfile/ Try type in "Procurar:" the names above: Paulo Roberto Patricia Renata Patrick Teste Cristina Oliveira Margarida Flor If you starting type letter "P" the function need return Paulo's image, Patricia's image and Patrick's image. Than´k God Bless PauloCauca Corin Falador Quote Link to comment Share on other sites More sharing options...
F1Fan Posted October 16, 2008 Share Posted October 16, 2008 You're not using the code I suggested. Your code will only show one image. Quote Link to comment Share on other sites More sharing options...
cauca Posted October 16, 2008 Author Share Posted October 16, 2008 ok ! I changed de code ... But now don't show de image ... Thank's God Bless Paulo Quote Link to comment Share on other sites More sharing options...
F1Fan Posted October 16, 2008 Share Posted October 16, 2008 Please re-post all of your code. Quote Link to comment Share on other sites More sharing options...
cauca Posted October 16, 2008 Author Share Posted October 16, 2008 ok !!! here is the code: index.php <html> <head> <script language="javascript"> var xmlHttp = false; try { xmlHttp = new ActiveXObject("Msxm12.XMLHTTP") } catch (e){ try { xmlHttp = new ActiveXObject("Microsoft.XMLHTTP") } catch (E){ xmlHttp = false } } if (!xmlHttp && typeof XMLHttpRequest != 'undefined') { xmlHttp = new XMLHttpRequest () } function teste(){ document.getElementById('ret_teste').innerHTML = "<div align='center'><img src='./loader.gif'></div>"; var inp_val = frm.inp_cont.value; var url="teste.php?action=users&teste="+inp_val; xmlHttp.open("GET",url,true); xmlHttp.onreadystatechange=stateChanged_r; xmlHttp.send(null); function stateChanged_r(){ if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ document.getElementById("ret_teste").innerHTML = xmlHttp.responseText; } } } function inserir(){ var ins_name = insert_values.ins_name.value var ins_file = insert_values.ins_file.value var url="insert.php" url=url+"?ins_name="+ins_name+"?ins_file"+ins_file url=url+"&sid="+Math.random() xmlHttp.open("GET",url,true) xmlHttp.onreadystatechange=stateChanged_i xmlHttp.send(null) function stateChanged_i() { document.getElementById('ret_insert').innerHTML = "<img src='./loader.gif'>"; if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { document.getElementById("ret_insert").innerHTML=xmlHttp.responseXML('Content-Type',"text/xml") } } } </script> </head> <body> <table align="center"> <tr> <td> <form name="insert_values" action="up.php" method="post"> Nome:<input type="text" name="ins_name"> Arquivo:<input type="file" name="ins_file"> <input type="submit" value="enviar""> </form> </td> </tr> <tr> <td><div id="ret_insert"</div> </td> </tr> <tr> <td colspan="2" align="center"> <form name="frm"> Procurar:<input type="text" name="inp_cont" onkeyup="teste(this)"><br> </form> </td> </tr> </table> <div id="ret_teste" align="center"></div> </body> </html> teste.php <?php include_once("conectadb.php"); if ($_GET['action']=="img"){ $query = "SELECT user_img WHERE user_id = '{$_GET['user_id']}'"; $result = mysql_query($query); $row = mysql_fetch_assoc($result); echo $row['user_img']; } else{ $teste = $_GET['teste']; $query="select user_id from user where user_name like '%$teste%'"; $select = mysql_query($query); while ($linha = mysql_fetch_assoc($select)){ $user = $linha['user_id']; echo "<image src='teste.php?action=img&user_id=$user'>"; } } ?> Thank's God Bless man Paulo Quote Link to comment Share on other sites More sharing options...
F1Fan Posted October 16, 2008 Share Posted October 16, 2008 OK, there's a problem with the query that gets the image. To test it, I went to: http://www.barahinformatica.com.br/testimgfile/teste.php?action=users&teste=pa and it almost shows three images. If you right-click on those images and select view image, you'll get this: http://www.barahinformatica.com.br/testimgfile/teste.php?action=img&user_id=1 along with this error: Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/barahinf/public_html/testimgfile/teste.php on line 6 So, the problem is somewhere in here: $query = "SELECT user_img WHERE user_id = '{$_GET['user_id']}'"; $result = mysql_query($query); $row = mysql_fetch_assoc($result); Quote Link to comment Share on other sites More sharing options...
cauca Posted October 16, 2008 Author Share Posted October 16, 2008 yessss I fund where are wrong : The select was missing this $query = "SELECT user_img [b]from user[/b] WHERE user_id = '{$_GET['user_id']}'"; yess Thank's man for all I'm lunch now srsrs God Bless Paulo Cauca Quote Link to comment Share on other sites More sharing options...
F1Fan Posted October 16, 2008 Share Posted October 16, 2008 LOL! That's funny, that was my mistake! Glad it works! You may want to add a piece in the JS function that checks if the user input is blank, because if you leave it like it is and there ends up being a lot of pictures, it may take a long time to load. By the way, I love your country. My wife and I spent a week in Rio de Janeiro this past February and we loved it. Plus my favorite F1 driver is Filipe Massa! Quote Link to comment Share on other sites More sharing options...
cauca Posted October 16, 2008 Author Share Posted October 16, 2008 Ok now I'll left the code more strong. You came to Rio de Janeiro, is a beautiful place to visit, but have a lot of beautiful beach in other states of Brasil , for exemple BOMBINHAS - Santa Catarina, or SALVADOR - Bahia, in NORDESTE'S beach in so beautiful too ! Thank's for all, God Bless you and your wife ! see you in the forum Paulo Cauca Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.