close ad
Install the LAtest Updates to Work with CC 2017 and CC 2018
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

PHP Repeat Region not working when the repeat region contains a Server Side Include?

Thread began 2/11/2014 7:02 am by Nathon Jones Web Design | Last modified 2/14/2014 10:29 am by Jason Byrnes | 2670 views | 17 replies |

Nathon Jones Web Design

PHP Repeat Region not working when the repeat region contains a Server Side Include?

We have added a repeat region to our page to repeat products from our MySQL database table.
It looks like this:

<?php do { ?>
<div class="prodfullpanel">

<div class="prodfullpaneltop">
<div class="prodfullpanelcol1">
<img src="led-light-bulbs/tmb/<?php echo $row_rsPRODFULL['LEDimgtmb']; ?>" width="120" height="120" style="border:none;" /><br />
<?php if ($row_rsPRODFULL['LEDwattage'] > 0) { // Show if column... ?>
<?php
$wattvalue=$row_rsPRODFULL['LEDwattage'];
echo str_replace('.0', '', $wattvalue);
?> Watt
<?php } // Show if column... ?>
</div>
<div class="prodfullpanelcol2">
<span class="h2style"><?php echo $row_rsPRODFULL['LEDtitle']; ?></span><br />
<span class="orange"><?php echo $row_rsPRODFULL['LEDproductcode']; ?></span>
<div class="pagefull">
<div class="page33">
<p>Brightness</p>
</div>
<div class="page34">
<p>Beam Angle<br />
<?php
if ($row_rsPRODFULL['LEDbeamangle']=="36")
{echo "<img src='plugins/beam-angles/36.png' width='75px' height='75px' />";}
elseif ($row_rsPRODFULL['LEDbeamangle']=="40")
{echo "<img src='plugins/beam-angles/40.png' width='75px' height='75px' />";}
elseif ($row_rsPRODFULL['LEDbeamangle']=="60")
{echo "<img src='plugins/beam-angles/60.png' width='75px' height='75px' />";}
elseif ($row_rsPRODFULL['LEDbeamangle']=="90")
{echo "<img src='plugins/beam-angles/90.png' width='75px' height='75px' />";}
elseif ($row_rsPRODFULL['LEDbeamangle']=="120")
{echo "<img src='plugins/beam-angles/120.png' width='75px' height='75px' />";}
?>
</p>
</div>
<div class="page33">
<p>Dimmable<br />
<?php
$dimm=$row_rsPRODFULL['LEDdimmable'];
if ($dimm=="True")
{echo "Yes";}
else
{echo "No";}
?>
</p>
</div>
</div>
<div class="pagefull">
<p>6 Year Warranty | 30 Day Hassle Free Returns</p>
</div>
</div>
<div class="prodfullpanelcol3">
<p><span class="h4style">£<?php echo $row_rsPRODFULL['LEDprice']; ?></span> inc. vat</p>
<p>&nbsp;</p>
</div>
</div>

</div>
<?php } while ($row_rsPRODFULL = mysql_fetch_assoc($rsPRODFULL)); ?>

We wanted to change this to be a Server Side Include so that we can make a change to one file and have it update all of our category pages so we changed it to this:

<?php do { ?>
<?php require_once("prodfullpanel.php"); ?>
<?php } while ($row_rsPRODFULL = mysql_fetch_assoc($rsPRODFULL)); ?>

prodfullpanel.php being the content that's in the first code block (above).
This causes the repeat region to stop working?

Can you not repeat Server Side Includes in PHP? We used this all the time in Classic ASP.
Would appreciate your advice. Thank you.
Regards
NJ

Sign in to reply to this post

Jason ByrnesWebAssist

This isn't a very good way to accomplish this.

Create a new page that contains the recordset and the repeat region.

then use Framework builder plugins to add it to main page.

see the Framework builder getting started guide:
http://www.webassist.com/tutorials/Getting-Started-with-Framework-Builder

Sign in to reply to this post

Nathon Jones Web Design

Out of interest though, should it work? If it should, why do you think it isn't?

