SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2000
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've got a database where i save logs from IRC channels.
    I have created a field called "name" for each log. And I know how to make the names into a link. But then I'm stuck, 'cause I don't know the easiest way to display the logs. One on each page that is. I mean, you click on the link and tadaa the log's displayed.
    To me it doesn't make any sense to manually code each page for the logs.
    So how's the way to make this as smooth as possible?
    //Magnus

  2. #2
    SitePoint Enthusiast
    Join Date
    Oct 2000
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Now I have figured out this...

    <?php

    $db=mysql_connect("localhost");
    mysql_select_db("indiepop2000",$db);

    $log_query = mysql_query("SELECT * FROM logs");
    while ($row = mysql_fetch_array($log_query))
    {
    $id=$row["ID"];
    $title=$row["namn"];
    $text=$row["text"];
    echo ("<a href=http://localhost/test.phpID=$id>$title</a>
    <br>
    ");
    }
    ?>

    the script is placed in the root dir on http://localhost
    and the links to all logs show up, but when I click on any of the links there's an url like http://localhost/test.php?ID=1 showed in the browsers adress win. and on the page the links are reloaded, not the log with an ID set to 1.
    I suppose I have to echo the $text var on the page loaded, how's that done?

  3. #3
    SitePoint Enthusiast
    Join Date
    Oct 2000
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Now this is really frustrating.

    Now I have 2 files

    the first one that lists all logs are named test.php
    and looks like this:

    <?php
    $db=mysql_connect("localhost");
    mysql_select_db("indiepop2000",$db);

    $logss_query = mysql_query("SELECT * FROM logs ORDER BY ID");

    while ($row = mysql_fetch_array($logs_query))
    {
    $id=$row["ID"];
    $title=$row["namn"];

    echo (<a href=http://localhost/indiepop2000/testar.php?ID=$id>$title</a>);
    }
    ?>

    Then I have the testar.php page

    <?php

    $db=mysql_connect("localhost");
    mysql_select_db("indiepop2000",$db);

    $sql="select * from logs where ID = '$id'";
    $result=MySQL_query($sql,$db);
    while($myrow=MySQL_fetch_array($result));
    {
    $logtext=$myrow["text"];
    echo "$logtext";
    }
    ?>

    I don't get any parse error neither a mysql error msg.
    And yes, I have checked for misspelling.
    But still the last page's totally blank.
    What am I doing wrong?

  4. #4
    SitePoint Zealot Atirez's Avatar
    Join Date
    Nov 2000
    Location
    England
    Posts
    173
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If i get what you are trying to do

    You could create a file which is set up to display one set of informaion or row onto a html file.

    So if you was to send the id number through a query. the recieving file could get the data from that row then display it.

    <?php
    // check for query
    if ($id){
    // Connect to database

    $dbcnx = @mysql_connect("database stuff");

    if (!$dbcnx) {
    echo( "&nbsp;<P>Unable to connect to the server at this time.</P>" );
    echo("<br></body></html>");
    exit();
    }

    // Select the database

    if (! @mysql_select_db("indiepop2000")){
    echo( "&nbsp;<P>Unable to locate the database.</P>" );
    echo("<br></body></html>");
    exit();
    }

    // Request the search

    $result = mysql_query("SELECT * FROM Logs WHERE ID LIKE '$id'");
    if (!$result) {
    echo("<br><P>Error performing query: " . mysql_error() . "</P><br>");
    echo("<br></body></html>");
    exit();
    }

    // Display results
    echo("<table align=\"center\" width=\"50%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">");

    while ( $row = mysql_fetch_array($result) ) {

    // In here use echo to write the table containing the results
    echo("<tr><td>results".$row[ID]."</td></tr>");}}

    And then after the results loop close the table and the file.

    echo("</table></body></html>");

    or you could use a template

    Hope this helps



    <Edited by Atirez on 12-13-2000 at 01:53 AM>

  5. #5
    SitePoint Enthusiast
    Join Date
    Oct 2000
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm.. there's still no data output =(

  6. #6
    SitePoint Enthusiast
    Join Date
    Oct 2000
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hahaaa... it's working just fine now )
    I made some adjustments in your script and yes =)
    I'm now feeling very euphoric. *ROTFLMAO*

    And I promise to you all that i will remember that ID is not the same as id


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
  •