pstanbra Posted February 15, 2007 Share Posted February 15, 2007 I ma trying to create a dynamic link; I have a table with brick number and url. The code below works and sets the link url on an image. However I have 40 images. 40 different urls Other than repeating the code below 40 times changing where brick = <number> is there another way to dynamically generate the url based on the image/brick <?php require_once('Connections/house.php'); ?> <?php mysql_select_db($database_house, $house); $query_brick1 = "SELECT bricks.url FROM bricks WHERE bricks.brick ='1'"; $brick1 = mysql_query($query_brick1, $house) or die(mysql_error()); $row_brick1 = mysql_fetch_assoc($brick1); $totalRows_brick1 = mysql_num_rows($brick1); ?> <a href="<?php echo $row_brick1[url]?>"><img src="images/cash-shaker_05.jpg" width="75" height="69" border="0"></a> <?php mysql_free_result($brick1); ?> Link to comment https://forums.phpfreaks.com/topic/38628-dynamic-links/ Share on other sites More sharing options...
trq Posted February 15, 2007 Share Posted February 15, 2007 Use a while() to loop through all your results. <?php mysql_select_db($database_house, $house); $query = "SELECT bricks.url FROM bricks WHERE bricks.brick ='1'"; if ($result = mysql_query($query)) { if (mysql_num_rows($result)) { while ($row = mysql_fetch_assoc($result) { echo "<a href=\"{$row['url']}\"><img src=\"images/cash-shaker_05.jpg\" width=\"75\" height=\"69\" border=\"0\"></a>"; } } } ?> Of course this would be more effective if you also stored the img src within your database (if you wanted a different image for each link). Link to comment https://forums.phpfreaks.com/topic/38628-dynamic-links/#findComment-185393 Share on other sites More sharing options...
pstanbra Posted February 15, 2007 Author Share Posted February 15, 2007 the logic is feasible however in practice im not so sure - you see i have a photoshop image that has been sliced up into a webpage. Im not sure I could use a loop as this would cause problems with image positioning? Link to comment https://forums.phpfreaks.com/topic/38628-dynamic-links/#findComment-185442 Share on other sites More sharing options...
mbtaylor Posted February 15, 2007 Share Posted February 15, 2007 I would have 2 tables. A table storing your bricks and a table storing your images (links to the image path). So there would be 2 primary keys brickID and imageID and a foreign key imageID in the brick table linking the correct image to the correct brick. It would then be just a case of doing a query with a join to display the bricks/images. $query = mysql_query ("SELECT * FROM bricks AS br INNER JOIN images AS im ON br.imageID=im.imageID"); Note dont use SELECT * just select the fields you want depending on your db structure Link to comment https://forums.phpfreaks.com/topic/38628-dynamic-links/#findComment-185452 Share on other sites More sharing options...
trq Posted February 15, 2007 Share Posted February 15, 2007 Im not sure I could use a loop as this would cause problems with image positioning? Why would it? Link to comment https://forums.phpfreaks.com/topic/38628-dynamic-links/#findComment-185455 Share on other sites More sharing options...
pstanbra Posted February 15, 2007 Author Share Posted February 15, 2007 hmm I jsut presume it would as its in a format as below. I presume the loop would not work as it would apply the images in a single cell? As you can see -there are many images here. Each image needs to have a dynamic link as this link in the table will be overwritten by a script later to change the url. re: the statement above $query = "SELECT bricks.url FROM bricks WHERE bricks.brick ='1'"; each image has an ID (brick number) the code above selects the row for that 1 particular image Im not really a php programmer but am trying .. <tr> <td width="58"><img src="images/cash-shaker_01.jpg" width="58" height="18" alt="" /></td> <td colspan="7"><img src="images/cash-shaker_02.jpg" width="189" height="18" alt="" /></td> <td width="10" rowspan="2"><img src="images/cash-shaker_03.jpg" width="10" height="32" alt="" /></td> <td colspan="6"><img src="images/cash-shaker_04.jpg" width="167" height="18" alt="" /></td> <td width="22" rowspan="2"><img src="images/cash-shaker_05.jpg" width="22" height="32" alt="" /></td> <td width="54"><img src="images/cash-shaker_06.jpg" width="54" height="18" alt="" /></td> <td width="10"><img src="images/spacer.gif" width="1" height="18" alt="" /></td> </tr> <tr> <td colspan="8"><img src="images/cash-shaker_07.jpg" width="247" height="14" alt="" /></td> <td colspan="6"><img src="images/cash-shaker_08.jpg" width="167" height="14" alt="" /></td> <td><img src="images/cash-shaker_09.jpg" width="54" height="14" alt="" /></td> <td><img src="images/spacer.gif" width="1" height="14" alt="" /></td> </tr> <tr> <td colspan="6"><img src="images/cash-shaker_10.jpg" width="157" height="25" alt="" /></td> <td width="11" rowspan="11"><img src="images/cash-shaker_11.jpg" width="11" height="196" alt="" /></td> <td colspan="5" rowspan="2"><img src="images/cash-shaker_12.jpg" width="175" height="43" alt="" /></td> <td width="7" rowspan="3"><img src="images/cash-shaker_13.jpg" width="7" height="54" alt="" /></td> <td colspan="4" rowspan="2"><img src="images/cash-shaker_14.jpg" width="150" height="43" alt="" /></td> <td><img src="images/spacer.gif" width="1" height="25" alt="" /></td> </tr> <tr> <td colspan="4"><img src="images/cash-shaker_15.jpg" width="92" height="18" alt="" /></td> <td width="49" rowspan="5"><img src="images/cash-shaker_16.jpg" width="49" height="86" alt="" /></td> <td width="16"><img src="images/cash-shaker_17.jpg" width="16" height="18" alt="" /></td> <td><img src="images/spacer.gif" width="1" height="18" alt="" /></td> </tr> <tr> <td colspan="4"><img src="images/cash-shaker_18.jpg" width="92" height="11" alt="" /></td> <td><img src="images/cash-shaker_19.jpg" width="16" height="11" alt="" /></td> <td colspan="5"><img src="images/cash-shaker_20.jpg" width="175" height="11" alt="" /></td> <td colspan="4"><img src="images/cash-shaker_21.jpg" width="150" height="11" alt="" /></td> <td><img src="images/spacer.gif" width="1" height="11" alt="" /></td> </tr> <tr> <td colspan="4"><img src="images/cash-shaker_22.jpg" width="92" height="38" alt="" /></td> <td><img src="images/cash-shaker_23.jpg" width="16" height="38" alt="" /></td> <td colspan="3"><img src="images/cash-shaker_24.jpg" width="90" height="38" alt="" /></td> <td width="10" rowspan="8"><img src="images/cash-shaker_25.jpg" width="10" height="142" alt="" /></td> <td colspan="4"><img src="images/cash-shaker_26.jpg" width="156" height="38" alt="" /></td> <td colspan="2" rowspan="2"><img src="images/cash-shaker_27.jpg" width="76" height="56" alt="" /></td> <td><img src="images/spacer.gif" width="1" height="38" alt="" /></td> </tr> <tr> <td colspan="4"><img src="images/cash-shaker_28.jpg" width="92" height="18" alt="" /></td> <td><img src="images/cash-shaker_29.jpg" width="16" height="18" alt="" /></td> <td colspan="3" rowspan="7"><img src="images/cash-shaker_30.jpg" width="90" height="104" alt="" /></td> <td colspan="4"><img src="images/cash-shaker_31.jpg" width="156" height="18" alt="" /></td> <td><img src="images/spacer.gif" width="1" height="18" alt="" /></td> </tr> <tr> <td colspan="4" rowspan="2"><img src="images/cash-shaker_32.jpg" width="92" height="32" alt="" /></td> <td rowspan="2"><img src="images/cash-shaker_33.jpg" width="16" height="32" alt="" /></td> <td colspan="3" rowspan="4"><img src="images/cash-shaker_34.jpg" width="118" height="48" alt="" /></td> <td colspan="3" rowspan="2"><img src="images/cash-shaker_35.jpg" width="114" height="32" alt="" /></td> <td><img src="images/spacer.gif" width="1" height="1" alt="" /></td> </tr> <tr> <td><img src="images/cash-shaker_36.jpg" width="49" height="31" alt="" /></td> <td><img src="images/spacer.gif" width="1" height="31" alt="" /></td> </tr> <tr> <td colspan="6"><img src="images/cash-shaker_37.jpg" width="157" height="8" alt="" /></td> <td colspan="3" rowspan="2"><img src="images/cash-shaker_38.jpg" width="114" height="16" alt="" /></td> <td><img src="images/spacer.gif" width="1" height="8" alt="" /></td> </tr> <tr> <td colspan="2" rowspan="2"><img src="images/cash-shaker_39.jpg" width="68" height="36" alt="" /></td> <td width="14" rowspan="4"><img src="images/cash-shaker_40.jpg" width="14" height="76" alt="" /></td> <td colspan="3" rowspan="2"><img src="images/cash-shaker_41.jpg" width="75" height="36" alt="" /></td> <td><img src="images/spacer.gif" width="1" height="8" alt="" /></td> </tr> <tr> <td width="75" rowspan="2"><img src="images/cash-shaker_42.jpg" width="75" height="38" alt="" /></td> <td height="68" colspan="5" rowspan="3" valign="top" background="images/cash-shaker_43.jpg"><span class="style9">Total Donations <?php echo $global_currency.getDonations('donation'); ?></span><br /> <span class="style9">Net Donations: <?php echo $global_currency.getNetDonations('donation'); ?><span class="style9" ></span><font color="#FFFFFF"><br /> <span class="style9" style="color: #FFFFFF"><font color="#FFFFFF"><font color="#FFFFFF">Total Fees: </font></font></span></font><span class="style9"><span style="color: #FFFFFF"> <?php echo $global_currency.getDonationFees('donation'); ?></span><font color="#FFFFFF"><span style="color: #FFFFFF"><br /> <span class="style9">Number of Donations</span></span><span class="style9">: <font color="#FFFFFF"><?php echo getDonationsCount('donation'); ?></font></span></font></td> <td><img src="images/spacer.gif" width="1" height="28" alt="" /></td> </tr> <tr> <td colspan="2"><img src="images/cash-shaker_44.jpg" width="68" height="10" alt="" /></td> <td colspan="3"><img src="images/cash-shaker_45.jpg" width="75" height="10" alt="" /></td> <td><img src="images/spacer.gif" width="1" height="10" alt="" /></td> </tr> <tr> <td colspan="2"><img src="images/cash-shaker_46.jpg" width="68" height="30" alt="" /></td> <td colspan="4"><img src="images/cash-shaker_47.jpg" width="86" height="30" alt="" /></td> <td colspan="2"><img src="images/cash-shaker_48.jpg" width="89" height="30" alt="" /></td> <td colspan="3"><img src="images/cash-shaker_49.jpg" width="86" height="30" alt="" /></td> <td><img src="images/spacer.gif" width="1" height="30" alt="" /></td> </tr> <tr> <td><img src="images/spacer.gif" width="58" height="1" alt="" /></td> <td width="10"><img src="images/spacer.gif" width="10" height="1" alt="" /></td> <td><img src="images/spacer.gif" width="14" height="1" alt="" /></td> <td width="10"><img src="images/spacer.gif" width="10" height="1" alt="" /></td> <td><img src="images/spacer.gif" width="49" height="1" alt="" /></td> <td><img src="images/spacer.gif" width="16" height="1" alt="" /></td> <td><img src="images/spacer.gif" width="11" height="1" alt="" /></td> <td width="79"><img src="images/spacer.gif" width="79" height="1" alt="" /></td> <td><img src="images/spacer.gif" width="10" height="1" alt="" /></td> <td width="1"><img src="images/spacer.gif" width="1" height="1" alt="" /></td> <td><img src="images/spacer.gif" width="10" height="1" alt="" /></td> <td><img src="images/spacer.gif" width="75" height="1" alt="" /></td> <td><img src="images/spacer.gif" width="7" height="1" alt="" /></td> <td width="36"><img src="images/spacer.gif" width="36" height="1" alt="" /></td> <td width="38"><img src="images/spacer.gif" width="38" height="1" alt="" /></td> <td><img src="images/spacer.gif" width="22" height="1" alt="" /></td> <td><img src="images/spacer.gif" width="54" height="1" alt="" /></td> <td></td> </tr> </table></td> <td width="20%" rowspan="3" valign="top" bgcolor="#FFCCFF"><p align="center"><span style="padding: 5px 5px 5px 5px;border-width: 1px;border-spacing: 0;border-style: dotted;border-color: #000000;"><img src="stellar-therm.php?current=<?php echo getNetDonations('donation'); ?>&target=150000&symbol=<?PHP echo $global_currency;?>" alt="Live Donation Thermometer" /></span></p> <p> </p> <p align="center"><img name="" src="" width="135" height="42" alt="" /></p> <p align="center"><img name="" src="" width="135" height="42" alt="" /></p> <p align="center"><img name="" src="" width="135" height="42" alt="" /></p> <p> </p> <p> </p></td> </tr> <tr> <td><span class="style11"><br /> Top 10 Donators </span><br /> <?php do { ?> <table width="499" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td width="243" height="45" valign="top"><span class="style8"><a href="<?php echo $row_links['option_name1']; ?>"><?php echo $row_links['option_selection1']; ?> </a><span class="style1">£<?php echo $row_links['mc_gross'];?></span></span><span class="style1"><span class="style2"><br /> <span class="style7"><?php echo $row_links['option_name1']; ?></span></span><br /> </span></td> <td valign="top"><span class="style7"><?php echo $row_links['option_name2'];?> </span></td> </tr> </table> <?php } while ($row_links = mysql_fetch_assoc($links)); ?></td> </tr> <tr> <td valign="top"><p> </p> <p align="center"> </p> <p> </p> <p align="center"> </p></td> </tr> </table> Link to comment https://forums.phpfreaks.com/topic/38628-dynamic-links/#findComment-185485 Share on other sites More sharing options...
pstanbra Posted February 15, 2007 Author Share Posted February 15, 2007 oh its so hard! Link to comment https://forums.phpfreaks.com/topic/38628-dynamic-links/#findComment-185606 Share on other sites More sharing options...
pstanbra Posted February 15, 2007 Author Share Posted February 15, 2007 any more comments on this guys Link to comment https://forums.phpfreaks.com/topic/38628-dynamic-links/#findComment-185823 Share on other sites More sharing options...
pstanbra Posted February 16, 2007 Author Share Posted February 16, 2007 ?? Link to comment https://forums.phpfreaks.com/topic/38628-dynamic-links/#findComment-186130 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.