I'm happy to try Framework Builder plugins but they sound very similar to what I was doing. Why do you feel that Server Side Includes aren't a good way to achieve what I am trying to achieve?

NJ

Sign in to reply to this post

Jason ByrnesWebAssist

doing it with server side includes like this the recordset would need to exist on both pages.

using framework builder, the recordset only needs to exist on famework page.

the downfall of using includes is that the code from the include page gets inserted at the include location.

if the include page has code that should go in the head of the document, this will; cause an issue.


Framework build plugins includes logic to parse the page into code chunks for the code above the doctype, in the head and in the body of the page.

when added to the main page the code chunks are placed in the correct place.


Plugins is a way of creating complex pieces of functionality, and reusing them across many pages in your site.

There are many limitations to using includes that are not inherent when using plugins.

Sign in to reply to this post

Nathon Jones Web Design

My include doesn't have code that should go in the head though. I already have the recordset coded in there and the reason I've chosen includes is because my recordset is different on every page, however the section pertaining to displaying the product information isn't.

If I use Framework build plugins then won't I need to create one for every one of my differing recordsets?

If I have coded the recordset manually in the head of the page above the DOCTYPE:

<?php require_once('Connections/njMySQL.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}

$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}

mysql_select_db($database_njMySQL, $njMySQL);
$query_rsPRODFULL = "SELECT LEDid, LEDtitle, LEDproductcode, LEDtypeID, LEDwattage, LEDdimmable, LEDbeamangle, LEDprice, LEDimgtmb, LEDdelete FROM LEDprods WHERE LEDdimmable = 1";
$rsPRODFULL = mysql_query($query_rsPRODFULL, $njMySQL) or die(mysql_error());
$row_rsPRODFULL = mysql_fetch_assoc($rsPRODFULL);
$totalRows_rsPRODFULL = mysql_num_rows($rsPRODFULL);
?>

...and then further down my page I have an include file that is simply calling fields from the above recordset, along with CSS styling and layout obviously, then shouldn't it work?

NJ

Sign in to reply to this post

Jason ByrnesWebAssist

no, the recordset would need to be in both pages.

using an include will not work for what you are trying to do.

maybe it did in ASP, but PHP is not the same.

Sign in to reply to this post

Nathon Jones Web Design

So this:

<?php require_once('Connections/njMySQL.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}

$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}

mysql_select_db($database_njMySQL, $njMySQL);
$query_rsPRODFULL = "SELECT LEDid, LEDtitle, LEDproductcode, LEDtypeID, LEDwattage, LEDdimmable, LEDbeamangle, LEDprice, LEDimgtmb, LEDdelete FROM LEDprods WHERE LEDdimmable = 1";
$rsPRODFULL = mysql_query($query_rsPRODFULL, $njMySQL) or die(mysql_error());
$row_rsPRODFULL = mysql_fetch_assoc($rsPRODFULL);
$totalRows_rsPRODFULL = mysql_num_rows($rsPRODFULL);
?>

...needs to be in the include file? Does the repeat region code also need to be in there?
Considering that all of my recordsets are different, do you still recommend Framework Builder plugins?

Thanks Jason.
Regards
NJ

Sign in to reply to this post

Jason ByrnesWebAssist

create a page for each recordset then and yes, use plugins.

Sign in to reply to this post

Nathon Jones Web Design

I already have pages for each recordset, for example:
http://www.ledwarehouseuk.com/LED-spotlights.php

Before I create Framework Builder plugins do I need to remove the recordset, repeat region and any PHP scripting relating to my database content from the above page?

When I create the new pages for the recordsets do I just go File > New? Won't that create a page with a title tag, meta tags, doctype etc? Do I need all of that? Won't W3C validation fail if that's the case?

Would appreciate clarification. Thank you.
Regards
NJ

Sign in to reply to this post

Jason ByrnesWebAssist

yes, remove the existing recodsets from the pages before creating the plugin pages.


yes use file new and create the page with the head, doc type and other code.

ses my previous explanation for why this wont cause a problem. it is the exact problem that using plugins is created to avoid.

Sign in to reply to this post
loading

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...