$结果= mysql

编程入门 行业动态 更新时间:2024-10-09 06:27:00
本文介绍了$结果= 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

本文发布于:2023-06-02 01:31:18,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/431012.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:mysql

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!