neridaj Posted January 2, 2008 Share Posted January 2, 2008 Hey, I need to extract some width and height dimensions from a database that include double quotes i.e., 25" x 35". I can't figure out how to escape the quotes and print them to the page concatenated with other data. Here is the code I'm trying to use: /* <?php include( 'dbinfo.php' ); $conn = mysql_connect( $dbhost, $dbuser, $dbpass ); mysql_select_db($dbname); $sql = 'select painting_id, painting_title, painting_year, painting_details, painting_dimensions, painting_pixel_height, painting_status from paintings where painting_year = 2007'; $demoResult = mysql_query( $sql ); while ( $demoRow = mysql_fetch_row( $demoResult ) ) { $id = $demoRow[0]; $title = $demoRow[1]; $year = $demoRow[2]; $details = $demoRow[3]; $dimensions = $demoRow[4]; $height = $demoRow[5]; $status = $demoRow[6]; $vartitle = str_replace(" ", "_", $title); $vartitle = strtolower($vartitle); $class = "floatright"; if($id % 2 != 0) { $class = ""; } $rndtitle = 'select painting_title from paintings where painting_year = 2007 order by rand() limit 1;'; $rndimg = mysql_query( $rndtitle ); $rndimg = mysql_fetch_array( $rndimg ); $rndimgtitle = $rndimg['painting_title']; $rndimgtitle = strtolower($rndimgtitle); $rndimgtitle = str_replace(" ", "_", $rndimgtitle); $vardimensions = str_replace('"', '\"', $dimensions); $caption = $title . ', ' . $year . '<br />' . $details .'<br />' . $vardimensions . '<br />' . $status; echo '<a class="' . $class . '" href="javascript:;" onclick="document.thumblarge.src=\'images/' . $vartitle . '_sdw.jpg\'; document.thumblarge.height=\'' . $height . '\'; document.getElementById(\'caption\').innerHTML=\'' . $caption . '\';" onmouseout="MM_swapImgRestore();" onmouseover="MM_swapImage(\'' . $vartitle . '_off\',\'\',\'thumbs/' . $vartitle . '_on.jpg\',1);"><img name="' . $vartitle . '_off" src="thumbs/' . $vartitle . '_off.jpg" width="100" height="100" border="0" id="' . $vartitle . '_off" alt="" /></a>'; }echo $caption; mysql_close ($conn); ?> */ Would it make more sense to leave the quotes out of the column and concatenate them to the data afterwards? Thanks, Jason Quote Link to comment https://forums.phpfreaks.com/topic/84044-solved-printing-double-quotes-from-database/ Share on other sites More sharing options...
The Little Guy Posted January 2, 2008 Share Posted January 2, 2008 htmlentities() place that around the outputted quotes. Quote Link to comment https://forums.phpfreaks.com/topic/84044-solved-printing-double-quotes-from-database/#findComment-427809 Share on other sites More sharing options...
neridaj Posted January 2, 2008 Author Share Posted January 2, 2008 Thanks a lot, worked like a charm! Quote Link to comment https://forums.phpfreaks.com/topic/84044-solved-printing-double-quotes-from-database/#findComment-427931 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.