• Resolved kcb212003

    (@kcb212003)


    I am trying to echo some data from a separate DB I have by using the title of the posts and can not figure it out, unless I manually put the post title in the code below. (I mainly need help with the [id=’….’] and if I put <?php the_title(); ?> in the id= I get an error)

    <?php $t_title = $_GET[‘the_title()’]; ?>
    <?php
    $con = mysql_connect(“localhost”,”********”,”********”);
    if (!$con)
    {
    die(‘Could not connect: ‘ . mysql_error());
    }
    mysql_select_db(“********”, $con);
    $result = mysql_query(“SELECT * FROM products WHERE id=’$t_title'”);
    echo “<table border=’1′>
    <tr>
    <th>F</th>
    <th>L</th>
    </tr>”;
    while($row = mysql_fetch_array($result))
    {
    echo “<tr>”;
    echo “<td>” . $row[‘size’] . “</td>”;
    echo “<td>” . $row[‘description’] . “</td>”;
    echo “</tr>”;
    }
    echo “</table>”;
    mysql_close($con);
    ?>

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter kcb212003

    (@kcb212003)

    or is there an other way to pull data from a different SQL database by using the post tile? something like <?php the_title(); ?> and it looks through the table for that title-id and echos the appropriate column (like description etc..)

    Thread Starter kcb212003

    (@kcb212003)

    SOLVED!!!

    I should have seen it. Fix code is below if anyone needs it…

    <?php
    $t_title=get_the_title();
    $con = mysql_connect(“localhost”,”********”,”********”);
    if (!$con)
    {
    die(‘Could not connect: ‘ . mysql_error());
    }
    mysql_select_db(“********”, $con);
    $result = mysql_query(“SELECT * FROM ******* WHERE *******=’$t_title'”);
    echo “<table border=’1′>
    <tr>
    <th>F</th>
    <th>L</th>
    </tr>”;
    while($row = mysql_fetch_array($result))
    {
    echo “<tr>”;
    echo “<td>” . $row[‘******’] . “</td>”;
    echo “<td>” . $row[‘******’] . “</td>”;
    echo “</tr>”;
    }
    echo “</table>”;
    mysql_close($con);
    ?>

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Getting Post Tile For SQL’ is closed to new replies.