Jump to content

Simple PHP help


arrond

Recommended Posts

Hi all,

 

I simply want a page to display a list of links that are stored in a SQL database. The database has 3 fields ID, URL and Title. I currently have the page displaying a list of the Titles. Example:

 

PNY GeForce 8800 GTX Review

8800 GTX review - TechSpot

GeForce 8800 GTS & GTX review

 

Now i want the corresponding URLs to be used as the hyperlinks for the page Titles. I have nearly got this working except each of the Titles are using the first URL as their hyperlink. I created a test page for you to see.

 

http://students.comp.glam.ac.uk/04033299/blg/display%20links.php

 

In dreamweaver ive got the following php code:

 

<?php do { ?>

<tr>

<td><?php echo $row_DisplayLinks['ID']; ?></td>

<td><?php echo $row_DisplayLinks['URL']; ?></td>

<td><a href="<?php echo $row_Test['URL']; ?>"><?php echo $row_DisplayLinks['Title']; ?></a></td>

</tr>

<?php } while ($row_DisplayLinks = mysql_fetch_assoc($DisplayLinks)); ?>

 

I think this needs to be changed: <?php echo $row_Test['URL']; ?>

 

By the way this is for my dissertation so any help will be very appreciated 

Thanks in advance

Link to comment
https://forums.phpfreaks.com/topic/45545-simple-php-help/
Share on other sites

Use a while() not a do while().

 

<?php
while ($row_DisplayLinks = mysql_fetch_assoc($DisplayLinks)) {
?>
<tr>
<td><?php echo $row_DisplayLinks['ID']; ?></td>
<td><?php echo $row_DisplayLinks['URL']; ?></td>
<td><a href="<?php echo $row_Test['URL']; ?>"><?php echo $row_DisplayLinks['Title']; ?></a></td>
</tr>
<?php
}
?>

Link to comment
https://forums.phpfreaks.com/topic/45545-simple-php-help/#findComment-221110
Share on other sites

It didnt work but thanks for the reply.  I used this instead:

 

<?php

               

                $result = mysql_query("SELECT * FROM tbllinks ORDER BY ID ASC")

                or die(mysql_error()); 

                while($row = mysql_fetch_array($result))

               

                    {

                        echo "<a href=" . $row['URL'] . ">" . $row['Title'] . "</a>";

                        echo "</br>";

                    }

                ?>

 

but would have prefered to keep it in the table.  Thanks again.

Link to comment
https://forums.phpfreaks.com/topic/45545-simple-php-help/#findComment-221131
Share on other sites

Try this to keep within the table,

 

$result = mysql_query("SELECT * FROM tbllinks ORDER BY ID ASC")

                or die(mysql_error()); 

                while($row = mysql_fetch_array($result))

               

                    {

$gotid = $row_DisplayLinks['ID'];

$goturl = $row_DisplayLinks['URL'];

$gottitle = $row_DisplayLinks['Title'];

 

$display .="

<tr>

<td>$gotid</td>

<td>$goturl</td>

<td><a href=\"$goturl\">$gottitle</a></td>

</tr>

";

}

 

<?php echo "$display"; ?>

 

Link to comment
https://forums.phpfreaks.com/topic/45545-simple-php-help/#findComment-221155
Share on other sites

That didnt work either but thanks again. 

 

I have modified the page to show how i want it to look.  Im using a dynamic table in dreamweaver to do it this way, just cant get the links to work  :-[

 

http://students.comp.glam.ac.uk/04033299/blg/display%20links.php

 

any more help will be great, cheers.

Link to comment
https://forums.phpfreaks.com/topic/45545-simple-php-help/#findComment-221180
Share on other sites

OMG i got it working.  I been playing about with two recordsets in dreamweaver.  The problem was in this line:

 

<td><a href="<?php echo $row_Test['URL']; ?>"><?php echo $row_DisplayLinks['Title']; ?></a></td>

 

The URL row is looking at the 'Test' recordset where the Title row is looking at the 'DisplayLinks' recordset.  Now both on DisplayLinks recordset its working fine.  Stupid me  ;D

 

Thanks alot guys.

Link to comment
https://forums.phpfreaks.com/topic/45545-simple-php-help/#findComment-221201
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.