echo table with link?
Moderator: General Moderators
echo table with link?
Hi guys, I am still trying to learn this php and I would apreciate any help.
I would like to display my data in a html table with one of the columns being a link.
All my variables are
$companyname = "whatever"; // would like this to be a link to nextpage.php
$address = "whatever";
$telephone = "whatever";
$type = "whatever";
I have tried:
echo "<table><td><a href="nextpage.php">$companyname</a></td></table>" but it does not seem to work.
Any ideas on how I can do this.
My database query has a limit of 30 and I would like to display 30 if possible.
thanks in advance.
I would like to display my data in a html table with one of the columns being a link.
All my variables are
$companyname = "whatever"; // would like this to be a link to nextpage.php
$address = "whatever";
$telephone = "whatever";
$type = "whatever";
I have tried:
echo "<table><td><a href="nextpage.php">$companyname</a></td></table>" but it does not seem to work.
Any ideas on how I can do this.
My database query has a limit of 30 and I would like to display 30 if possible.
thanks in advance.
Watch out how you use single and double marks:
Will Cause an error because you start your string with a " and yo have a " around your link.
This can be fixed by escaping the quote:
Or the way I would do it:
You don't have to escape the double quotes if the string is wrapped in single quotes. (Or visa versa) Also, you'll see that I parsed my variable with a period (You can't imbed variables into strings wrapped with single quotes). Either way will work for you.
Will Cause an error because you start your string with a " and yo have a " around your link.
Code: Select all
echo "<table><td><a href="nextpage.php">$companyname</a></td></table>";Code: Select all
//Notice the \ before the "
echo "<table><td><a href=\"nextpage.php\">$companyname</a></td></table>";Code: Select all
echo '<table><td><a href="nextpage.php">' . $companyname . '</a></td></table>';
Last edited by hawleyjr on Fri Aug 12, 2005 8:15 am, edited 2 times in total.
Hi Again.
Can anyone please give me a hint on how to display this for multiple records?
Thanks
Here is what I have upto now but I would like to display more than one record.
feyd | please post php code appropriately in
Can anyone please give me a hint on how to display this for multiple records?
Thanks
Here is what I have upto now but I would like to display more than one record.
Code: Select all
<?php
include_once("connect.php");
$sql = "SELECT DISTINCT companyname, description, address, phone, fax, type, postcode from companies WHERE companyname='$_REQUEST[form1]' ORDER BY postcode";
$result = mysql_query($sql)
or die ("Couldn't select $_REQUEST[form1]");
echo "
\n";
while ($line = mysql_fetch_array($result))
{
extract($line); // extracts all line into variables with same name as fields
}
echo "\n";
echo '<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<th width="6%" height="26" scope="col"><div align="left"></div></th>
<th width="59%" valign="top" scope="col"><div align="left"><a href="nextpage.php">' . $companyname . '</div></th>
<th width="35%" scope="col"><div align="left">$phone</div></th>
</tr>
<tr>
<th scope="row"><div align="left"></div></th>
<th valign="top" scope="row"><div align="left">$description</div></th>
<th scope="row"><div align="left"></div></th>
</tr>
<tr>
<th scope="row"><div align="left"></div></th>
<th valign="top" scope="row"><div align="left"></div></th>
<th scope="row"><div align="left"></div></th>
</tr>
</table>';
?>feyd | please post php code appropriately in
Code: Select all
tags.[/color]Thanks for that, It works fine but do you have any ideas why the fax and phone numbers are not printed?
Thanks.
Thanks.
Code: Select all
<?php
include_once("connect.php");
$sql = "SELECT DISTINCT companyname, address, phone, fax, type, postcode from companies WHERE companyname='$_REQUEST[form1]' ORDER BY postcode";
$result = mysql_query($sql)
or die ("Couldn't select $_REQUEST[form1]");
echo "
\n";
//-------------get each event type ------
while ($line = mysql_fetch_array($result))
{
extract($line);
echo '<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<th width="6%" height="26" scope="col"><div align="left"></div></th>
<th width="59%" valign="top" scope="col"><div align="left"><a href="nextpage.php">' . $companyname . '</div></th>
<th width="35%" scope="col"><div align="left"><?php echo $phone; ?></div></th>
</tr>
<tr>
<th scope="row"><div align="left"></div></th>
<th valign="top" scope="row"><div align="left"><?php echo $fax;?></div></th>
<th scope="row"><div align="left"></div></th>
</tr>
<tr>
<th scope="row"><div align="left"></div></th>
<th valign="top" scope="row"><div align="left"></div></th>
<th scope="row"><div align="left"></div></th>
</tr>
</table>'; // extracts all line into variables with same name as fields
}
?>- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
change:tonote the single quotes..
Code: Select all
<?php echo $phone; ?>Code: Select all
' . $phone . '