Php 无法从数据库获取链接的URL

Php 无法从数据库获取链接的URL,php,mysql,html,Php,Mysql,Html,我正在做一个项目,并将永远感谢帮助我的URl的链接。我试着四处看看,但没有结果。我有一个数据库(4列)。最后一个链接(link1)应该链接到具有指定URL的视频。当表格出现时,URL不可单击(有没有办法简化此操作,比如“单击我”?)。这是我的密码。我还附上了一张桌子的图片。这真是伤了我的脑筋,谢谢 <?php $con = mysqli_connect("localhost","feedb933_charles","pass100","feedb933_test"); /

我正在做一个项目,并将永远感谢帮助我的URl的链接。我试着四处看看,但没有结果。我有一个数据库(4列)。最后一个链接(link1)应该链接到具有指定URL的视频。当表格出现时,URL不可单击(有没有办法简化此操作,比如“单击我”?)。这是我的密码。我还附上了一张桌子的图片。这真是伤了我的脑筋,谢谢

<?php
    $con = mysqli_connect("localhost","feedb933_charles","pass100","feedb933_test");

    // Check connection
    if (mysqli_connect_errno())
    {
        echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }

    $sql = "SELECT * FROM videos";
    $result = mysqli_query($con, $sql); 

    echo "<table>"; 
    echo "<tr> 
    <th>topic1</th> 
    <th>subject1</th> 
    <th>link1</th> 
    </tr>"; 
    while( $row = mysqli_fetch_array( $result)) { 
        $topic1 = $row["topic1"]; 
        $subject1 = $row["subject1"]; 
        $link1 = $row["link1"]; 

        echo "<tr> 
        <td>$topic1</td>
        <td>$subject1</td>
        <td>$link1</td>
        </tr>";
    }
    echo "</table>";
    mysqli_close($con);
?>

试试这个:

<?php
    $sql = "SELECT * FROM `videos`";
    $result = mysqli_query($con, $sql);
?> 
<table>
<?php 
   while($row = mysqli_fetch_assoc( $result)) { 
 ?>       
    <tr> 
        <td><?php echo $row['topic1'];?></td>
        <td><?Php echo $row['subject1'];?></td>
        <td><a href="<?php echo $row['link1']; ?>" target="_blank">Click me</td>
  </tr>
  <?php } ?>
<table>

我添加了
target
属性以在新窗口中打开链接。

我查看了您的代码,发现了几个错误

更改
$con=mysqli_connect(“本地主机”、“feedb933_测试”、“pass100”、“feedb933_测试”)
$con=new mysqli(“本地主机”、“feedb933\u测试”、“pass100”、“feedb933\u测试”)

然后将
if(mysqli\u connect\u errno())
更改为
if(mysqli\u connect\u error()){

然后改变

$sql = "SELECT * FROM videos";

或者如果要选择一行

$differentvalue = ""; // value to run
$sql = "SELECT topic1, subject1, link1 FROM videos WHERE difvalue = ?";
difvalue
是与其他值不同的值,因此php代码知道要获取什么

使用stmt意味着没有sql注入

加:

然后在side
if(something){}else{in HERE}

(如果您有
其中diffvalue
)添加:

然后

加:

然后在
if(something){code}else{code}

加:

echo“主题1主题1链接1”;
foreach($列为$行=>$new){
$html='.$new['topic1'].';
$html.=''.$new['subject1'].';
$html.='.$new['link1'].';
echo$html;
}
回声“;
如果您仍然有问题,请转到列出的链接

希望这有帮助


<?php
$con=mysqli_connect("localhost","feedb933_charles","pass100","feedb933_test");

    // Check connection
    if (mysqli_connect_errno())
    {
        echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }

    $sql = "SELECT * FROM videos";
    $result = mysqli_query($con, $sql); 

    echo "<table>"; 
    echo "<tr> 
    <th>topic1</th> 
    <th>subject1</th> 
    <th>link1</th> 
    </tr>"; 
    while( $row = mysqli_fetch_array( $result)) { 
        $topic1 = $row["topic1"]; 
        $subject1 = $row["subject1"]; 
        $link1 = $row["link1"]; 

        echo "<tr> 
        <td>$topic1</td>
        <td>$subject1</td>
        <a href="'.$link.'"><td>$link1</td></a>
*//this href will give u the link as u asked. //be sure you store proper url. In case of exact video name saved in column thn can make the url for your web output. //ex:<a href="http://example.com/'.$link.'.extension">*

        </tr>";
    }
    echo "</table>";
    mysqli_close($con);
?>

Hi Mawia。谢谢,但它不起作用。link1列中的所有数据都消失了。看这里,我更新了我的答案。检查一下。你在问题中只显示了三列。谢谢你Mawia!!它起作用了。你是个明星。一开始它不起作用(但可能是缓存问题).有趣的是,我也尝试了Do版本,但没有成功(没有出现任何问题)。令人惊讶的是,整个代码也小得多。谢谢阿加恩塔克斯提供的目标信息,很好的一个。谢谢尼古拉斯的快速回复。我会看看这个,但现在表中的链接正在工作。好的。我花了一段时间把这个答案放在一起,但这个代码对我有效。谢谢德拉维亚的快速回复
$differentvalue = ""; // value to run
$sql = "SELECT topic1, subject1, link1 FROM videos WHERE difvalue = ?";
$stmt = $con->stmt_init();
if (!$stmt->prepare($sql))
{
    print "Failed to prepare statement\n";
}
else
{

}
$stmt->bind_param("s", $differentvalue); // $stmt->bind_param("s", $differentvalue); if text, $stmt->bind_param("i", $differentvalue); if integer
$stmt->execute();
$list = $stmt->fetchAll();
echo "<table><tr><th>topic1</th><th>subject1</th><th>link1</th></tr><tr>";

foreach ($list as $row => $new) {
    $html = '<td>' . $new['topic1'] . '</td>';
    $html .= '<td>' . $new['subject1'] . '</td>';
    $html .= '<td>' . $new['link1'] . '</td>';
    echo $html;
}

echo "</tr></table>";
<?php
$con=mysqli_connect("localhost","feedb933_charles","pass100","feedb933_test");

    // Check connection
    if (mysqli_connect_errno())
    {
        echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }

    $sql = "SELECT * FROM videos";
    $result = mysqli_query($con, $sql); 

    echo "<table>"; 
    echo "<tr> 
    <th>topic1</th> 
    <th>subject1</th> 
    <th>link1</th> 
    </tr>"; 
    while( $row = mysqli_fetch_array( $result)) { 
        $topic1 = $row["topic1"]; 
        $subject1 = $row["subject1"]; 
        $link1 = $row["link1"]; 

        echo "<tr> 
        <td>$topic1</td>
        <td>$subject1</td>
        <a href="'.$link.'"><td>$link1</td></a>
*//this href will give u the link as u asked. //be sure you store proper url. In case of exact video name saved in column thn can make the url for your web output. //ex:<a href="http://example.com/'.$link.'.extension">*

        </tr>";
    }
    echo "</table>";
    mysqli_close($con);
?>