Jump to content

Running code inside of quotes?


hukadeeze

Recommended Posts

public function content_productshome($directories, $booksquery, $cardsquery, $categoriesquery)
{
	//Create array from categories query
	$num_categoriesresults = $categoriesquery->num_rows;
	$categories = array();
	for ($i=0; $i <$num_categoriesresults; $i++)
	{
		$currentcatrow = $categoriesquery->fetch_assoc();
		$categories[$currentcatrow['CategoryID']] = $currentcatrow['CategoryName'];
	}

	return '

	<p>
	books:
	</p>

	<table width="80%" border="1" cellspacing="3" cellpadding="3">
	  <tr>
		<td>Title</td>
		<td>Category</td>
		<td>ISBN</td>
		<td>Price</td>
	  </tr>
		$num_bookresults = $booksquery->num_rows;
		for ($i=0; $i<$num_bookresults; $i++)
		{
		$currentbookrow = $booksquery->fetch_assoc();
		  <tr>
			<td>echo $currentbookrow['Title'];</td>
			<td>echo $categories[$currentbookrow['CategoryID']];</td>
			<td>echo $currentbookrow['ISBN'];</td>
			<td>echo '$'.$currentbookrow['Price'];</td>
		  </tr>
		}
	</table>

	<p>
	cards:
	</p>

	';


}

The same process would take place beneath the cards paragraph as well.

Try this.  There may be a few typos as I am unable to test it, but you should be able to see the general idea.  I am placing all the output into a variable $html, then returning that variable at the end.

 

public function content_productshome($directories, $booksquery, $cardsquery, $categoriesquery)
{
	//Create array from categories query
	$num_categoriesresults = $categoriesquery->num_rows;
	$categories = array();
	for ($i=0; $i <$num_categoriesresults; $i++)
	{
		$currentcatrow = $categoriesquery->fetch_assoc();
		$categories[] = $currentcatrow;
	}

	$html = '

	<p>
	books:
	</p>

	<table width="80%" border="1" cellspacing="3" cellpadding="3">
	  <tr>
		<td>Title</td>
		<td>Category</td>
		<td>ISBN</td>
		<td>Price</td>
	  </tr>';

		$num_bookresults = $booksquery->num_rows;
		for ($i=0; $i<$num_bookresults; $i++)
		{
		$currentbookrow = $booksquery->fetch_assoc();
		  $html .= "<tr>
			<td>{$currentbookrow['Title']}</td>
			<td>{$categories[$currentbookrow['CategoryID']]}</td>
			<td>$currentbookrow['ISBN']}</td>
			<td>{$currentbookrow['Price']}</td>
		  </tr>";
		}
                $html .= '</table>

	<p>
	cards:
	</p>

	';

                return $html;
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.