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!
I have a script which displays my mysql database records in two alternate coloured rows. I have a primary key called "asset" which is coloured red. I need this be a link which posts to another php script called viewall.php. Here is the view.php script. I have *** the part that I need to link.
<?php
//The connection part missed out
// The database select part
$query = "SELECT * FROM dedicated order by type";
$result = mysql_query($query) or die ("Query failed");
//the number of rows part
$numofrows = mysql_num_rows($result);
echo "<TABLE BORDER=\"0\" table width=\"100%\">\n";
echo "<TR bgcolor=\"#cccccc\"><TD font colour=\"red\"><b>Asset</b></TD><TD><b>Title</b></TD><TD><b>Customer</b></TD><TD><b>Type</b></TD><TD><b>IP address</b></TD></TR>\n";
for($i = 0; $i < $numofrows; $i++) {
$row = mysql_fetch_array($result); //get a row from our result set
if($i % 2) { //this means if there is a remainder
echo "<TR bgcolor=\"#ffff99\">\n";
} else { //if there isn't a remainder we will do the else
echo "<TR bgcolor=\"#ffffcc\">\n";
}
[b]************** THIS PART BELOW ".$row['asset']." This needs to link through to another page however I do not know how to do this. please help ****************[/b]
echo "<TD><font color=\"red\"><b>".$row['asset']."</b></font></TD><TD><font size=\"2\">".$row['title']."</TD><TD><font size=\"2\">".$row['customer']."</TD><TD><font size=\"2\">".$row['type']."</TD><TD><font size=\"2\">".$row['IP']."</TD>\n";
echo "</TR>\n";
}
//now let's close the table and be done with it
echo "</TABLE>\n";
?>
first of all you will probably get a message from one of the mod's for not using the php tags to hightligh your code. little button under subject that says PHP on it.
you need to put a hyper link around what you want the user to click on to go to the next page. like
The asset number does not display as a link, however the name, i.e server123 is display as the link and has moved under the asset heading. Also the IP address has dissapeared. I am not sure whether this has something to do with my $row variable..
$result = mysql_query($query) or die ("Query failed");
//let's get the number of rows in our result so we can use it in a for loop
$numofrows = mysql_num_rows($result);
echo "<TABLE BORDER=\"0\" table width=\"100%\">\n";
echo "<TR bgcolor=\"#cccccc\"><TD font colour=\"red\"><b>Asset</b></TD><TD><b>Title</b></TD><TD><b>Customer</b></TD><TD><b>Type</b></TD><TD><b>IP address</b></TD></TR>\n";
for($i = 0; $i < $numofrows; $i++) {
$row = mysql_fetch_array($result); //get a row from our result set
if($i % 2) { //this means if there is a remainder
echo "<TR bgcolor=\"#ffff99\">\n";
} else { //if there isn't a remainder we will do the else
echo "<TR bgcolor=\"#ffffcc\">\n";
}
echo "<TD><font color=\"red\"><b><a href=\"viewall.php?varl=".$row['asset']."".$row['asset']."</a></b></font></TD><TD><font size=\"2\">".$row['title']."</TD><TD><font size=\"2\">".$row['customer']."</TD><TD><font size=\"2\">".$row['type']."</TD><TD><font size=\"2\">".$row['IP']."</TD>\n";
echo "</TR>\n";
}
//now let's close the table and be done with it echo "<a href=\"other.php?var1=".$var1."\">link</a>";
echo "</TABLE>\n";
at this point you will probablly have to do a view source and see how you table is structured to make sure you have all the corrct <tr><td></td></tr> in the right place.
we will about the table layout after but lets get the code going
you have to put in the final > after <a href=""
That will hopefully solve some issues.