Using a sql query thats stored in a table on the database.

Hi,

I am trying to store a sql query in a database, but every time I try to read it, it shows all the code as text.

Here is the code on the page:
[php] $parts_sql = “SELECT * FROM parts WHERE part_cat = " . $category_row[‘cat_id’] . " ORDER BY CAST(part_a AS DECIMAL(10,2))”;

		$parts_result = mysql_query($parts_sql);

		if(!$parts_result)
		{
			echo '<tr><td>The parts could not be displayed, please try again later.</tr></td></table>';
		}
		else
		{

			while($parts_row = mysql_fetch_array($parts_result))
			{
                                          $pageformat_sql = "SELECT * FROM category_pages WHERE catpage_number = " . $category_row['cat_page'] . "";

                                          $pageformat_result = mysql_query($pageformat_sql);


                                           if(!$pageformat_result)
                                           {
                                           echo 'Error';
                                           }
                                            else
                                            {
                                            while($pageformat_row = mysql_fetch_assoc($pageformat_result))
                                            {
                                              $data = $pageformat_row['catpage_table'];
                                            echo '<table class="table2 centre" style="width:750px">
                                              ' . $pageformat_row['catpage_tabletitle'] . '' . $data . '';



                                            }
                                            }

}}[/php]

And this is what is stored in the database table:
[php]

' . $parts_row['part_number'] . ' ' . $parts_row['part_a'] . ' mm ' . $parts_row['part_b'] . ' mm ' . $parts_row['part_c'] . ' mm ' . $parts_row['part_d'] . ' mm ' . $parts_row['part_e'] . ' mm ' . $parts_row['part_imped100'] . ' <img border="0" src="images/pdf.jpg" alt="Download" [/php]

I would be very grateful to anyone who can help me with this.

I think there is a lot of information missing here, and possibly some incorrect information.

Are you really trying to store a “query”, or store the data, or store the php code to display the data?

This smells of all kinds of wrong. Tell us about what you are ultimately trying to do so we can give you the right answers.

Sponsor our Newsletter | Privacy Policy | Terms of Service