Page 1 of 1

echoing text, image and flash problem.

Posted: Thu Apr 14, 2011 1:07 pm
by Netroxy
Hello. So I've been helped by two experts on PHP, and I figured how to make my 'games.php?id='. I thank them for helping me, I wish I can offer them something. I have something regarding echoing out the text, images and flash. I have my Text to be displayed in a different area of the webpage, the flash in another area of the same page, and an ImageIcon in another area of the page. Just to get a better understanding, im extracting ID's with information from a mysql database. Anyhow, if I am to use a certain PHP code anywhere in the HTML page, is it necessary to use echo? I have noticed if I take one of the echo lines outside of the <? php and ?>, it won't work. Should all echos be within the brackets of the PHP? Also, should I place 'echo' to the left of all HTML codes if I am to associate them with the PHP code?

Thanks guys.

Re: echoing text, image and flash problem.

Posted: Thu Apr 14, 2011 1:27 pm
by social_experiment
Netroxy wrote:Should all echos be within the brackets of the PHP?
Yes. If it's not encased in php tags it will be parsed as html. It's necesarry to echo or the values will not be displayed.

Re: echoing text, image and flash problem.

Posted: Thu Apr 14, 2011 2:17 pm
by Netroxy
I can draw this for better understanding:

Webpage:



Category Title # of Plays

=================================================================
Advertisement



Flash Game



Advertisement
=================================================================
Game Instructions Controls




Ok so the example above is the layout I have. My problem is, when I paste the PHP code in the page, I am pasting right where the Flash Game is placed. The category text, title text, # of plays text, games instruction text and control text show up bundling with the flash game in the middle. All the text are stuck together inside one area with the flash game. I can't separate the echos to where they belong. I'm afraid if I take out the echo's within the PHP, the code will stop working. Here is an example of the code I have:



=============================

Code: Select all

<?php
if(isset($_GET['id'])) {
$conn = mysql_connect("host", "username", "password");
mysql_select_db("games");
$game_id = $_GET['id'];
$sql = "SELECT * FROM games WHERE id='$game_id' LIMIT 1";
$result = mysql_query($sql, $conn) or die(mysql_error());
$number_of_results = mysql_num_rows($result);

while ($result_array = mysql_fetch_array($result, MYSQL_ASSOC)) {

$id = $result_array['fldID'];
$title = $result_array['fldTitle'];
$iconsmall = $result_array['fldIconSmall']; // Example: game1234.png
$instructions = $result_array['fldInstructions'];
$controls = $result_array['fldControls'];
$swf = $result_array['fldSwfSrc']; // Example: game1234.swf
$iconsmall_file_location = 'http://www.blabla.com/games/images/' . $iconsmall;
$swf_file_location = 'http://www.blabla.com/games/' .$swf;

echo '<a href="http://www.blabla.com/games.php?id=' . $id . '"></a>';
echo '<h1>' . $title . '</h1>';
echo '<h1>' . $instructions . '</h1>';
echo '<h1>' . $controls. '</h1>';
echo '<img src="' . $iconsmall_file_location . '" width="50" height="50" border="0" />';
echo '<object width="550" height="400">';
echo '<param name="movie" value="' . $swf_file_location . '">';
echo '<embed src="' . $swf_file_location . '" width="550" height="400">';
echo '</embed>';
echo '</object>';
}
} else {
$sel2 = mysql_query("SELECT * FROM games");
if(!$sel2) {
echo "sorry could not get list of current games: " .mysql_error();
exit();
}
while($row = mysql_fetch_assoc($sel2)) {
echo "
Play " .$row['title']. "<a href='index.html?id=".$row['id']."'>Here</a>";
}
}
?>
=============================

I don't know how to take out the echos within the PHP script above, and place them in Category, Title, # of Plays, Game Instructions and Controls area, because HTML is surrounding those areas.

Re: echoing text, image and flash problem.

Posted: Fri Apr 15, 2011 1:31 am
by social_experiment
What happens if no row matching $_GET['id'] is found?