Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP MYSQL while change field name each time
    text
    copied!<p>I have a database to store people's quick links. This is a very basic quick link storage method. The database looks like this:</p> <p>full_name | 1url | 1name | 2url | 2name | 3url |3 name | 4url |4name | 5url | 5name</p> <p>^This goes on until 10. I know this is a bad way, but this is for an unprofessional website.</p> <p>I will want to put the result into an ordered list. But I am unsure how to change the number (1url or 2url) each time?</p> <p>So currently I have it set up like this in PHP</p> <pre><code>$result = mysql_query(SELECT * FROM `links` WHERE `full_name`='$loggedin')or die (mysql_error()); while($row = mysql_fetch_array($result)){ echo '&lt;li&gt;&lt;a href="'; echo $row['1url']; echo '"&gt;&lt;/a&gt;&lt;/li&gt;'; } </code></pre> <p>But I am having no luck with that! I'm very unsure of what I should do. I want it to display another <code>&lt;li&gt;</code> with an <code>&lt;a&gt;</code> and the link plus name of the link for each row found.</p> <p>Thanks! Please be specific with me, as this is new ground! :D</p> <p>EDIT:</p> <p>I have also run into another problem. I have used code from peoples' answers and most of them work. However, If one of the fields is blank (so a user has only 6 quick links) it still shows an <code>&lt;li&gt;</code>. Now I can't see anyway round this issue. :/</p> <p>SOLUTION:</p> <p>Here is what works:</p> <pre><code>while($row = mysql_fetch_array($result)){ for($i = 1; $i &lt; 10; $i++) { if(!trim($row[$i . 'url'])=='') { echo '&lt;li&gt;&lt;a href="'; echo $row[$i . 'url']; echo '"&gt;'; echo $row[$i . 'name']; echo '&lt;/a&gt;&lt;/li&gt;'; } //end of didn't trim }//end for for }//end of while </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload