简体   繁体   English

如何从SQL提取数据字段

[英]How to extract field of data from SQL

I am a hobbyist programmer and stuck with php and sql 我是一个业余程序员,并且一直使用php和sql

I have a website where I hope to allow different users to list their domains and websites for sale. 我有一个网站,希望允许不同的用户列出要出售的域名和网站。 I have an SQL database with the fields: id , domain and price . 我有一个SQL数据库,其中包含以下字段: iddomainprice Now I added a column of data where "namer" is the field name. 现在,我添加了一列数据,其中“ namer”是字段名称。

I am trying to extract the field "namer" so it appears on the website but it won't work. 我正在尝试提取字段“ namer”,使其出现在网站上,但将无法正常工作。

The problem starts at // PROBLEM AREA in the code and after that div it's okay. 问题始于// PROBLEM AREA代码中的// PROBLEM AREA ,然后经过该div就可以了。

<div class="domain_list_item_main_linear" style="font-family: 'Open Sans', Arial; width:98%;">

    <div style="width:33%;float:left;">
        <a href="<?php /*?><?php echo ConfigPeer::GetValue('website_folder'); ?>
        <?php echo $domain->getCleanName(); ?><?php */?>https://www.afternic.com/domain/<?php echo urlencode($domain); ?>" class="moLPdomain" target="_blank">
        <?php echo html_entity_decode($domain->getDivTipNameLinear(), ENT_QUOTES); ?></a>

        <?php if(!$domain->getIsSold()): ?>
    </div>

    <div class="moLPprice" style="width:22%;float:left;margin-left:0px;">

        <?php 

        // PROBLEM AREA
            $eventid = $_GET['id'];
            $namer = $_GET['namer'];
            $result = mysql_query("SELECT $namer FROM `domain` WHERE `id` = '$eventid' ");
            $row = mysql_fetch_array($result);
            echo $row[$namer];      
        ?>  </div>

The problem is where you are using $namer . 问题出在使用$namer

The section after SELECT should contain the name of a column which contains the data you are trying to extract. SELECT之后的部分应包含一名称,其中包含您要提取的数据。 Looking at your code, $namer isn't the name of the column, but some data that you are trying to match. 查看您的代码, $namer不是列的名称,而是您要匹配的某些数据。

So the structure of the SQL should be like this: 因此,SQL的结构应如下所示:

SELECT column_name FROM table_name WHERE a_column_name = a_val;

I suggest you take a look at SQL SELECT statements, w3school's is a good place to start: 我建议您看一下SQL SELECT语句,w3school是一个不错的起点:

http://www.w3schools.com/php/php_mysql_select.asp http://www.w3schools.com/php/php_mysql_select.asp

Edit: 编辑:

You're SQL should look like this: 您的SQL应该看起来像这样:

SELECT namer FROM domain WHERE id = $eventid;

If you want to get the 'namer' of the domain with that ID. 如果要获取具有该ID的域的“名称”。

You're variable $namer must be storing any of the following words for your query to run: 您是变量$namer必须存储以下任何单词才能运行查询:

id
domain
price

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM