Page 1 of 1

[SOLVED] Need help with mysql/php script.

Posted: Tue Oct 05, 2004 4:18 pm
by zidokid
I am creating somewhat of a "downloads" system, where it records the information about each download on my site to a mysql database, ive added a couple of downloads, but only one will show up.
Here is the code:

Code: Select all

<?

$check=mysql_query("SELECT * FROM downloads");
$down=mysql_fetch_array($check);

?>
<table width="355" border="0" cellspacing="2">
  <tr>
    <td width="55" class="x"><center>Name</center></td>
    <td width="203" class="x"><center>Description</center></td>
    <td width="83" class="x"><center>Download</center></td>
  </tr>
  <?
  
  echo "<tr><td width="55" class="y"><center>",$down['name'],"</center></td>";
  echo "<td width="203" class="y"><center>",$down['desc'],"</center></td>";
  echo "<td width="83" class="y"><center><a href="downloads/",$down['link'],"">Download</a></center></td></tr>";
  
  ?>
  </table>
If anyone would care to help i would be very grateful.

Posted: Tue Oct 05, 2004 4:24 pm
by feyd
you only asked for 1.. you need a loop of some sort to fetch the rest of the records that matched your query.

Posted: Tue Oct 05, 2004 4:28 pm
by zidokid
so i could do this with the "while" function?

Posted: Tue Oct 05, 2004 4:29 pm
by qads
yup

Posted: Tue Oct 05, 2004 4:38 pm
by zidokid
Yeah cool it worked all i needed to do was this:

Code: Select all

<?
  while ($down = mysql_fetch_array($check)) {
  echo "<tr><td width="55" class="y"><center>",$down['name'],"</center></td>";
  echo "<td width="203" class="y"><center>",$down['desc'],"</center></td>";
  echo "<td width="83" class="y"><center><a href="downloads/",$down['link'],"">Download</a></center></td></tr>";
  
  }
  ?>
Thanks for the help.

Posted: Wed Oct 06, 2004 3:24 am
by twigletmac
You can save yourself a bunch of escaping by using single quotes around your HTML, or by going out of PHP except where you need variables:

Code: Select all

<?php
while ($down = mysql_fetch_array($check)) {
  echo '<tr><td width="55" class="y"><center>',$down['name'],'</center></td>';
  echo '<td width="203" class="y"><center>',$down['desc'],'</center></td>';
  echo '<td width="83" class="y"><center><a href="downloads/',$down['link'],'">Download</a></center></td></tr>';
  
  }
?>

/* OR */

<?php
while ($down = mysql_fetch_array($check)) {
?>
 <tr><td width="55" class="y"><center><?php echo $down['name']; ?></center></td>
 <td width="203" class="y"><center><?php echo $down['desc']; ?></center></td>
 <td width="83" class="y"><center><a href="downloads/<?php echo $down['link']; ?>">Download</a></center></td></tr>
<?php
    }
?>
Mac