Jump to content

variable string mix html output


steveh62

Recommended Posts

Hi peeps, I am rather new here and would like some assistanece (HELP!!) in trying to resolve an issue I have...

 

1. I have a mysql query that brings in an image id and dependant on which gallery id the image comes from an include script is pulled in and rendered via a variable i.e as follows and then further output as stable html.

 

//pull in image id script

  if($pid )

{

other php stuff here {

$x .="<td>some more htm stuff</td><br/><td>$output</td>

 

}

}

 

// Final Output

echo <<<__HTML_END

 

<html>

<head>

<title></title>

</head>

<body>

<table width='100%' border='0' align='center' style='width: 100%;'>

$x

</table>

</body>

</html>

 

__HTML_END;

 

 

where $output is sourced via the include script as another variable.

 

the problem I have is in the include script...how can I insert as part of the rendering variable

a php/mysql query to render the below script dynamically - pulling in data from a db with the script erroring??

 

i.e.

//include this script if image is from gallery x and output var $output in var $x in script above.

 

$output = "<fieldset class='dropdown' style='border:0px'>

<legend>Available Sizes</legend>

<select name='canvasSizes'id='csizes' size='1' class='dropdown' onchange='CanvasFunction();'>

      <option value='200mm x 300mm'>200mm x 300mm</option>

      <option value='200mm x 400mm'>200mm x 400mm</option>

      <option value='200mm x 500mm'>200mm x 500mm</option>

    </select>

  </fieldset>";

 

I suppose really I want to be able to do a mysql query inside a variable, that contains other html, that will then render out in the

Link to comment
https://forums.phpfreaks.com/topic/128846-variable-string-mix-html-output/
Share on other sites

I  suppose what I am saying is...Can I do a mysql query inside a string variable that looks something like the following

 

$output = "Select from the following: (some choices are fixed)<p class='dropdown'><input type='radio' checked='checked' onClick='showCanvas();' name='selectType' id='canvas' value='canvas'>

    <b>Canvas</b></p>

  <p id='poster' class='dropdown'>

    <input type='radio' onClick='showPoster();' name='selectType' id='poster' value='poster'>

    <b>Poster</b></p>

<div id='canvasSizes' Style='display: block'>

<table><tr><td>

<form action='process.php' method='post'>

<fieldset class='dropdown' style='border:0px'>

<legend>Available Sizes</legend>

<select name='canvasSizes'id='csizes' size='1' class='dropdown' onchange='CanvasFunction();'>

      <option value='200mm x 300mm'>200mm x 300mm</option>

      <option value='200mm x 400mm'>200mm x 400mm</option>

      <option value='200mm x 500mm'>200mm x 500mm</option>

    </select>

  </fieldset>

 

";

 

TO this

 

$output = "Select from the following: (some choices are fixed)<p class='dropdown'><input type='radio' checked='checked' onClick='showCanvas();' name='selectType' id='canvas' value='canvas'>

    <b>Canvas</b></p>

  <p id='poster' class='dropdown'>

    <input type='radio' onClick='showPoster();' name='selectType' id='poster' value='poster'>

    <b>Poster</b></p>

<div id='canvasSizes' Style='display: block'>

<table><tr><td>

<form action='process.php' method='post'>

<fieldset class='dropdown' style='border:0px'>

<legend>Available Sizes</legend>";

 

$q = mysql_query("SELECT * from gallery WHERE id='".addslashes($pid)."'" );

echo '<select name='canvasSizes' id='csizes' size='1' class='dropdown' onchange='CanvasFunction();'>';

while ($row = mysql_fetch_assoc($result)) {

$x = $row['sizes'];

echo '<option value='$sizes'>$sizes</option>';

}

";

   

</select>

  </fieldset>

 

 

";

 

 

 

 

 

Ok, I think what you're looking to do is the following... You need to make the script that gets your drop down list a function. You can look that up in more details yourself but I'll provide a pseudo code example below...

 

libfunc ($image, $library){

if ($library == "library1")
{
GENERATE DROP DOWN LIST FOR LIBRARY 1;

echo $dropdownlist;
}elseif ($library == "library2")
{
GENERATE DROP DOWN LIST FOR LIBRARY 2;

echo $dropdownlist;
}elseif ($library == "library3")
{
GENERATE DROP DOWN LIST FOR LIBRARY 3;

echo $dropdownlist;
}
}

 

