Results 1 to 9 of 9

Thread: DB Question

  1. #1
    Join Date
    Jan 2003
    Location
    IL, US
    Posts
    6

    Question DB Question

    HI,
    How do you do this:
    Connect to the DB and pull a specific row of information from it.
    But the row to pull from it has to be specified by the ?id= tag..
    So when you click the link "[FSK] - Operation Traffic" it should connect to the db and find the row with the Title field "[FSK] - Operation Traffic" and display all the information in that row. Then if you go back and click on the link called "Testing" then it should pull the row with the Title called "Testing" and display that information...
    If you know how to do this then please post it on here or email me...

  2. #2
    Join Date
    Jan 2003
    Posts
    3
    Well, which preprocessor/language are you using?

    If it's PHP then .....

    $cfg['server'] = "mysql server-name";
    $cfg['user'] = "db user";
    $cfg['db'] = "the database";

    $sql = mysql_connect($cfg['server'],$cfg['user'],$cfg['pass']);
    @mysql_select_db($cfg['db'],$sql) or die(mysql_error());

    $query = "SELECT * from your_table where id=$idtag";
    $result = mysql_query($query);

    while ($row = mysql_fetch_array($result)) {
    echo "$row[id] or whatever";
    }

    if you use mypage.php?id=whatever
    you can extract the info from id with $id in mypage.php

    try doing a simple variable passing operation

  3. #3
    Join Date
    Dec 2002
    Location
    Cape Town, South Africa
    Posts
    75
    In PHP, I'd use $_GET['id'] instead of $id (or $_GET['idtag'] instead of $idtag), as new versions of PHP come with register globals off, for security reasons. Even on old installations, it's a good habit to get into. You can read more about it at http://www.php.net/manual/en/securit...terglobals.php

  4. #4
    Join Date
    Jan 2003
    Location
    IL, US
    Posts
    6
    Thanks for your replies...
    I use php programming...

    Ok with that code how do you go about displaying the retrived information later in that page? I need to be able to pull the information then in the desiered columns (tables and tds) display it...

    PHP Code:
    <Table width="70%" cellspacing="1" cellpadding="1" valign="top" align="center" border="2" bordercolor="#FF0000">
    <tr><td align="center">Title:</td>
    <td width="16.7%" align="center"><FONT SIZE=1pt><b><?="$title"?></td>
    <tr></tr>
    <td align="center" width="16%">Author:</td>
    <td width="16.7%" align="center"><FONT SIZE=1pt><b><?php while (list(,$a) = each ($author)){ echo "$a[0] $a[1]<br>\n"; } ?></td>
    <tr></tr>
    <td align="center">Release:</td>
    <td width="16.7%" align="center"><FONT SIZE=1pt><b><?php while (list(,$r) = each ($release)){ echo "$r[0] $r[1]<br>\n"; } ?></td>
    <tr></tr>
    <td align="center">Grade:</td>
    <td width="16.7%" align="center"><FONT SIZE=1pt><b><?php while (list(,$g) = each ($grade)){ echo "$g[0] $g[1]<br>\n"; } ?></td>
    <tr></tr>
    <td align="center">File Size:</td>
    <td width="16.7%" align="center"><FONT SIZE=1pt><b><?php while (list(,$er) = each ($ererer)){ echo "$er[0] $er[1]<br>\n"; } ?></td>
    <tr></tr>
    <td align="center">D/L:</td>
    <td width="16.7%" align="center"><FONT SIZE=1pt><b><?php while (list(,$s) = each ($sfilename)){ echo "$s[0] $s[1]<br>\n"; } ?></td>
    </TABLE>
    So I need to be able to connect, pull the specifed info (by $idtag or $id) and then put it in those fields later on... I was using:

    PHP Code:
    <?php

    $title 
    SelectQuery ("Downloads""Title");

    if (!
    is_array($title)){

    echo 
    "Error: $title<br>\n";

    exit;

    }
    ?>
    to put the pulled info into a variable and then using:

    PHP Code:
    <?php while (list(,$t) = each ($title)){ echo "$t[0] $t[1]<br>\n"; } ?>
    to display it... But when I used that way it wouldn't display only the info from the $id or $idtag... If you need to see exactly how I need it to work ask in a post and I'll give you a link...
    Thanks in advance for any help...

  5. #5
    Join Date
    Jan 2003
    Location
    IL, US
    Posts
    6
    Also, another question is:
    On the page that would have the links to retrive the information from the db and display it in the fileinfo template page, how do you make it so it displays only 15 at a time but so it auto generates the code for last page, next page, and page jump (1,2,3,4,5,6), and also how to make it be able so you click on lets say the column name (Title) and it would re-organize the results by title and same with the other fields...
    Right now for that I have it display the results 0-15 then I made links so you can see the other results... I use both the (?id=15&idtag=30) and it retrieves that to display the results with the limit, although I would just make the links manually for the re-organizing but it doesn't seem like you can read more then the ?id=...&idtag=...? Any help is appreciated......

  6. #6
    Join Date
    Jan 2003
    Location
    IL, US
    Posts
    6
    Well, I manually did the code for the jump to page (1,2,3,4,5,6) and the organize by coulumn by clicking on the Title of the column... I still can't figure out the code for the next and back links, though... If you know how to do this please post.
    Thanks in advance...

  7. #7
    Join Date
    Jan 2003
    Location
    IL, US
    Posts
    6
    Ok, I figured out how to display the results where I need them.. Now the only thing I haven't got figured out and fixed is the back and next pages (I would rather use the auto generated one's if possible) ... If you know how to do that please post...
    Thanks for all of your help so far...

  8. #8
    Join Date
    Jan 2003
    Location
    IL, US
    Posts
    6
    I figured out the next and back links by using if statments... The only thing left would to have it automatically add those links but that doesn't matter that much... So if you know how and don't mind posting I'd appreciate it but how I have it set-up right now will work efficentally enough..
    Again, thank you for all of your help...

  9. #9
    Join Date
    Dec 2002
    Location
    Cape Town, South Africa
    Posts
    75
    You seem to have got quite far yourself! Maybe this script will help if you haven't got there already: http://www.phpbuilder.com/columns/rod20000221.php3

Posting Permissions

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