PHP MYSQL while change field name each time -
i have database store people's quick links. basic quick link storage method. database looks this:
full_name | 1url | 1name | 2url | 2name | 3url |3 name | 4url |4name | 5url | 5name
^this goes on until 10. know bad way, unprofessional website.
i want put result ordered list. unsure how change number (1url or 2url) each time?
so have set in php
$result = mysql_query(select * `links` `full_name`='$loggedin')or die (mysql_error()); while($row = mysql_fetch_array($result)){ echo '<li><a href="'; echo $row['1url']; echo '"></a></li>'; }
but having no luck that! i'm unsure of should do. want display <li>
<a>
, link plus name of link each row found.
thanks! please specific me, new ground! :d
edit:
i have run problem. have used code peoples' answers , of them work. however, if 1 of fields blank (so user has 6 quick links) still shows <li>
. can't see anyway round issue. :/
solution:
here works:
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 }//end of while
$result = mysql_query("select * `links` `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>'; } }
mind you, pretty hacky... have implemented 3 columns (maybe 4 using autoincrement sort) , select rows based on user, emitting each row. removes 10 url limit.
edit
for second question, have @ php 'empty' function , break/continue loop if function returns true.
Comments
Post a Comment