![]() |
| ||
| Returning HTML code through SQL query? I need to return some HTML code stored as a text data type in my database. Is there a way to return this HTML effiencly through PHP that will execute this code when HTML parses the page? Currently I have this: $result = @mysql_query("SELECT * FROM sponsors");This works for normal text but not HTML or jscript etc. Any suggestions? |
| ||
| Re: Returning HTML code through SQL query? Correction, straight HTML works however scripts will not work. |
| ||
| Re: Returning HTML code through SQL query? Dude, are you trying to use javascript with the php? Instead of using javascript the way you want - make the php echo the results for you. Another thing is - you can optimize your query to the mysql db, as I see you want a single cell from the table to be displayed. Instead retrieving all records using * in the select statement, better do it like this. $result = mysql_query("select html from sponsor"); $rows = mysql_num_row($result) -> this will give you information how many records you have in the db. if ($rows=0) { echo '<p>No sponsors at this time!</p>';} else { echo '<table>'; for ($i=0; $i<$rows; $i++) { $text = mysql_result($result, $i); -> you don't need the column name as it is only 1 column echo "<tr> /n /t<td>$text</td> /n /t</tr>"; } } echo '</table>'; And that's that. Try it and advise what happens. |
| ||
| Re: Returning HTML code through SQL query? Thanks for the response. I know it looks dumb but for some reason php echo commands do not work on the server (its not my server, im doing this fo a friend). So I resorted to js commands to print results. Thanks for the optimization tips. I changed up the code a bit and i have some code to work but not others and for some reason (its a very strange server) it wont throw the errors when there is one, it just wont run the script. What works right now is text like this: <img src="IMAGE SOURCE URL"> But what doesn't work is this: <p>TEXT HERE! - Anyone know why this would not work? Thanks. |
| ||
| Re: Returning HTML code through SQL query? UPDATE: What i am doing is takign the html string, performing the php function, addslashes($html); and then inserting that into the database. This works however when I tried to print to the screen it shows up as white space. I'm assuming its throwing an error however idk where its coming from. Any help would be appreciated. |
| ||
| Re: Returning HTML code through SQL query? Quote:
Apache 2.x does not show errors along with the code. To view the errors you have, check the apache error log or change the config file to show php errors. - I am not 100% sure whether you have to change the httpd.conf or the php.ini - I have to check. If you have errors in your mysql syntax, then you should use the mysql_error() function of php. It goes something like this e.g. $query = mysql_query("your_query", link); if (!$query){die mysql_error();} For the echo function, it is really awkward, still you can always try the print() function, that is basically the same. Good luck. p.s. use <?php ?> as of versions abve 4.x |
| ||
| Re: Returning HTML code through SQL query? Don't know if this will be any help. But i'd suggest using a inline frame to print the table onscreen. Use this script to print the table <?php Then just link the url to the inline frame NB. Remember to save your html as PHP if your phasing isn't setup. This is probably the easiest way i've come up with without the use of phasing. |
| All times are GMT -4. The time now is 11:30 am. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC