SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    Apache Expert i_like_php's Avatar
    Join Date
    Nov 2001
    Location
    Dallas, Texas
    Posts
    1,342
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help With Adding Id's

    ok i have a descriptions of links stored in the mysql database just fine, but what i'm trying to do is add the id of the link to the end of link. like for example...

    http://blah/index.php?id=100

    ok heres the code i have so far what am i forgetting?

    PHP Code:
    <?php 
    $username 
    "php"
    $password "5"
    $hostname "localhost";     
    $dbc mysql_connect($hostname$username$password
        or die(
    "Unable to connect to MySQL"); 
    $selected mysql_select_db("test",$dbc
        or die(
    "Could not select database"); 
    //pulling the links from the database
    $sql_query "SELECT * FROM site_links WHERE cat like 'main'";
    //store the SQL query in the result variable
    $result mysql_query($sql_query);
    if(
    mysql_num_rows($result))
    {
    //output as long as there are still available fields
    while($row mysql_fetch_row($result))
    {
    echo (
    "{<a href=\"$row[2]\">&nbsp;$row[3]</a>}&nbsp;");
    }
    }
    //if no fields exist
    else
    {
    echo 
    "no values in the database";
    }
    mysql_close($dbc);
    ?>
    i love php

  2. #2
    SitePoint Enthusiast SlayMan's Avatar
    Join Date
    Oct 2004
    Location
    Germany/ Hamburg
    Posts
    89
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok guessing this is your link u want to add the id to:
    PHP Code:
    echo ("{<a href=\"$row[2]\">&nbsp;$row[3]</a>}&nbsp;"); 
    i would change it to:
    PHP Code:
    echo "<a href=\"".$row[2]."?id=".$row[1]"\">&nbsp;".$row[3]."</a>&nbsp;"/* Assuming $row[1] is ur id, u should get the point*/ 
    maybe i am not getting ur idea but this should do it.
    Sorry for breaking up bracketed structure i don't know about those brackets.
    SlayMan,
    Your friendly neighbourhood trainee and webmaster
    go, see for yourself @ http://www.alpupp.de

  3. #3
    Apache Expert i_like_php's Avatar
    Join Date
    Nov 2001
    Location
    Dallas, Texas
    Posts
    1,342
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i tried your idea and it didn't work, it said missing a t value or something like that.
    i love php

  4. #4
    SitePoint Wizard
    Join Date
    Aug 2004
    Location
    California
    Posts
    1,672
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    echo "<a href=\"".$row[2]."?id=".$row[1]."\">&nbsp;".$row[3]."</a>&nbsp;"
    or
    PHP Code:
    echo "<a href=\"{$row[2]}?id={$row[1]}\">&nbsp;{$row[3]}</a>&nbsp;"
    Last edited by arborint; Jan 19, 2005 at 22:51.

  5. #5
    SitePoint Addict trogdor1024's Avatar
    Join Date
    Oct 2004
    Location
    New Jersey
    Posts
    235
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What are the names of the fields in the database?

    PHP Code:
    <?
    //echo "{<a href=\"$row[2]\">&nbsp;$row[3]</a>}&nbsp;";
    echo '{<a href="' $row['fieldname2'] . '?id=' $row['fieldname1'] . '">&nbsp;' $row['fieldname3'] . '</a>}';
    ?>

  6. #6
    Apache Expert i_like_php's Avatar
    Join Date
    Nov 2001
    Location
    Dallas, Texas
    Posts
    1,342
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by trogdor1024
    What are the names of the fields in the database?

    PHP Code:
    <?
    //echo "{<a href=\"$row[2]\">&nbsp;$row[3]</a>}&nbsp;";
    echo '{<a href="' $row['fieldname2'] . '?id=' $row['fieldname1'] . '">&nbsp;' $row['fieldname3'] . '</a>}';
    ?>
    ok the names are ......

    1./photos/
    2.designs-online.php
    3./forum/
    4./server-status
    5.version.php
    6./designs/

    those are the links and they under the category main and the table name is site_links.
    i love php


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •