Jump to content

Recommended Posts

Hi, i have spent hours on google looking for an anwser as I just cant seem to get this to work. It seemed simple at first, but now I am not too sure. I am displaying information of a single row on a page using a while loop. I would like to take 4 variables $make $model  $year and $county to use in the title tag. This is what I have so far and it just shows me a totally blank page, it works without it it fine, where am I going wrong?

 

<title><?php custom_title(); ?></title>

 

<?php


			   if(mysql_num_rows($query)==0){

				die("Sorry, but the page doesnt exist!");

				  }else{

					while($info = mysql_fetch_array($query)){
					$price = number_format($info ['price']); //formatting the price to use a thousand separator
						echo "<div id=\"details\">";	
						echo "<div id=\"make\"><h1>" . $info['make'] . " " . $info['model'] . "</h1></div>";
						echo "<div id=\"left_spec\">";
						echo " <span class=\"price\">£$price</span>";
						echo "<h2>Specification:</h2>";
						echo "<div class=\"spec_item\"><strong>Year: </strong></div><div class=\"spec_detail\">" . $info ['year'] . "</div>";
						echo "<div class=\"spec_item\"><img src=\"images/".$info['berth'] . ".gif\" class=\"berth\"  alt=\"". $info['berth'] ." berth\"/>" .$info['berth'] . " berth</div>";
						echo "<div class=\"spec_item\"><strong>MIRO: </strong></div><div class=\"spec_detail\">".$info['weightun'] . "kg</div>";
						echo "<div class=\"spec_item\"><strong>MTPLM: </strong></div><div class=\"spec_detail\">".$info['weightla'] . "kg</div>";
						echo "<div class=\"spec_item\"><strong>Internal: </strong></div><div class=\"spec_detail\">".$info['lengthin'] . "ft</div>";
						echo "<div class=\"spec_item\"><strong>Shipping length: </strong></div><div class=\"spec_detail\">".$info['lengthex'] . "ft</div>";	
						echo "<div class=\"spec_item\"><strong>Awning size: </strong></div><div class=\"spec_detail\">".$info['awning'] . "cm</div>";
						echo "<div class=\"spec_item\"><strong>Additional description: </strong></div><div id=\"additional\">".$info['spec'] . "</div><br />";
						echo "<h2>Contact:</h2>";
						echo "<div class=\"spec_item\"><strong>Contact name: </strong></div><div class=\"spec_detail\">".$info['contactname'] . "</div>";
						echo "<div class=\"spec_item\"><strong>Telephone: </strong></div><div class=\"spec_detail\">".$info['contactnum'] . "</div>";
						echo "<div class=\"spec_item\"><strong>Email: </strong></div><div class=\"spec_detail\"><a href=\"mailto:".$info['contactemail'] . "\">".$info['contactemail'] . "</a></div>";
						echo "<div class=\"spec_item\"><strong>County: </strong></div><div class=\"spec_detail\">".$info['county'] . "</div><br /><br />";
						echo "<hr width=\"90%\" class=\"solid\">";
						echo "<form method='post' action='sendmail.php'>
								<div class=\"form_titles\">Name: </div><input name=\"name\" type=\"text\" /><br />
								<div class=\"form_titles\">Email address: </div><input name=\"email\" type=\"text\" /><br />
								<input name=\"hidden\" type=\"hidden\" value=\"". $info ['contactemail'] ."\" />
								Enquiry:<br />
								<textarea name=\"comments\" rows=\"15\" cols=\"40\">
								</textarea><br />
								<input type=\"submit\" />
							</form>";
					echo "</div>";
					echo "<div id=\"right_images\">";
						echo "<img src=\"".$info['image2'] . "\" class=\"display\" alt=\"". $info['make'] . " " . $info['model'] ."\"/>";
						echo "<img src=\"".$info['image3'] . "\" class=\"display\" alt=\"". $info['make'] . " " . $info['model'] ."\"/>";
						echo "<img src=\"".$info['image4'] . "\" class=\"display\" alt=\"". $info['make'] . " " . $info['model'] ."\"/>";
						echo "<img src=\"".$info['image5'] . "\" class=\"display\" alt=\"". $info['make'] . " " . $info['model'] ."\"/>";
					echo "</div>";

				echo "</div>";



				function custom_title() 
				{
				$make = $info ['make'];
				$model = $info ['model'];
				$year = $info ['year'];
				$county = $info ['county'];

				echo "Used $make $model $year for sale in $county";
				}

				 }

			}

	?>

Read on variable scope. In short: variables declared outside of a function are not seen within it. You have to pass them to it.

 

Another thing. It's genrally better to have a function that returns a value, and then echo it.

 

function custom_title($info) 
{
  $make = $info ['make'];
  $model = $info ['model'];
  $year = $info ['year'];
  $county = $info ['county'];
              
  return "Used $make $model $year for sale in $county";
}

 

<title><?php echo(custom_title($info)); ?></title>

Hi, thanks v much for the reply, I have done what you suggested and replaced my function and title tag with what you suggested but I am still getting a blank page? is it because the function is inside the loop which is after the title tag?

is there any way i can get around it because as you can see by my code that the loop creates the page which obviously must come after the title tag, I have turned error reporting on and still a blank page?

 

There is. It's called separation of data preparation and data display.

 

You should run all mysql queries that get data from database first. Then display your HTML.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.