In your main script you will then call the following from your main query.

 

include "code above.php";

SQL QUERY OBTAINS VALUES OF $image AND $library;

$dropdownlist=libfunc($image, $library);

$htmlpage=CODE FOR HTML GENERATION PLUS $dropdownlist;

echo $htmlpage;

 

Tell me if I'm completely missing the point...

Look for the following variables to see how they are called $result_final , $output so there's actually three scripts

 

main which does the mysql calls to get the galleries and images, then it does an image check to see which gallery it belongs to...that then in turn gets the last script which is a variable string - need mysql query here to build the dynamic dropdown where the 1st drop down is. Ths is then in turn called via the $output variable back in the main script via $result_final...hope you see where I am coming from.

 

//main script
$images_dir = "gallery";
//include("config.inc.php");

// initialization
$result_array = array();
$counter = 0;

$pid = ($_GET['pid']);
//$gid = "";
$gid = (int)($_GET['gid']);

// Thumbnail Listing

if($gid && empty($pid))
{
	$number_of_thumbs_in_row = 4;

	$result = mysql_query( "SELECT * FROM gallery WHERE gid = $gid AND galleryType != 'B'" );//get data that is not a sale item
	$nr = mysql_num_rows( $result );
	if( empty( $nr ) )
	{
		$result_final = "\t<tr valign='top'><td>No Category found</td></tr>\n";
	}
	else
	{
		while( $row = mysql_fetch_array( $result ) )
		{
			$result_array[] = "
			<table width='115' cellpadding='1' cellspacing='0' bgcolor='#666666'><tr><td><table width='115' height='160' border='0' cellpadding='5' cellspacing='0' background='site_images/imagebgpix.jpg' align='center'><tr align='center'><td> 
			<a href='index.php?pid=".$row['id']."'><img src='".$images_dir."/tb_".$row['filename']."' border='0' width='100' height='150' alt='".$row[4]."' /><br/><span class='imagetxtlinks'>view details</span></a></td></tr></table></td></tr></table><br/>";
		}
		mysql_free_result( $result );	

		$result_final = "<tr>\n<tr>";

		foreach($result_array as $thumbnail_link)
		{
			if($counter == $number_of_thumbs_in_row)
			{	
				$counter = 1;
				$result_final .= "\n</tr>\n<tr>\n<tr>";
			}
			else
			$counter++;

			$result_final .= "\t<td>".$thumbnail_link."</td>\n";
		}

		if($counter)
		{
			if($number_of_photos_in_row-$counter)
		$result_final .= "\t<td colspan='".($number_of_photos_in_row-$counter)."'> </td>\n";

			$result_final .= "</tr>";
		}
	}
}

// Full Size View of Photo
 //else
  if($pid )
{

//get the rest of the assets for this particular image		
	$result = mysql_query("SELECT * from gallery WHERE id='".addslashes($pid)."'" );
	list($id, $gid, $galleryType, $print, $title, $filename, $desc, $keywords, $price) = mysql_fetch_array( $result );//mimic the table structure and pull in the data
	$nr = mysql_num_rows( $result );
	mysql_free_result( $result );	

	if( empty( $nr ) )
	{
		$result_final = "\t<tr><td>No Photo found</td></tr>\n";
	}
	else
	{

//check for image gallery type - special, named, genre(stock0, sale//

include("imagecheck.php");

[color=red]$result_final .=" //////formats this part for all galleries////
  <tr> 
    <td  valign='top'>
<a href='index.php?gid=$gid'><img src='site_images/back_btn.gif' border='0' title='back' alt='back'></a>
<img src='".$images_dir."/".$filename."' border='0'></td>
    <td  valign='top'>
<div id='mainimage'>
<div id='mainimagetitle'>
$title. from £$price
<div id='detaildesc'>
 $desc
 <br/><br/>'"
 .$output.
"</div></div><br/></div>
</td>
  </tr>[/color]";
	}
}

// Final Output
echo <<<__HTML_END

<html>
<head>
<title></title>
</head>
<body>
<table width='100%' border='0' align='center' style='width: 100%;'>
[color=red]$result_final[/color]		
</table>
</body>
</html>

__HTML_END;

if (($gid && pid)==0){
echo 'do something else here';
}
?>

 

//imagecheck include

