Jump to content

Recommended Posts

I don't know what i'm asking for so i haven't searched the forumns - appologies!

 

I have the following:

<table width="100%">

<tr align="center" bgcolor="#c0c0c0">

<td width="10%">Request Number</td>

<td width="20%">Product</td>

<td width="50%">Title</td>

<td width="10%">Created Date</td>

<td width="10%">View?</td>

</tr>

<?PHP

for($i = 1; $i < 11; ++$i)

{

echo('<tr>');

echo('<td align="center">Number $i</td>');

echo('<td>Product $i</td>');

echo('<td>Title $i</td>');

echo('<td align="center">Date $i</td>');

echo('<td align="center"><input type="submit" value="View" /></td>');

echo('</tr>');

}

?>

</table>

 

Now if i put that into a .php file and look at it through internet explorer it works fine.

 

But if i put it into a database along with the rest of the content of my website, the website code picks up the page id, hits the db and echo's it out - this seems to work for html tags, but not php? i get this instead:

 

); echo(' Number $i '); echo(' Product $i '); echo(' Title $i '); echo(' Date $i '); echo('  '); echo('

'); } ?> 

 

I guess at the point i echo out the content the processing of php has already been done - what can i do?

Ok... try this...

 

<table width="100%">
<tr align="center" bgcolor="#c0c0c0">
<td width="10%">Request Number</td>
<td width="20%">Product</td>
<td width="50%">Title</td>
<td width="10%">Created Date</td>
<td width="10%">View?</td>
</tr>
<?php
for($i = 1; $i < 11; ++$i)
{
   echo '<tr>';
   echo '<td align="center">Number $i</td>';
   echo '<td>Product $i</td>';
   echo '<td>Title $i</td>';
   echo '<td align="center">Date $i</td>';
   echo '<td align="center"><input type="submit" value="View" /></td>';
   echo '</tr>';
}
?>
</table>

Have you connected to the database before you are trying to call data from it.  I can not see that you have  done that. 

 

Also you dont actually have any variable defined apart from $i, which is just counting. 

 

 

Connect.php

 

<?
//config for mysql 
$database_dbname = "Put your database name here";
$database_server = "localhost";
$database_username = "root";
$database_password = "";

$dbconn = mysql_connect($database_server, $database_username, $database_password);

if($table = mysql_select_db($database_dbname, $dbconn)) { 
echo "<H2>select table ok!</H2>";
} else {
echo "<h2>error selecting</h2>";
}
?>

 

Then you need to call it in your function

 

<table width="100%">
<tr align="center" bgcolor="#c0c0c0">
<td width="10%">Request Number</td>
<td width="20%">Product</td>
<td width="50%">Title</td>
<td width="10%">Created Date</td>
<td width="10%">View?</td>
</tr>
<?php

require_once("connect.php");
for($i = 1; $i < 11; ++$i)
{
   echo '<tr>';
   echo '<td align="center">Number $i</td>';
   echo '<td>Product $i</td>';
   echo '<td>Title $i</td>';
   echo '<td align="center">Date $i</td>';
   echo '<td align="center"><input type="submit" value="View" /></td>';
   echo '</tr>';
}
?>
</table>

 

That will get you connecting to the database.  Now you need to fetch the information.  Can you post the table structure?

 

The whole of the website is working and pulling data from the database for html tags (i.e. basic content) theres no problem with that at all. The bit i'm doing at the moment is just popping in placeholders so i can then go and have a look at the layout. Then once happy i'm going to go and hit the database and pull the real data back. But at the moment the table won't draw corretcly with the dummy 10 rows.

The source of the website is

<table width="100%">

<tr align="center" bgcolor="#c0c0c0">

<td width="10%">Request Number</td>

<td width="20%">Product</td>

<td width="50%">Title</td>

<td width="10%">Created Date</td>

<td width="10%">View?</td>

</tr>

<?php

for($i = 1; $i < 11; $i++)

{

  echo '<tr>';

  echo '<td align="center">Number $i</td>';

  echo '<td>Product $i</td>';

  echo '<td>Title $i</td>';

  echo '<td align="center">Date $i</td>';

  echo '<td align="center"><input type="submit" value="View" /></td>';

  echo '</tr>';

}

?>

</table>

after being sent to the client. so why is the output of the script not being processed?

Im not sure I get what you mean.  I have run this code on my server and it comes out fine, check below.

 

phphelpcu2.th.png

 

Im unsure what you are doing, or are trying to do. Are you running a server on your computer? because if you are running a php script without a server it will not run! hope this helps.

 

 

I'm now pretty sure of my problem: What i'm trying to echo is PHP (<?PHP ..... ?>) which you can't do.

I have other code that hits the db and echo's content. If the content i'm trying to echo is:

<table width="100%">

<tr align="center" bgcolor="#c0c0c0">

<td width="10%">Request Number</td>

<td width="20%">Product</td>

<td width="50%">Title</td>

<td width="10%">Created Date</td>

<td width="10%">View?</td>

</tr>

<?php

for($i = 1; $i < 11; $i++)

{

  echo '<tr>';

  echo '<td align="center">Number $i</td>';

  echo '<td>Product $i</td>';

  echo '<td>Title $i</td>';

  echo '<td align="center">Date $i</td>';

  echo '<td align="center"><input type="submit" value="View" /></td>';

  echo '</tr>';

}

?>

</table>

then the bits within the <?PHP ?> tags won't work.

 

So how do i get around that? having content in the db which is PHP and processing that to include in the echo.

If you're trying to select the information for the table from a mySQL database, you need to tell us what the fields/tables are called. I'd scrap the for() and use a while() loop to display the table; but we can't help without database information!

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.