[SOLVED] Need help with mysql/php script.

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
zidokid
Forum Newbie
Posts: 3
Joined: Tue Oct 05, 2004 3:41 pm

[SOLVED] Need help with mysql/php script.

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
zidokid
Forum Newbie
Posts: 3
Joined: Tue Oct 05, 2004 3:41 pm

Post by zidokid »

so i could do this with the "while" function?
qads
DevNet Resident
Posts: 1199
Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane

Post by qads »

yup
zidokid
Forum Newbie
Posts: 3
Joined: Tue Oct 05, 2004 3:41 pm

Post 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.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
Post Reply