<?
//image check
switch ($galleryType){
case S://special
include("specials_variants.php");
break;
case N://named galleries
include("named_variants.php");
break;
case G://genres
//include("genre_variants.php");
break;
}
?>

 

//and pulls in this if image belongs to this gallery
$output = "Select from the following: (some choices are fixed)<p class='dropdown'><input type='radio' checked='checked' onClick='showCanvas();' name='selectType' id='canvas' value='canvas'>
    <b>Canvas</b></p>
  <p id='poster' class='dropdown'>
    <input type='radio' onClick='showPoster();' name='selectType' id='poster' value='poster'>
    <b>Poster</b></p>
<div id='canvasSizes' Style='display: block'>
<table><tr><td>
<form action='process.php' method='post'>
<fieldset class='dropdown' style='border:0px'>
<legend>Available Sizes</legend>".select()."
<select name='canvasSizes'id='csizes' size='1' class='dropdown' onchange='CanvasFunction();'>
      <option value='200mm x 300mm'>200mm x 300mm</option>
      <option value='200mm x 400mm'>200mm x 400mm</option>
      <option value='200mm x 500mm'>200mm x 500mm</option>
    </select>
  </fieldset>
  <fieldset class='dropdown' style='border:0px'>
    <legend>Wrap: 
    </legend>	
<select name='wrap' id='cwrap' size='1'  class='dropdown'>
      <option value='Face Print only'>Face Print Only</option>
    </select>
</fieldset>
  <fieldset class='dropdown' style='border:0px'>
    <legend>Frame: 
    </legend>
<select name='cFrame' size='1' class='dropdown' id='cframe'>
      <option value='Wide (44mm)'>Wide (44mm)</option>
    </select>
</fieldset>
<fieldset class='dropdown' style='border:0px'>
    <legend>U.V coat: 
    </legend>
<select name='ccoat' id='ccoat' size='1'  class='dropdown' onchange='CanvasFunction();'>
      <option value='No'>No</option>
      <option value='Yes'>Yes</option>
    </select>
</fieldset>
		<fieldset class='dropdown' style='border:0px'>
    <legend>Output as: 
    </legend>
<select name='ckit' id='ckit' size='1' class='dropdown'>
      <option value='Stretched'>Stretched</option>
    </select>
</fieldset><br/>
<div id='CanvasDiv' class='redajaxOutput'><b>Total Price:£$price</b></div><br/><input name='canvas' type='submit' value='add to cart' class='dropdown'>
<input type='hidden' name='gid' value='$gid'>
<input type='hidden' name='pid' value='$pid'>
<input type='hidden' name='gallery' value='$title'>
<input type='hidden' id='baseprice' name='baseprice' value='$price'>
</form>
</td></tr></table>
</div>

<div id='posterSizes' style='display: none'>
<table><tr><td>
<form action='process.php' method='post'>
<fieldset class='dropdown' style='border:0px'>
<legend>Available Sizes</legend>
<select name='pSizes' id='psize' size='1' class='dropdown' onchange='PosterFunction();'>
      <option value='A0 (841mm x 1189mm)'>A0 (841mm x 1189mm)</option>
      <option value='A1 (594mm x 841mm)'>A1 (594mm x 841mm)</option>
      <option value='A2 (420mm x 594mm)'>A2 (420mm x 594mm)</option>
    </select>
  </fieldset>
  <fieldset class='dropdown' style='border:0px'>
    <legend>Border:</legend>
<select name='pborder' id='pborder' size='1' style='width: '200' class='dropdown' onchange='PosterFunction();'>
      <option value='No'>No</option>
      <option value='Yes'>Yes</option>
    </select>
</fieldset>
<fieldset class='dropdown' style='border:0px'>
    <legend>Finish:</legend>
<select name='pfinish' id='pfinish' size='1' style='width: '200' class='dropdown' onchange='PosterFunction();'>
      <option value='Gloss'>Gloss</option>
      <option value='Matt'>Matt</option>
    </select>
</fieldset>
<br>
<div id='PosterDiv' class='redajaxOutput'>Poster result will display here</div><br/><input name='psubmit' type='submit' value='add to cart' class='dropdown'>
<input type='hidden' name='gid' value='$gid'>
<input type='hidden' name='pid' value='$pid'>
<input type='hidden' name='gallery' value='$title'>
</form>	
</td></tr></table>
</div>
"
;
?>

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.