!!!!!! ROW Table PROBLEM !!!!!!!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
maceved23
Forum Newbie
Posts: 17
Joined: Sun Jul 13, 2003 11:56 pm

!!!!!! ROW Table PROBLEM !!!!!!!

Post by maceved23 »

Hi.

I'm having a problem with a page I want to show. My query is working perfect but when a I get data from my DB, a table is create for each user.

I need to show data of each user one after one in my table, one row for each user.

This is the code

Code: Select all

include('config.php');

if (empty($email_busca))
	{
	viewheader();
	echo"<h4>Olvido digitar el correo electrónico que desea consultar</h4>";
	echo"<br>";
	echo"<center><h4><a href="javascript:history.back()">Regresar</a></h4></center>";
	viewfooter();
	exit;
	}
	db_connect();
	viewheader();

$res = mysql_query("SELECT * FROM `$dbtable` WHERE `email1`  LIKE '%{$_GET['email_busca']}%' LIMIT 10") or die(mysql_error());
if (mysql_num_rows($res)<1){

echo"<br>";
echo"<br>";
echo"<br>";
echo "ESTE CORREO ELECTRÓNICO NO HA SIDO REGISTRADO!!!!";
echo"<br>";
echo"<h4><a href="javascript:history.back()">Regresar</a></h4>";
} else {

while ($row = mysql_fetch_assoc($res))
{
echo"<br>";
echo"<h4>ESTOS SON LOS DATOS DEL USUARIO CONSULTADO</h4>";
echo"<br>";

echo"<table width='80%' border='0' cellpadding='1' cellspacing='0' class='textfield2'>";
      	echo"<tr bgcolor='#F6F6F6'>";
	echo"<td valign='top' align='right' colspan='4'>";
    echo"<font>";
	echo" - ";
	echo"<a href='menu.php'>REGRESAR</a>";
	echo" - ";
	echo" - ";
	echo"<a href='logout.php'>SALIR</a>";
	echo" - ";
	echo"</font>";
    echo"</td>";
	echo"</tr>";
      	
      	      	echo"<tr>";
        echo"<td valign='top'>";
 	echo"<table width='100%' border='0' cellspacing='1' cellpadding='3' align='center'>";
	echo"<tr bgcolor='#F1F1F1'>";
        echo"<td valign='top' colspan='3'>";
      	echo"<font>";
      		echo"<tr bgcolor='#F6F6F6'>";
	echo"<td><font><b>Nombre</b></font></td>";
	echo"<td><font><b>Email</b></font></td>";
	echo"<td><font><b>Consultar</b></font></td>";
	echo"<td align='center'><font><b>Mail</b></font></td>";
	echo"<td align='center'><font><b>Seguimiento</b></font></td>";
	echo"</tr>";
	echo "<tr bgcolor='$bgColor'>";
	echo"<td valign='top'><font><b>{$row['nombre']} {$row['apellido1']} {$row['apellido2']}</b><br>";
	echo"<td valign='top'><a href='mailto:$email1'>{$row['email1']}</a></td>";
	echo"<td><a href='fiche_membre1.php?id={$row['id']}' target='_blank') onMouseOver="status='Consultar Información del usuario'; return true;" onMouseOut="status='';">Consultar Información</a><br></td>";
	echo"<td><a href='envio_mail.php?id={$row['id']}' target='_blank' onMouseOver="status='Ingresar'; return true;" onMouseOut="status='';"><center><img src='checkbox.gif' width='18' height='18' border='0'><b></b></center></a></td><br>";
	echo"<td><a href='seguimiento.php?id={$row['id']}' target='_blank' onMouseOver="status='Ingresar'; return true;" onMouseOut="status='';"><center><img src='seg.gif' width='22' height='18' border='0'><b></b></center></a></td><br>";
	echo"<tr bgcolor='#F6F6F6'>";
	echo"<td valign='top' align='right' colspan='5'>";
    echo"<font>";
	echo" - ";
	echo"<a href='menu.php'>REGRESAR</a>";
	echo" - ";
	echo" - ";
	echo"<a href='logout.php'>SALIR</a>";
	echo" - ";
	echo"</font>";
    echo"</td>";
	echo"</tr>";
	echo"</table>";
	echo"</td></tr></table>";
	echo"<br>";
	echo"<br>";
}
}
HELP ME I KNOW IT COUL BE SIMPLE BUT I DON'T SEE THE ERROR
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

The issue is with where you've placed your HTML tags - if you put them in the while loop then you will get one table per record...

