WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Getting Post Tile For SQL (3 posts)

  1. kcb212003
    Member
    Posted 1 year ago #

    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);
    ?>

  2. kcb212003
    Member
    Posted 1 year ago #

    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..)

  3. kcb212003
    Member
    Posted 1 year ago #

    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);
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic