English 中文(简体)
PHP MYSQL同时改变外地名称
原标题:PHP MYSQL while change field name each time
  • 时间:2011-02-23 21:46:01
  •  标签:
  • php
  • mysql

我有一个数据库储存人员快速链接。 这是一个非常基本的快速链接存储方法。 数据库也这样做:

正式名称: __________________________ _____________ _____________ _____________ _____________ _____________ _____________ _____________ _____________ _____________ _____________ _____________ _____________ _____________ _____________ _____________ _____________ _____________ _____________ _____________ _____________ _____________ _____________ _____________ _____________ _____________ _____________ _____________ _____________ _____________ _____________ _____________

^ 直至10年。 我知道这是坏的,但这是一个不专业的网站。

我想把结果列入一个定案清单。 但是,我不知道如何每次改变人数(1url或2url)?

因此,我目前已经把这一点列入公共卫生和社会福利部。

$result = mysql_query(SELECT * FROM `links` WHERE `full_name`= $loggedin )or die (mysql_error());
   while($row = mysql_fetch_array($result)){
     echo  <li><a href=" ;
     echo $row[ 1url ];
     echo  "></a></li> ;            
   }

但我没有这样做! 我对我应该做的事情感到非常不安。 我想显示另一个<代码><li> with an <a> and thelink Plus name for each row found。

感谢! 请具体谈谈我,因为这是一个新的基础!

EDIT:

我也陷入另一个问题。 我使用了来自各国人民回答的守则,其中大多数工作。 然而, 如果一个领域为空白(用户只有6个快速链接),它仍显示一个<代码><li>。 现在,我看着这个问题的任何进展。

内容:

这里是行之有效的:

while($row = mysql_fetch_array($result)){

    for($i = 1; $i < 10; $i++) {

       if(!trim($row[$i .  url ])==  ) { 
         echo  <li><a href=" ;
         echo $row[$i .  url ];
         echo  "> ;
         echo $row[$i .  name ];
         echo  </a></li> ;
        } //end of didn t trim  

    }//end for for
}//end of while
最佳回答
$result = mysql_query("SELECT * FROM `links` WHERE `full_name`= $loggedin ")or die (mysql_error());
   while($row = mysql_fetch_array($result)){
     for($i = 1; $i < 10; $i++)
     {
         echo  <li><a href=" ;
         echo $row[$i .  url ];
         echo  "></a></li> ;
     }            
   }

你们知道,这只是粗略的。 我刚才会用三栏(可能用自动加固进行分类的4栏)加以执行,然后根据用户选择分行,逐行。 这消除了10个卢尔限制。

<><>Edit>/strong>

For your second question, have a look at the PHP empty function and break/continue the loop if the function returns true.

问题回答

更清洁,更方便地改变您的数据库设置。 你可以有两个表格:

<>strong>users

  • id: a unique ID for each user, probably an auto increment int of some sort
  • full_name: just as you ve used it in your table

<quick_links

  • id: quick link id, probably an auto increment int (or you could do a primary index on user_id+order)
  • user_id: the user ID to tell us who this quick_link belongs to
  • name: the name of the quick link
  • url: the url of the quick link
  • order: what order to show this link in

那么,你只能做这样的事情。

$userid_result = mysql_query(
    "SELECT `id` from `users` WHERE `full_name` = $loggedin;"
);
$row = mysql_fetch_row($userid_result);
$userid = $row[0];

$links_result = mysql_query(
    "SELECT * from `quick_links` WHERE `user_id` = $userid ORDER BY `order` ASC;"
);

while($quick_link = mysql_fetch_object($links_result))
{
    printf("<li><a href="%s">%s</a></li>", $quick_link->url, $quick_link->$name);
}

Of course you d need some error checking in there, but that gives you an idea.

You need to put some double quotes around your select statement:

$result = mysql_query("SELECT * FROM `links` WHERE `full_name`= $loggedin ") or die (mysql_error());
   while($row = mysql_fetch_array($result)){
     echo  <li><a href=" ;
     echo $row[ 1url ];
     echo  "></a></li> ;            
   }
while ($row = mysql_fetch_array($result))
{
  $full_name = array_shift($row);
  for ($i = 0; $i < 10; ++$i)
  {
    echo  <li><a href=  . htmlspecialchars(array_shift($row)) .  > ;
    echo array_shift($row);
    echo  </a></li> ;
  }
}

array_shift returns the first element from an array and removes it from the array at the same time. So the code above removes the full_name field from the record and then iterates over the rest of the record, removing and printing a URL and its corresponding name on each iteration.

rel=“nofollow”>htmlspecialchars 用于确保创建有效的<代码>a-tag。 视连接点的名称而定,还应在链接名称上加以使用。

页: 1

$result = mysql_query( "SELECT * FROM `links` WHERE `full_name`= $loggedin " )
             or die (mysql_error());

$i = 0;

while($row = mysql_fetch_array($result)){

     $attributeURL  = $i .  url ;
     $attributeName = $i++ .  name ;

     echo  <li> 
        .  <a href="  .  $row[ $attributeURL ] .  ">  .  $row[ $attributeName ] . </a> 
        .  </li> 
        ;            


}




相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签