Click to See Complete Forum and Search --> : Adding a Query string to this code...


teege84
06-14-2007, 11:51 AM
THis probably sounds simple however being totally new to this its beyond me!

I have the following code to display the results of a SQL table into columns however I now need to add a query string to the displayed data - where would i add the link code? Cheers!

<?php
$i = 1;
while ($row=mysql_fetch_assoc($result)) {
echo '<td>'.$row['name'].'</td>';
$i = $i + 1; //add 1 to $i
if ($i == 5) {
echo '</tr><tr width="563" bgcolor="#CCCCFF">';
$i = 1;
} }
echo '</tr></table>'
?>

callumd
06-14-2007, 12:53 PM
Hi Teege84,

Is that piece of code your entire script? Because if you want to get data from a database, you need to use functions like mysql_connect(), mysql_query(), etc.

Or do you mean you just want to display your SQL query somewhere on the page?

teege84
06-14-2007, 03:35 PM
Hi, below is the full code not including the connection to the database:

$query = "select * from TOWN
order by name";

$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();
?>
<table width="100" border="0" align="center" cellpadding="10" cellspacing="1" bgcolor="#336699">
<tr width="563" bgcolor="#CCCCFF">
<?php
$i = 1;
while ($row=mysql_fetch_assoc($result)) {
echo '<td>'.$row['name'].'</td>';

$i = $i + 1;
if ($i == 5) {
echo '</tr><tr width="563" bgcolor="#CCCCFF">';
$i = 1;
}
}
echo '</tr></table>'
?>

The query string i want to add is like this:

<a href="http://www.XXXXXXXXX.com/XXXXXX.php?id=<? echo"$name";?>"><? echo"$name";?></a>

Hope this makes sense

william232
06-15-2007, 11:04 PM
Yea here try this code


<?php
$query = "select * from TOWN
order by name";

$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();
?>
<table width="100" border="0" align="center" cellpadding="10" cellspacing="1" bgcolor="#336699">
<tr width="563" bgcolor="#CCCCFF">
<?php
$i = 1;
while ($row=mysql_fetch_assoc($result))
{echo "<td><a href=\"index.php?id=".$row['mid'].">".$row['name']."</td>";

$i = $i + 1;
if ($i == 5)
{
echo '</tr><tr width="563" bgcolor="#CCCCFF">';
$i = 1;
}
}
echo '</tr></table>';
?>


Please rename index.php to the name of your file