I am very new to php and have written my first script, or at least found one and changed it a little to suit my needs. But after a little more research and reading I know there has to be a better way to do this. Essentially for each page I need to pull a single company's information form a few different tables in different areas of the page, but the script I am using is a loop looping through one company's info. I knwo I probably don't need the loop but am not sure where to start looking for a better solution. If someone could point me in the right direction I would be very grateful.
Here is the code I am using now:
Code: Select all
mysql_connect($hostname,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM co_links WHERE co_name='Playful Promises'";
$result=mysql_query($query);
$num=mysql_num_rows($result);
?>
<ul>
<?php
$i=0;
while ($i < $num) {
$link_1=mysql_result($result,$i,"link_1");
$text_1=mysql_result($result,$i,"text_1");
$link_2=mysql_result($result,$i,"link_2");
$text_2=mysql_result($result,$i,"text_2");
$link_3=mysql_result($result,$i,"link_3");
$text_3=mysql_result($result,$i,"text_3");
$link_4=mysql_result($result,$i,"link_4");
$text_4=mysql_result($result,$i,"text_4");
$link_5=mysql_result($result,$i,"link_5");
$text_5=mysql_result($result,$i,"text_5");
$link_6=mysql_result($result,$i,"link_6");
$text_6=mysql_result($result,$i,"text_6");
$link_7=mysql_result($result,$i,"link_7");
$text_7=mysql_result($result,$i,"text_7");
$link_8=mysql_result($result,$i,"link_8");
$text_8=mysql_result($result,$i,"text_8");
$link_9=mysql_result($result,$i,"link_9");
$text_9=mysql_result($result,$i,"text_9");
$link_10=mysql_result($result,$i,"link_10");
$text_10=mysql_result($result,$i,"text_10");
$link_11=mysql_result($result,$i,"link_11");
$text_11=mysql_result($result,$i,"text_11");
?>
<li><a href="<?php echo $link_1; ?>"><?php echo $text_1; ?></a></li>
<li><a href="<?php echo $link_2; ?>"><?php echo $text_2; ?></a></li>
<li><a href="<?php echo $link_3; ?>"><?php echo $text_3; ?></a></li>
<li><a href="<?php echo $link_4; ?>"><?php echo $text_4; ?></a></li>
<li><a href="<?php echo $link_5; ?>"><?php echo $text_5; ?></a></li>
<li><a href="<?php echo $link_6; ?>"><?php echo $text_6; ?></a></li>
<li><a href="<?php echo $link_7; ?>"><?php echo $text_7; ?></a></li>
<li><a href="<?php echo $link_8; ?>"><?php echo $text_8; ?></a></li>
<li><a href="<?php echo $link_9; ?>"><?php echo $text_9; ?></a></li>
<li><a href="<?php echo $link_10; ?>"><?php echo $text_10; ?></a></li>
<li><a href="<?php echo $link_11; ?>"><?php echo $text_11; ?></a></li>
</ul>
<?php
$i++;
}
?>
</li>
If I have not posted anything correctly please let me know as I am still very new to posting in forums. Thanx!