Posting this as a link to other script

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
User avatar
mhouldridge
Forum Contributor
Posts: 267
Joined: Wed Jan 26, 2005 5:13 am

Posting this as a link to other script

Post 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
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

Post 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
User avatar
mhouldridge
Forum Contributor
Posts: 267
Joined: Wed Jan 26, 2005 5:13 am

Post 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!
User avatar
mhouldridge
Forum Contributor
Posts: 267
Joined: Wed Jan 26, 2005 5:13 am

Post 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";
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

Post 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.
User avatar
mhouldridge
Forum Contributor
Posts: 267
Joined: Wed Jan 26, 2005 5:13 am

Post by mhouldridge »

Hmm...

Still doing the same.
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

Post 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.
User avatar
mhouldridge
Forum Contributor
Posts: 267
Joined: Wed Jan 26, 2005 5:13 am

Post 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.
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

Post 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.
User avatar
mhouldridge
Forum Contributor
Posts: 267
Joined: Wed Jan 26, 2005 5:13 am

Post 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?
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

Post 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?
Post Reply