I had a go at reformatting your code:

Code: Select all

<?php

include 'config.php';

if (empty($email_busca)) {
	viewheader();
	echo '<h4>Olvido digitar el correo electrónico que desea consultar</h4>';
	echo '<h4 style="text-align: center;"><a href="javascript:history.back()">Regresar</a></h4>';
	viewfooter();
	exit;
}

db_connect();
viewheader();

// separate out your SQL query - it'll make your life much easier in the long
// run.
$sql = "SELECT * FROM `$dbtable` WHERE `email1`  LIKE '%{$_GET['email_busca']}%' LIMIT 10";
$res = mysql_query($sql) or die(mysql_error().'<p>'.$sql.'</p>');

// be consistent about where you place braces on your statements.
if (mysql_num_rows($res) < 1) {

echo '<p style="margin: 30 0 10 0;">ESTE CORREO ELECTRÓNICO NO HA SIDO REGISTRADO!!!!</p>';
echo '<h4><a href="javascript:history.back()">Regresar</a></h4>';

} else {

	// you need to start the table here if you want it to contain all of the 
	// records, if you put the start in the while loop you'll get one table
	// and heading per record
?>

<h4>ESTOS SON LOS DATOS DEL USUARIO CONSULTADO</h4>

<!-- be consistent about using either single or double quotes around
     your HTML
	 use CSS properly - then you won't have to use  tags anymore 
	 and delete all your  tags -->

<!-- your table tags were a bit messy - missing closing tags and 
     strangely nested tables, I've tried to clean it up but I'm not
	 sure how well it worked -->
<table width="80%" border="0" cellpadding="1" cellspacing="0" class="textfield2">
<tr bgcolor="#F6F6F6">
	<td valign="top" align="right">
		- <a href='menu.php'>REGRESAR</a> -  - <a href='logout.php'>SALIR</a> - 
	</td>
</tr>
<tr>
	<td valign="top">
		<table width="100%" border="0" cellspacing="1" cellpadding="3" align="center">
		<tr bgcolor="#F1F1F1">
			<td valign="top" colspan="5">&nbsp;</td>
		</tr>
		<tr bgcolor="#F6F6F6">
			<th style="text-align: left;">Nombre</th>
			<th style="text-align: left;">Email</th>
			<th style="text-align: left;">Consultar</th>
			<th>Mail</th>
			<th>Seguimiento</th>
		</tr>
<?php
	// format your code - use tabs to make it easier to follow.
	while ($row = mysql_fetch_assoc($res)) {
?>
		<!-- where does the $bgColor variable come from? -->
		<tr bgcolor="<?php echo $bgColor; ?>">
			<td valign="top">
				<b><?php echo $row['nombre']; ?> <?php echo $row['apellido1']; ?> <?php echo $row['apellido2']; ?></b>
			</td>
			<td valign="top">
				<a href="mailto:<?php echo $row['email1']; ?>"><?php echo $row['email1']; ?></a>
			</td>
			<td>
				<a href="fiche_membre1.php?id=<?php echo $row['id']; ?>" target="_blank" onMouseOver="status='Consultar Información del usuario'; return true;" onMouseOut="status='';">Consultar Información</a>
			</td>
			<td>
				<div align="center"><a href="envio_mail.php?id=<?php echo $row['id']; ?>" target="_blank" onMouseOver="status='Ingresar'; return true;" onMouseOut="status='';">
					<img src="checkbox.gif" width="18" height="18" border="0" />
				</a></div>
			</td>
			<td>
				<div align="center"><a href="seguimiento.php?id=<?php echo $row['id']; ?>" target="_blank" onMouseOver="status='Ingresar'; return true;" onMouseOut="status='';">
					<img src="seg.gif" width="22" height="18" border="0" />
				</a></div>
			</td>
		</tr>
<?php
	
	} // end while
	
?>
		</table>
	</td>
</tr>
<tr bgcolor="#F6F6F6">
	<td valign="top" align="right">
	 - <a href='menu.php'>REGRESAR</a> -  - <a href='logout.php'>SALIR</a> - 
	</td>
</tr>
</table>

<?php
} // end if 
?>
Mac
maceved23
Forum Newbie
Posts: 17
Joined: Sun Jul 13, 2003 11:56 pm

WORKING I UNDERSTAND MY ERROR

Post by maceved23 »

THANKS A LOT
twigletmac



I unadestand wich was my problem, you help me a lot, thanks for your time, and dedication in this wonderful forum.

MARIO A.
Post Reply