$结果= mysql_query() [英] $result = mysql_query()

查看:82
本文介绍了$结果= mysql_query()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是php/mysql的新手,所以如果我做的过时了,请在这里原谅我的知识水平,并随时将我引向一个更好的方向.

I am brand new to php/mysql, so please excuse my level of knowledge here, and feel free to direct me in a better direction, if what I am doing is out of date.

我正在从数据库中提取信息以填写登录页面.布局以左侧的图片和右侧的标题开始.在这里,我使用查询来检索页面标题文本:

I am pulling in information from a database to fill in a landing page. The layout starts with an image on the left and a headline to the right. Here, I am using the query to retrieve a page headline text:

<?php
$result = mysql_query("SELECT banner_headline FROM low_engagement WHERE thread_segment = 'a3'", $connection);
if(!$result) {
    die("Database query failed: " . mysql_error());
}
while ($row = mysql_fetch_array($result)) {
    echo $row["banner_headline"];
}
?>

这很好用,但现在我想在 img alt 标签内复制该标题文本.在alt标记内复制此查询信息的最佳方法是什么?我可以使用任何简短的代码吗?还是仅将代码复制到alt标记中并运行两次就更好了?

This works great, but now I want to duplicate that headline text inside the img alt tag. What is the best way to duplicate this queries information inside the alt tag? Is there any abbreviated code I can use for this, or is it better to just copy this code inside the alt tag and run it twice?

感谢您的见解!

推荐答案

正如评论所说,您正在使用不推荐使用的函数,但是要回答您的问题,您应该声明一个变量,以在从数据库,以便您可以随时使用它.

You are, as the comment says, using deprecated functions, but to answer your question, you should declare a variable to hold the value once your retrieve it from the database so that you can use it whenever your want.

<?php
$result = mysql_query("SELECT banner_headline FROM low_engagement WHERE thread_segment = 'a3'", $connection);
if(!$result) {
    die("Database query failed: " . mysql_error());
}

$bannerHeadline = "";

while ($row = mysql_fetch_array($result)) {
    $bannerHeadline = $row["banner_headline"];
}

echo $bannerHeadline; //use this wherever you want

?>

这篇关于$结果= mysql_query()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