Page 1 of 1

Posting this as a link to other script

Posted: Thu May 12, 2005 4:41 am
by mhouldridge
Hi,

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.

Code: Select all

<?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";
?>
Any help would be greatly appreciated folks!

regards,
Mark[/b]

Jcart | Please review :arrow: Posting Code in the Forums

Posted: Thu May 12, 2005 5:46 am
by phpScott
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

Code: Select all

echo "<TD><font color=\"red\"><b><a href='nextPage.php?asset=".$row['asset']."".$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";
then on nextPage.php you will need to do something like

Code: Select all

if(isset($_GET['asset']))
  //what ever you want to do with asset.
hopefully that helps

Posted: Thu May 12, 2005 5:55 am
by mhouldridge
Thanks, that is kinda working now...

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..

Hmm....


Thanks for your help so far!

Posted: Thu May 12, 2005 5:57 am
by mhouldridge
Sorry,

The ip address is showing, however everything has moved left accross one.

Here is my code;

Code: Select all

$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";

Posted: Thu May 12, 2005 6:22 am
by phpScott
sorry forgot to put the closing > around the <a href >

Code: Select all

echo "<TD><font color=\"red\"><b><a href='nextPage.php?asset=".$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";
try it agian.

Posted: Thu May 12, 2005 7:11 am
by mhouldridge
Hmm...

Still doing the same.

Posted: Thu May 12, 2005 8:11 am
by phpScott
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.

Posted: Thu May 12, 2005 8:17 am
by mhouldridge
Yes, it looks strange,

The hmtl code shows the asset number however it isnt visible;

<TD><font color="red"><b><a href="viewall2.php?varl=000009</a></b></font></TD><TD><font size="2">NETSERVER2416</TD><TD><font size="2">Britannia Movers</TD><TD><font size="2">Dedicated Server</TD><TD><font size="2">10.10.10.10</TD>
</TR>

Above you can see the 000009 asset number.... argh!.

I dunno... im confused.

Posted: Thu May 12, 2005 9:03 am
by phpScott
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.

Code: Select all

echo &quote;<TD><font color=\&quote;red\&quote;><b><a href='viewall2.php?varl=&quote;.$row&#1111;'asset'].&quote;>&quote;.$row&#1111;'asset'].&quote;</a></b></font></TD><TD><font size=\&quote;2\&quote;>&quote;.$row&#1111;'title'].&quote;</TD><TD><font size=\&quote;2\&quote;>&quote;.$row&#1111;'customer'].&quote;</TD><TD><font size=\&quote;2\&quote;>&quote;.$row&#1111;'type'].&quote;</TD><TD><font size=\&quote;2\&quote;>&quote;.$row&#1111;'IP'].&quote;</TD>\n&quote;;
this line which I posted before into your code where you are creating the row.

since asset is both going to be the link and what is clicked we will be able to compare the numbers to see what is happening.

Posted: Thu May 12, 2005 9:46 am
by mhouldridge
Yes,

That shows the asset links correctly now, however again some errors...

The bottom record always shows;

<a href='viewall2.php?varl=000001000001

Any thoughts?

Posted: Thu May 12, 2005 10:46 am
by phpScott
is that just in the <a href> or is it also the link bit.

What is the last record in that table?
Check in phpMyAdmin or what ever you use to view your db.

What are you expecting?