Jump to content

Geting data and making a link


strago

Recommended Posts

I got the script geting the data. How would I add an if to it, where  if it's the title, it'll show up as

 

<A HREF="http://www.domain.com/info/**ID**.html">**Title**</a>

 

I think the part that needs messed with is...

mysql_data_seek ($result, 0);
while ($row = mysql_fetch_assoc ($result)) {
    echo "<TR>\n";
    foreach ($row as $column) {
        echo "<TD>$column</TD>\n";
    }
    echo "</TR>\n";
}
echo "</TABLE>\n";

The complete script...

/* construct and run our query */
if (isset($_GET["page"])) { $page  = $_GET["page"]; } else { $page=1; };
$start_from = ($page-1) * 50;
$query = "SELECT Title,Id,URL,Description FROM XXXXXX ORDER BY $order ASC LIMIT $start_from, 50";
$result = mysql_query ($query);

/* make sure data was retrieved */
$numrows = mysql_num_rows($result);
if ($numrows == 0) {
    echo "No data to display!";
    exit;
}

/* now grab the first row and start the table */
$row = mysql_fetch_assoc ($result);
echo "<TABLE border=1>\n";
echo "<TR>\n";
foreach ($row as $heading=>$column)
{
    /* check if the heading is in our allowed_order
     * array. If it is, hyperlink it so that we can
     * order by this column */
    echo "<TD><b>";
    if (in_array ($heading, $allowed_order)) {
        echo "<a href=\"{$_SERVER['PHP_SELF']}?order=$heading\">$heading</a>";
    } else {
        echo $heading;
    }                
    echo "</b></TD>\n";
}
echo "</TR>\n";

/* reset the $result set back to the first row and
 * display the data */
mysql_data_seek ($result, 0);
while ($row = mysql_fetch_assoc ($result)) {
    echo "<TR>\n";
    foreach ($row as $column) {
        echo "<TD>$column</TD>\n";
    }
    echo "</TR>\n";
}
echo "</TABLE>\n";
Edited by strago
Link to comment
Share on other sites

Since you are looping through information in your database that is associated with the link I would add the links or page name into your database in the same row as the title. Therefore, you would echo out the title as you do and also anchor text around it. Inside that anchor text you would echo out the page that is associated with the title to link to that page.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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