Jump to content


Photo

Is there anyway to shorten this??


  • Please log in to reply
3 replies to this topic

#1 newb

newb
  • Members
  • PipPipPip
  • Advanced Member
  • 454 posts

Posted 11 June 2006 - 04:24 AM

<?php
include "../inc/connect.php";

$result = mysql_query("SELECT id, title, artist, thumb FROM pictures WHERE id='1'");
$result2 = mysql_query("SELECT id, title, artist, thumb FROM pictures WHERE id='2'")
or die(mysql_error());  

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

$thumb = $row['thumb'];
$title = $row['title'];
$artist = $row['artist'];

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

$thumb2 = $row['thumb'];
$title2 = $row['title'];
$artist2 = $row['artist'];

}

echo "<p align='left'><font face='Arial'><b>My Thumbnails</b></font><br>
<br></p>
<table border='0' width='100%' id='table1'>
    <tr>
        <td width='33%' valign='top' height='65'>
        $thumb<br>
        Title: $title<br>
        Artist(s): $artist
        </td>
        <td width='33%' valign='top' height='65'>
        $thumb2<br>
        Title: $title2<br>
        Artist(s): $artist2
This code works fine. The problem is, I dont wan't to keep copying and pasting, adding repetitive code to the file. I was hoping there was a way to avoid doing this. It would save me alot of time and work. I just want to grab the data from the database. Anyone think they can help me with this? If so let me know, thanks.

#2 Masna

Masna
  • Staff Alumni
  • Advanced Member
  • 288 posts
  • LocationNew York

Posted 11 June 2006 - 04:41 AM

Use the while loops you're already using.

Wait a minute... Do you know what the while loop is for?
I like LoL.

#3 newb

newb
  • Members
  • PipPipPip
  • Advanced Member
  • 454 posts

Posted 11 June 2006 - 04:53 AM

Nope, I'm basically trying to figure out how to print the data on the page without having to copy and paste all that code over and over and modifying it (thumb3, thumb4, thumb5, etc...). It's enough that I have to insert it all in the SQL db.

#4 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 11 June 2006 - 05:54 AM

<?php
include "../inc/connect.php";

$result = mysql_query("SELECT id, title, artist, thumb FROM pictures") or die(mysql_error());  

echo "<p align='left'><font face='Arial'><b>My Thumbnails</b></font><br><br></p>";
echo "<table border='0' width='100%' id='table1'>";

while($row = mysql_fetch_array( $result )) {
   $thumb = $row['thumb'];
   $title = $row['title'];
   $artist = $row['artist'];

   echo "<tr>";
   echo    "<td width='33%' valign='top' height='65'>";
   echo       "$thumb<br>";
   echo       "Title: $title<br>";
   echo       "Artist(s): $artist";
   echo    "</td>";
   echo "</tr>";
}
echo "</table>";
?>

Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users